gstvalue: only unwrap string delimited with "
authorLuis de Bethencourt <luis.bg@samsung.com>
Thu, 26 Mar 2015 17:01:06 +0000 (17:01 +0000)
committerLuis de Bethencourt <luis.bg@samsung.com>
Fri, 27 Mar 2015 17:18:23 +0000 (17:18 +0000)
Don't unwrap strings that start but don't finish with a double quote. If a
string is delimited by two quotes we unescape them and any special characters
in the middle (like \" or \\). If the first character or the last character
aren't a quote we assume it's part of an unescaped string.

Moved some deserialize_string unit tests because we don't try to unwrap strings
missing that second quote anymore.

https://bugzilla.gnome.org/show_bug.cgi?id=688625

gst/gstvalue.c
tests/check/gst/gstvalue.c

index 031c02a..21771eb 100644 (file)
@@ -3012,12 +3012,13 @@ gst_value_deserialize_string (GValue * dest, const gchar * s)
   if (G_UNLIKELY (strcmp (s, "NULL") == 0)) {
     g_value_set_string (dest, NULL);
     return TRUE;
-  } else if (G_LIKELY (*s != '"')) {
+  } else if (G_LIKELY (*s != '"' || s[strlen (s) - 1] != '"')) {
     if (!g_utf8_validate (s, -1, NULL))
       return FALSE;
     g_value_set_string (dest, s);
     return TRUE;
   } else {
+    /* strings delimited with double quotes should be unwrapped */
     gchar *str = gst_string_unwrap (s);
     if (G_UNLIKELY (!str))
       return FALSE;
index 7b913f5..3be87c4 100644 (file)
@@ -542,21 +542,18 @@ GST_START_TEST (test_deserialize_string)
     "\"foo\\%\"", "foo%"}, {
     "\"0123456789_-+/:.\"", "0123456789_-+/:."}, {
     "\"Hello\\ World\"", "Hello World"}, {
+    "\"Hello\\ World", "\"Hello\\ World"}, {
+    "\"\\", "\"\\"}, {
+    "\"\\0", "\"\\0"}, {
     "", ""},                    /* empty strings */
     {
     "\"\"", ""},                /* quoted empty string -> empty string */
         /* Expected FAILURES: */
     {
-    "\"", NULL},                /* missing second quote */
-    {
-    "\"Hello\\ World", NULL},   /* missing second quote */
-    {
-    "\"\\", NULL},              /* quote at end, missing second quote */
-    {
-    "\"\\0", NULL},             /* missing second quote */
-    {
     "\"\\0\"", NULL},           /* unfinished escaped character */
     {
+    "\"", NULL},                /* solitary quote */
+    {
     "\" \"", NULL},             /* spaces must be escaped */
 #if 0
         /* FIXME 0.9: this test should fail, but it doesn't */