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
This commit is contained in:
Luis de Bethencourt 2015-03-26 17:01:06 +00:00
parent c565c5ecb4
commit 555e0211c8
2 changed files with 7 additions and 9 deletions

View 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;

View 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 */