imcontext: Fix a regression in Compose file parsing
authorMatthias Clasen <mclasen@redhat.com>
Sun, 14 Feb 2021 16:54:05 +0000 (11:54 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 14 Feb 2021 16:56:24 +0000 (11:56 -0500)
We accidentally dropped the handing of # comments.
Bring it back. Test included.

Fixes: #3664
gtk/gtkcomposetable.c
testsuite/gtk/compose/comments [new file with mode: 0644]
testsuite/gtk/compose/comments.expected [new file with mode: 0644]

index c5261f8a631d445da34519a36dc0b7a92d6e2e61..20afc2dc446e7f5b0744d273acaa0a51602d8b3d 100644 (file)
@@ -77,28 +77,40 @@ parse_compose_value (GtkComposeData *compose_data,
                      const char     *val,
                      const char     *line)
 {
-  char *word;
   const char *p;
-  gsize len;
   GString *value;
   gunichar ch;
   char *endp;
 
-  len = strlen (val);
-  if (val[0] != '"' || val[len - 1] != '"')
+  if (val[0] != '"')
     {
       g_warning ("Need to double-quote the value: %s: %s", val, line);
       goto fail;
     }
 
-  word = g_strndup (val + 1, len - 2);
-
   value = g_string_new ("");
 
-  p = word;
+  p = val + 1;
   while (*p)
     {
-      if (*p == '\\')
+      if (*p == '\0')
+        {
+          g_warning ("Missing closing '\"': %s: %s", val, line);
+          goto fail;
+        }
+      else if (*p == '\"')
+        {
+          p++;
+          while (*p && g_ascii_isspace (*p))
+            p++;
+          if (*p != '\0' && *p != '#')
+            {
+              g_warning ("Garbage after closing '\"': %s: %s", val, line);
+              goto fail;
+            }
+          break;
+        }
+      else if (*p == '\\')
         {
           if (p[1] == '"')
             {
@@ -148,8 +160,6 @@ parse_compose_value (GtkComposeData *compose_data,
 
   compose_data->value = g_string_free (value, FALSE);
 
-  g_free (word);
-
   return TRUE;
 
 fail:
diff --git a/testsuite/gtk/compose/comments b/testsuite/gtk/compose/comments
new file mode 100644 (file)
index 0000000..062c9aa
--- /dev/null
@@ -0,0 +1,4 @@
+<Multi_key> <a> : "a" # just an a
+<Multi_key> <b> : "#" # not an a
+# this line is ignored
+<Multi_key> <c> : "a" # wild and wilder: "@!$#
diff --git a/testsuite/gtk/compose/comments.expected b/testsuite/gtk/compose/comments.expected
new file mode 100644 (file)
index 0000000..728817b
--- /dev/null
@@ -0,0 +1,5 @@
+# n_seqs: 3
+# max_seq_len: 2
+<Uff20> <U61> : "a" # U61
+<Uff20> <U62> : "#" # U23
+<Uff20> <U63> : "a" # U61