From: Darin Adler Date: Sun, 19 Aug 2001 17:28:07 +0000 (+0000) Subject: Added missing \ character. X-Git-Tag: GLIB_1_3_7~27 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6d4342990a57e6877b66421d2eb27fddd5811197;p=platform%2Fupstream%2Fglib.git Added missing \ character. * glib/gshell.c: (g_shell_quote): Added missing \ character. * tests/shell-test.c: (check_string_result), (test_shell_unquote), (main): Added tests for g_shell_quote and g_shell_unquote. --- diff --git a/ChangeLog b/ChangeLog index 87238d7..7bf7a77 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2001-08-19 Darin Adler + + * glib/gshell.c: (g_shell_quote): Added missing \ character. + + * tests/shell-test.c: (check_string_result), (test_shell_unquote), + (main): Added tests for g_shell_quote and g_shell_unquote. + 2001-08-19 Fatih Demir * configure.in: Added "ta" to the languages list. diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 87238d7..7bf7a77 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,10 @@ +2001-08-19 Darin Adler + + * glib/gshell.c: (g_shell_quote): Added missing \ character. + + * tests/shell-test.c: (check_string_result), (test_shell_unquote), + (main): Added tests for g_shell_quote and g_shell_unquote. + 2001-08-19 Fatih Demir * configure.in: Added "ta" to the languages list. diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 87238d7..7bf7a77 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,10 @@ +2001-08-19 Darin Adler + + * glib/gshell.c: (g_shell_quote): Added missing \ character. + + * tests/shell-test.c: (check_string_result), (test_shell_unquote), + (main): Added tests for g_shell_quote and g_shell_unquote. + 2001-08-19 Fatih Demir * configure.in: Added "ta" to the languages list. diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 87238d7..7bf7a77 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,10 @@ +2001-08-19 Darin Adler + + * glib/gshell.c: (g_shell_quote): Added missing \ character. + + * tests/shell-test.c: (check_string_result), (test_shell_unquote), + (main): Added tests for g_shell_quote and g_shell_unquote. + 2001-08-19 Fatih Demir * configure.in: Added "ta" to the languages list. diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 87238d7..7bf7a77 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,10 @@ +2001-08-19 Darin Adler + + * glib/gshell.c: (g_shell_quote): Added missing \ character. + + * tests/shell-test.c: (check_string_result), (test_shell_unquote), + (main): Added tests for g_shell_quote and g_shell_unquote. + 2001-08-19 Fatih Demir * configure.in: Added "ta" to the languages list. diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 87238d7..7bf7a77 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,10 @@ +2001-08-19 Darin Adler + + * glib/gshell.c: (g_shell_quote): Added missing \ character. + + * tests/shell-test.c: (check_string_result), (test_shell_unquote), + (main): Added tests for g_shell_quote and g_shell_unquote. + 2001-08-19 Fatih Demir * configure.in: Added "ta" to the languages list. diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 87238d7..7bf7a77 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,10 @@ +2001-08-19 Darin Adler + + * glib/gshell.c: (g_shell_quote): Added missing \ character. + + * tests/shell-test.c: (check_string_result), (test_shell_unquote), + (main): Added tests for g_shell_quote and g_shell_unquote. + 2001-08-19 Fatih Demir * configure.in: Added "ta" to the languages list. diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 87238d7..7bf7a77 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,10 @@ +2001-08-19 Darin Adler + + * glib/gshell.c: (g_shell_quote): Added missing \ character. + + * tests/shell-test.c: (check_string_result), (test_shell_unquote), + (main): Added tests for g_shell_quote and g_shell_unquote. + 2001-08-19 Fatih Demir * configure.in: Added "ta" to the languages list. diff --git a/glib/gshell.c b/glib/gshell.c index e27d799..3f6134b 100644 --- a/glib/gshell.c +++ b/glib/gshell.c @@ -198,7 +198,7 @@ g_shell_quote (const gchar *unquoted_string) { /* Replace literal ' with a close ', a \', and a open ' */ if (*p == '\'') - g_string_append (dest, "'\''"); + g_string_append (dest, "'\\''"); else g_string_append_c (dest, *p); diff --git a/tests/shell-test.c b/tests/shell-test.c index 8dc32c0..4787733 100644 --- a/tests/shell-test.c +++ b/tests/shell-test.c @@ -178,13 +178,113 @@ run_tests (void) } } +static gboolean any_test_failed = FALSE; + +#define CHECK_STRING_RESULT(expression, expected_value) \ + check_string_result (#expression, __FILE__, __LINE__, expression, expected_value) + +static void +check_string_result (const char *expression, + const char *file_name, + int line_number, + char *result, + const char *expected) +{ + gboolean match; + + if (expected == NULL) + match = result == NULL; + else + match = result != NULL && strcmp (result, expected) == 0; + + if (!match) + { + if (!any_test_failed) + fprintf (stderr, "\n"); + + fprintf (stderr, "FAIL: check failed in %s, line %d\n", file_name, line_number); + fprintf (stderr, " evaluated: %s\n", expression); + fprintf (stderr, " expected: %s\n", expected == NULL ? "NULL" : expected); + fprintf (stderr, " got: %s\n", result == NULL ? "NULL" : result); + + any_test_failed = TRUE; + } + + g_free (result); +} + +static char * +test_shell_unquote (const char *str) +{ + char *result; + GError *error; + + error = NULL; + result = g_shell_unquote (str, &error); + if (error == NULL) + return result; + + /* Leaks the error, which is no big deal. */ + + if (error->domain != G_SHELL_ERROR) + return g_strdup ("error in domain other than G_SHELL_ERROR"); + + /* It would be nice to check the error message too, but that's + * localized, so it's too much of a pain. + */ + switch (error->code) + { + case G_SHELL_ERROR_BAD_QUOTING: + return g_strdup ("G_SHELL_ERROR_BAD_QUOTING"); + case G_SHELL_ERROR_EMPTY_STRING: + return g_strdup ("G_SHELL_ERROR_EMPTY_STRING"); + case G_SHELL_ERROR_FAILED: + return g_strdup ("G_SHELL_ERROR_FAILED"); + default: + return g_strdup ("bad error code in G_SHELL_ERROR domain"); + } +} + int main (int argc, char *argv[]) { run_tests (); - return 0; -} + CHECK_STRING_RESULT (g_shell_quote (""), "''"); + CHECK_STRING_RESULT (g_shell_quote ("a"), "'a'"); + CHECK_STRING_RESULT (g_shell_quote ("("), "'('"); + CHECK_STRING_RESULT (g_shell_quote ("'"), "''\\'''"); + CHECK_STRING_RESULT (g_shell_quote ("'a"), "''\\''a'"); + CHECK_STRING_RESULT (g_shell_quote ("a'"), "'a'\\'''"); + CHECK_STRING_RESULT (g_shell_quote ("a'a"), "'a'\\''a'"); + + CHECK_STRING_RESULT (test_shell_unquote (""), ""); + CHECK_STRING_RESULT (test_shell_unquote ("a"), "a"); + CHECK_STRING_RESULT (test_shell_unquote ("'a'"), "a"); + CHECK_STRING_RESULT (test_shell_unquote ("'('"), "("); + CHECK_STRING_RESULT (test_shell_unquote ("''\\'''"), "'"); + CHECK_STRING_RESULT (test_shell_unquote ("''\\''a'"), "'a"); + CHECK_STRING_RESULT (test_shell_unquote ("'a'\\'''"), "a'"); + CHECK_STRING_RESULT (test_shell_unquote ("'a'\\''a'"), "a'a"); + + CHECK_STRING_RESULT (test_shell_unquote ("\\\\"), "\\"); + CHECK_STRING_RESULT (test_shell_unquote ("\\\n"), ""); + + CHECK_STRING_RESULT (test_shell_unquote ("'\\''"), "G_SHELL_ERROR_BAD_QUOTING"); + CHECK_STRING_RESULT (test_shell_unquote ("\"\\\"\""), "\""); + CHECK_STRING_RESULT (test_shell_unquote ("\""), "G_SHELL_ERROR_BAD_QUOTING"); + CHECK_STRING_RESULT (test_shell_unquote ("'"), "G_SHELL_ERROR_BAD_QUOTING"); + CHECK_STRING_RESULT (test_shell_unquote ("\"\\\\\""), "\\"); + CHECK_STRING_RESULT (test_shell_unquote ("\"\\`\""), "`"); + CHECK_STRING_RESULT (test_shell_unquote ("\"\\$\""), "$"); + CHECK_STRING_RESULT (test_shell_unquote ("\"\\\n\""), "\n"); + + CHECK_STRING_RESULT (test_shell_unquote ("\"\\'\""), "\\'"); + CHECK_STRING_RESULT (test_shell_unquote ("\"\\\r\""), "\\\r"); + CHECK_STRING_RESULT (test_shell_unquote ("\"\\n\""), "\\n"); + + return any_test_failed ? 1 : 0; +}