]> git.notmuchmail.org Git - notmuch/commitdiff
util: Fix two corner-cases in boolean term quoting function
authorAustin Clements <amdragon@MIT.EDU>
Tue, 11 Mar 2014 20:42:00 +0000 (16:42 -0400)
committerDavid Bremner <david@tethera.net>
Sat, 15 Mar 2014 18:05:06 +0000 (15:05 -0300)
Previously, make_boolean_term did not quote empty boolean terms or
boolean terms that started with '('.  These cases are incompatible
with Xapian: empty terms cannot be omitted, and boolean terms that
start with '(' trigger an alternate term quoting syntax.

Fix this by quoting empty terms and terms that contain '('.

util/string-util.c

index 9e2f728fc6750c586f3effed3ecac5673ea980e0..3e7066cd58ea191a9e647f5a0177f5547f662388 100644 (file)
@@ -75,10 +75,12 @@ make_boolean_term (void *ctx, const char *prefix, const char *term,
     int need_quoting = 0;
 
     /* Do we need quoting?  To be paranoid, we quote anything
     int need_quoting = 0;
 
     /* Do we need quoting?  To be paranoid, we quote anything
-     * containing a quote, even though it only matters at the
+     * containing a quote or '(', even though these only matter at the
      * beginning, and anything containing non-ASCII text. */
      * beginning, and anything containing non-ASCII text. */
+    if (! term[0])
+       need_quoting = 1;
     for (in = term; *in && !need_quoting; in++)
     for (in = term; *in && !need_quoting; in++)
-       if (is_unquoted_terminator (*in) || *in == '"'
+       if (is_unquoted_terminator (*in) || *in == '"' || *in == '('
            || (unsigned char)*in > 127)
            need_quoting = 1;
 
            || (unsigned char)*in > 127)
            need_quoting = 1;