Support &s as key of dict entry in format string
authorRyan Lortie <desrt@desrt.ca>
Tue, 23 Mar 2010 14:17:15 +0000 (09:17 -0500)
committerRyan Lortie <desrt@desrt.ca>
Tue, 23 Mar 2010 14:18:28 +0000 (09:18 -0500)
Partial fix for bug 613618.

glib/gvariant.c
glib/tests/gvariant.c

index e3e7cdc..721740f 100644 (file)
@@ -2745,15 +2745,25 @@ g_variant_format_string_scan (const gchar  *string,
     case '{':
       c = next_char();
 
-      if (c == '@')
-        c = next_char ();
+      if (c == '&')
+        {
+          c = next_char ();
 
-      /* ISO/IEC 9899:1999 (C99) §7.21.5.2:
-       *    The terminating null character is considered to be
-       *    part of the string.
-       */
-      if (c != '\0' && strchr ("bynqiuxthdsog?", c) == NULL)
-        return FALSE;
+          if (c != 's' && c != 'o' && c != 'g')
+            return FALSE;
+        }
+      else
+        {
+          if (c == '@')
+            c = next_char ();
+
+          /* ISO/IEC 9899:1999 (C99) §7.21.5.2:
+           *    The terminating null character is considered to be
+           *    part of the string.
+           */
+          if (c != '\0' && strchr ("bynqiuxthdsog?", c) == NULL)
+            return FALSE;
+        }
 
       if (!g_variant_format_string_scan (string, limit, &string))
         return FALSE;
index f756d13..1a51268 100644 (file)
@@ -2699,6 +2699,13 @@ test_format_strings (void)
             *end == '\0');
   g_assert (g_variant_format_string_scan ("{yv}", NULL, &end) &&
             *end == '\0');
+  g_assert (!g_variant_format_string_scan ("{&?v}", NULL, &end));
+  g_assert (g_variant_format_string_scan ("{@?v}", NULL, &end) &&
+            *end == '\0');
+  g_assert (!g_variant_format_string_scan ("{&@sv}", NULL, &end));
+  g_assert (!g_variant_format_string_scan ("{@&sv}", NULL, &end));
+  g_assert (g_variant_format_string_scan ("{&sv}", NULL, &end) &&
+            *end == '\0');
   g_assert (!g_variant_format_string_scan ("{vv}", NULL, &end));
   g_assert (!g_variant_format_string_scan ("{y}", NULL, &end));
   g_assert (!g_variant_format_string_scan ("{yyy}", NULL, &end));