unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH v3 0/5] Use Xapian query syntax for batch-tag dump/restore
@ 2012-12-28 18:26 Austin Clements
  2012-12-28 18:26 ` [PATCH v3 1/5] util: Factor out boolean term quoting routine Austin Clements
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Austin Clements @ 2012-12-28 18:26 UTC (permalink / raw)
  To: notmuch

This obsoletes

  id:1356493723-11085-1-git-send-email-amdragon@mit.edu

This version improves the documentation comment for make_boolean_term
and hopefully simplifies parse_boolean_term (though in a somewhat
different way than David suggested).

The diff relative to v2 follows

diff --git a/util/string-util.c b/util/string-util.c
index db01b4b..83b4953 100644
--- a/util/string-util.c
+++ b/util/string-util.c
@@ -112,11 +112,12 @@ parse_boolean_term (void *ctx, const char *str,
 
     /* Implement de-quoting compatible with make_boolean_term. */
     if (*pos == '"') {
-	char *out = talloc_strdup (ctx, pos + 1);
+	char *out = talloc_array (ctx, char, strlen (pos));
 	int closed = 0;
-	/* Find the closing quote and un-double doubled internal
-	 * quotes. */
-	for (pos = *term_out = out; *pos; ) {
+	*term_out = out;
+	/* Skip the opening quote, find the closing quote, and
+	 * un-double doubled internal quotes. */
+	for (++pos; *pos; ) {
 	    if (*pos == '"') {
 		++pos;
 		if (*pos != '"') {
@@ -133,12 +134,15 @@ parse_boolean_term (void *ctx, const char *str,
 	    goto FAIL;
 	*out = '\0';
     } else {
-	*term_out = talloc_strdup (ctx, pos);
+	const char *start = pos;
 	/* Check for text after the boolean term. */
 	while (*pos > ' ' && *pos != ')')
 	    ++pos;
 	if (*pos)
 	    goto FAIL;
+	/* No trailing text; dup the string so the caller can free
+	 * it. */
+	*term_out = talloc_strdup (ctx, start);
     }
     return 0;
 
diff --git a/util/string-util.h b/util/string-util.h
index aff2d65..43d49d0 100644
--- a/util/string-util.h
+++ b/util/string-util.h
@@ -20,7 +20,12 @@
 char *strtok_len (char *s, const char *delim, size_t *len);
 
 /* Construct a boolean term query with the specified prefix (e.g.,
- * "id") and search term, quoting term as necessary.
+ * "id") and search term, quoting term as necessary.  Specifically, if
+ * term contains any non-printable ASCII characters, non-ASCII
+ * characters, close parenthesis or double quotes, it will be enclosed
+ * in double quotes and any internal double quotes will be doubled
+ * (e.g. a"b -> "a""b").  The result will be a valid notmuch query and
+ * can be parsed by parse_boolean_term.
  *
  * Output is into buf; it may be talloc_realloced.
  * Return: 0 on success, non-zero on memory allocation failure.

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-12-31  5:52 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-28 18:26 [PATCH v3 0/5] Use Xapian query syntax for batch-tag dump/restore Austin Clements
2012-12-28 18:26 ` [PATCH v3 1/5] util: Factor out boolean term quoting routine Austin Clements
2012-12-28 18:26 ` [PATCH v3 2/5] util: Function to parse boolean term queries Austin Clements
2012-12-29 16:50   ` Mark Walters
2012-12-29 21:58   ` Tomi Ollila
2012-12-31  5:52     ` Austin Clements
2012-12-28 18:26 ` [PATCH v3 3/5] dump: Disallow \n in message IDs Austin Clements
2012-12-28 18:26 ` [PATCH v3 4/5] dump/restore: Use Xapian queries for batch-tag format Austin Clements
2012-12-28 18:26 ` [PATCH v3 5/5] man: Update notmuch-dump(1) and notmuch-restore(1) Austin Clements

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).