From 555e0211c8c67814546eca1c572af78840902eba Mon Sep 17 00:00:00 2001 From: Luis de Bethencourt Date: Thu, 26 Mar 2015 17:01:06 +0000 Subject: [PATCH] gstvalue: only unwrap string delimited with " 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 | 3 ++- tests/check/gst/gstvalue.c | 13 +++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/gst/gstvalue.c b/gst/gstvalue.c index 031c02a..21771eb 100644 --- a/gst/gstvalue.c +++ b/gst/gstvalue.c @@ -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; diff --git a/tests/check/gst/gstvalue.c b/tests/check/gst/gstvalue.c index 7b913f5..3be87c4 100644 --- a/tests/check/gst/gstvalue.c +++ b/tests/check/gst/gstvalue.c @@ -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 */ -- 2.7.4