* mu-str: treat '..' in non-range fields differently

This commit is contained in:
djcb
2013-06-01 06:07:29 -07:00
parent 60f75eea42
commit d57b109557
2 changed files with 13 additions and 6 deletions

View File

@ -463,7 +463,7 @@ check_for_field (const char *str, gboolean *is_field,
static gboolean static gboolean
handle_esc_maybe (GString *gstr, char **cur, gunichar uc, handle_esc_maybe (GString *gstr, char **cur, gunichar uc,
gboolean query_esc) gboolean query_esc, gboolean range_field)
{ {
char kar; char kar;
@ -480,6 +480,9 @@ handle_esc_maybe (GString *gstr, char **cur, gunichar uc,
g_string_append_c (gstr, kar); g_string_append_c (gstr, kar);
return TRUE; return TRUE;
case '.': case '.':
if (!range_field)
break;
if ((*cur)[1] == '.' && (*cur)[2] != '.') { if ((*cur)[1] == '.' && (*cur)[2] != '.') {
g_string_append (gstr, ".."); g_string_append (gstr, "..");
*cur = g_utf8_next_char (*cur); *cur = g_utf8_next_char (*cur);
@ -503,6 +506,7 @@ process_str (const char *str, gboolean xapian_esc, gboolean query_esc)
{ {
GString *gstr; GString *gstr;
char *norm, *cur; char *norm, *cur;
gboolean is_field, is_range_field;
norm = g_utf8_normalize (str, -1, G_NORMALIZE_ALL); norm = g_utf8_normalize (str, -1, G_NORMALIZE_ALL);
if (G_UNLIKELY(!norm)) { /* not valid utf8? */ if (G_UNLIKELY(!norm)) { /* not valid utf8? */
@ -515,6 +519,8 @@ process_str (const char *str, gboolean xapian_esc, gboolean query_esc)
if (!norm) if (!norm)
return NULL; return NULL;
check_for_field (str, &is_field, &is_range_field);
gstr = g_string_sized_new (strlen (norm)); gstr = g_string_sized_new (strlen (norm));
for (cur = norm; cur && *cur; cur = g_utf8_next_char (cur)) { for (cur = norm; cur && *cur; cur = g_utf8_next_char (cur)) {
@ -524,7 +530,8 @@ process_str (const char *str, gboolean xapian_esc, gboolean query_esc)
uc = g_utf8_get_char (cur); uc = g_utf8_get_char (cur);
if (xapian_esc) if (xapian_esc)
if (handle_esc_maybe (gstr, &cur, uc, query_esc)) if (handle_esc_maybe (gstr, &cur, uc, query_esc,
is_range_field))
continue; continue;
if (g_unichar_ismark(uc)) if (g_unichar_ismark(uc))

View File

@ -195,7 +195,7 @@ test_mu_str_process_query_term (void)
const char* esc; const char* esc;
} words [] = { } words [] = {
{ "aap@noot.mies", "aap_noot_mies" }, { "aap@noot.mies", "aap_noot_mies" },
{ "Foo..Bar", "foo..bar" }, { "Foo..Bar", "foo__bar" },
{ "Foo.Bar", "foo_bar" }, { "Foo.Bar", "foo_bar" },
{ "Foo Bar", "foo_bar" }, { "Foo Bar", "foo_bar" },
{ "\\foo", "_foo" }, { "\\foo", "_foo" },
@ -205,9 +205,9 @@ test_mu_str_process_query_term (void)
{ "date:2010..2012", "date:2010..2012"}, { "date:2010..2012", "date:2010..2012"},
{ "d:2010..2012", "d:2010..2012"}, { "d:2010..2012", "d:2010..2012"},
{ "size:10..20", "size:10..20"}, { "size:10..20", "size:10..20"},
{ "x:2010..2012", "x:2010..2012"}, { "x:2010..2012", "x:2010__2012"},
{ "q:2010..2012", "q:2010..2012"}, { "q:2010..2012", "q:2010__2012"},
{ "subject:2010..2012", "subject:2010..2012"}, { "subject:2010..2012", "subject:2010__2012"},
{ "(maildir:foo)", "(maildir:foo)"}, { "(maildir:foo)", "(maildir:foo)"},
{ "Тесла, Никола", "тесла__никола"}, { "Тесла, Никола", "тесла__никола"},
{ "Masha@Аркона.ru", "masha_аркона_ru" }, { "Masha@Аркона.ru", "masha_аркона_ru" },