From 98ca74f9a84e4f4361a84fbd43fe78bc01855a7c Mon Sep 17 00:00:00 2001 From: djcb Date: Sat, 21 Jan 2012 11:18:29 +0200 Subject: [PATCH] * mu-msg-str.c: improve xapian-escaping, string-eating --- src/mu-str.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/mu-str.c b/src/mu-str.c index 6a04fd45..afc81634 100644 --- a/src/mu-str.c +++ b/src/mu-str.c @@ -350,14 +350,13 @@ eat_esc_string (char **strlst) if (*str == '"') { quoted = !quoted; continue; - } else if (quoted) - gstr = g_string_append_c (gstr, *str); - else if (*str == '\\') { + } else if (*str == '\\') { if (str[1] != ' ' && str[1] != '"' && str[1] != '\\') goto err; /* invalid escaping */ - g_string_append_c (gstr, *(str++)); + g_string_append_c (gstr, str[1]); + ++str; continue; - } else if (*str == ' ') { + } else if (*str == ' ' && !quoted) { ++str; goto leave; } else @@ -445,29 +444,25 @@ mu_str_ascii_xapian_escape_in_place (char *query, gboolean esc_space) switch (*cur) { case ' ': - if (!esc_space) - break; case '@': case '-': + case ';': case '/': - case '.': - { - /* don't replace a final special char */ - if (cur[1]== ' ' || cur[1]=='\t' || cur[1]== '.') - ++cur; - else if (cur[1] == '\0') - break; + *cur = escchar; + break; + case '.': /* don't escape '..' */ + if (cur[1]=='.') + cur += 1; else *cur = escchar; break; - } case ':': /* if there's a registered xapian prefix before the * ':', don't touch it. Otherwise replace ':' with - * a space'... ugh yuck ugly... + * a _'... ugh yuck ugly... */ if (!is_xapian_prefix (query, cur)) - *cur = ' '; + *cur = escchar; break; } }