unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Mark Walters <markwalters1009@gmail.com>
To: david@tethera.net, notmuch@notmuchmail.org
Cc: David Bremner <bremner@unb.ca>
Subject: Re: [PATCH] simplify unhex_and_quote
Date: Sun, 23 Dec 2012 08:19:20 +0000	[thread overview]
Message-ID: <87a9t5p4dz.fsf@qmul.ac.uk> (raw)
In-Reply-To: <1356231570-28232-1-git-send-email-david@tethera.net>


On Sun, 23 Dec 2012, david@tethera.net wrote:
> From: David Bremner <bremner@unb.ca>
>
> the overgeneral definition of a prefix can be replaced by lower case
> alphabetic, and still work fine with current notmuch query syntax.
>
> token_len++ is moved to the end, and we restore the delimiter just so
> we can leave the string as as we found it.
> ---
>
> As always, Jani has a keen eye for muddle. Except he's wrong about 
> tok_len - prefix_len, and Mark and I are right. Hopefully ;).
>
> Restoring the delimiter at the end might be pointless (since the rest
> of the input line is modified), but it is one less surprise for somebody 
> repurposing the function.

I am now worried about side bit of Xapian syntax, in particular, what
about brackets. I think we could have

(tag:inbox or tag:tag%20with%20spaces) and <something>

In which case the first token is (tag:inbox which does not
match. Additionally the third token is tag:tag%20with%20spaces) which
presumably gets quoted to tag:"tag with spaces)" and I am guessing
Xapian  treats this differently than with bracket after the quote.

Finally, I don't know if a query can contain a : without being a prefix
query. If it can that could end up being misquoted.

One possible way round the first problem might be to require the Xapian
syntax to be space separated from the rest but that does mean we are
diverging from the command line syntax.

(I am not very familiar with Xapian syntax nor with quite where this
function is used so I may be worrying about nothing)

Best wishes

Mark





>
> Patches 5 and 6 can be ignored now.
>  tag-util.c |   12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/tag-util.c b/tag-util.c
> index b0a846b..ee28512 100644
> --- a/tag-util.c
> +++ b/tag-util.c
> @@ -78,11 +78,13 @@ unhex_and_quote (void *ctx, char *encoded, const char *line_for_error,
>  	size_t prefix_len;
>  	char delim = *(tok + tok_len);
>  
> -	*(tok + tok_len++) = '\0';
> +	*(tok + tok_len) = '\0';
>  
> -	prefix_len = hex_invariant (tok, tok_len);
> +	/* The following matches a superset of prefixes currently
> +	 * used by notmuch */
> +	prefix_len = strspn (tok, "abcdefghijklmnopqrstuvwxyz");
>  
> -	if ((strcmp (tok, "*") == 0) || prefix_len >= tok_len - 1) {
> +	if ((strcmp (tok, "*") == 0) || prefix_len == tok_len) {
>  
>  	    /* pass some things through without quoting or decoding.
>  	     * Note for '*' this is mandatory.
> @@ -98,7 +100,7 @@ unhex_and_quote (void *ctx, char *encoded, const char *line_for_error,
>  
>  	} else {
>  	    /* potential prefix: one for ':', then something after */
> -	    if ((tok_len - prefix_len > 2) && *(tok + prefix_len) == ':') {
> +	    if ((tok_len - prefix_len >= 2) && *(tok + prefix_len) == ':') {
>  		if (! (*query_string = talloc_strndup_append (*query_string,
>  							      tok,
>  							      prefix_len + 1))) {
> @@ -129,6 +131,8 @@ unhex_and_quote (void *ctx, char *encoded, const char *line_for_error,
>  		goto DONE;
>  	    }
>  	}
> +	/* restore the string and skip delimiter */
> +	*(tok + tok_len++) = delim;
>      }
>  
>    DONE:
> -- 
> 1.7.10.4
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

  reply	other threads:[~2012-12-23  8:19 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-21 13:08 [Patch v8 01/18] parse_tag_line: use enum for return value david
2012-12-21 13:08 ` [Patch v8 02/18] tag-util: factor out rules for illegal tags, use in parse_tag_line david
2012-12-21 13:08 ` [Patch v8 03/18] notmuch-tag.c: convert to use tag-utils david
2012-12-21 13:08 ` [Patch v8 04/18] notmuch-tag: factor out double quoting routine david
2012-12-21 13:08 ` [Patch v8 05/18] util/string-util: add strnspn david
2012-12-21 13:08 ` [Patch v8 06/18] util/hex-escape: add a function to check strings unchanged by hex encoding david
2012-12-21 13:08 ` [Patch v8 07/18] unhex_and_quote: new function to quote hex-decoded queries david
2012-12-22 23:36   ` Jani Nikula
2012-12-23  2:59     ` [PATCH] simplify unhex_and_quote david
2012-12-23  8:19       ` Mark Walters [this message]
2012-12-21 13:08 ` [Patch v8 08/18] notmuch-restore: move query handling for batch restore to parser david
2012-12-21 13:08 ` [Patch v8 09/18] cli: add support for batch tagging operations to "notmuch tag" david
2012-12-22 22:51   ` Jani Nikula
2012-12-21 13:08 ` [Patch v8 10/18] test/tagging: add test for error messages of tag --batch david
2012-12-21 13:08 ` [Patch v8 11/18] test/tagging: add basic tests for batch tagging functionality david
2012-12-21 13:08 ` [Patch v8 12/18] test/tagging: add tests for exotic tags david
2012-12-21 13:08 ` [Patch v8 13/18] test/tagging: add test for exotic message-ids and batch tagging david
2012-12-21 13:08 ` [Patch v8 14/18] test/tagging: add test for compound queries with " david
2012-12-21 13:08 ` [Patch v8 15/18] notmuch-tag.1: tidy synopsis formatting, reference david
2012-12-21 13:08 ` [Patch v8 16/18] man: document notmuch tag --batch, --input options david
2012-12-21 13:08 ` [Patch v8 17/18] test/tagging: add test for naked punctuation in tags; compare with quoting spaces david
2012-12-21 13:08 ` [Patch v8 18/18] more man fixup david
2012-12-21 13:29 ` [Patch v8 01/18] parse_tag_line: use enum for return value David Bremner
2012-12-22 23:47   ` Jani Nikula
2012-12-22 21:48 ` Jani Nikula

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a9t5p4dz.fsf@qmul.ac.uk \
    --to=markwalters1009@gmail.com \
    --cc=bremner@unb.ca \
    --cc=david@tethera.net \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).