diff --git a/src/mu-str.c b/src/mu-str.c index 0b550fc2..81484c94 100644 --- a/src/mu-str.c +++ b/src/mu-str.c @@ -406,6 +406,13 @@ check_for_field (const char *str, gboolean *is_field, gboolean *is_range_field) CheckPrefix pfx; pfx.str = str; + + /* skip any non-alphanum starts in cpfx->str; this is to + * handle the case where we have e.g. "(maildir:/abc)" + */ + while (pfx.str && !isalnum(*pfx.str)) + ++pfx.str; + pfx.match = pfx.range_field = FALSE; mu_msg_field_foreach ((MuMsgFieldForeachFunc)each_check_prefix, @@ -454,6 +461,8 @@ mu_str_xapian_escape_in_place (char *term, gboolean esc_space) *cur = escchar; ++colon; break; + case '(': + case ')': case '\'': case '*': /* wildcard */ break; diff --git a/src/tests/test-mu-query.c b/src/tests/test-mu-query.c index 4eb65bfc..dab1a147 100644 --- a/src/tests/test-mu-query.c +++ b/src/tests/test-mu-query.c @@ -223,7 +223,6 @@ test_mu_query_03 (void) g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query), ==, queries[i].count); g_free (xpath); - } @@ -234,10 +233,10 @@ test_mu_query_04 (void) int i; QResults queries[] = { - { "frodo@example.com", 1}, /* does not match: see mu-find (1) */ + { "frodo@example.com", 1}, { "f:frodo@example.com", 1}, { "f:Frodo Baggins", 1}, - { "bilbo@anotherexample.com", 1}, /* same things */ + { "bilbo@anotherexample.com", 1}, { "t:bilbo@anotherexample.com", 1}, { "t:bilbo", 1}, { "f:bilbo", 0}, @@ -256,10 +255,38 @@ test_mu_query_04 (void) g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query), ==, queries[i].count); g_free (xpath); - } +static void +test_mu_query_logic (void) +{ + gchar *xpath; + int i; + + QResults queries[] = { + { "subject:gcc" , 1}, + { "subject:lisp" , 1}, + { "subject:gcc OR subject:lisp" , 2}, + { "subject:gcc or subject:lisp" , 2}, + { "subject:gcc AND subject:lisp" , 0}, + + { "subject:gcc OR (subject:scheme AND subject:elisp)" , 2}, + { "(subject:gcc OR subject:scheme) AND subject:elisp" , 1} + }; + + xpath = fill_database (MU_TESTMAILDIR); + g_assert (xpath != NULL); + + for (i = 0; i != G_N_ELEMENTS(queries); ++i) + g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query), + ==, queries[i].count); + g_free (xpath); +} + + + + static void test_mu_query_accented_chars_01 (void) { @@ -599,6 +626,9 @@ main (int argc, char *argv[]) g_test_add_func ("/mu-query/test-mu-query-02", test_mu_query_02); g_test_add_func ("/mu-query/test-mu-query-03", test_mu_query_03); g_test_add_func ("/mu-query/test-mu-query-04", test_mu_query_04); + + g_test_add_func ("/mu-query/test-mu-query-logic", test_mu_query_logic); + g_test_add_func ("/mu-query/test-mu-query-accented-chars-1", test_mu_query_accented_chars_01); g_test_add_func ("/mu-query/test-mu-query-accented-chars-2", diff --git a/src/tests/test-mu-str.c b/src/tests/test-mu-str.c index 5409641c..fadb8882 100644 --- a/src/tests/test-mu-str.c +++ b/src/tests/test-mu-str.c @@ -199,7 +199,8 @@ test_mu_str_xapian_escape (void) { "size:10..20", "size:10..20"}, { "x:2010..2012", "x:2010__2012"}, { "q:2010..2012", "q_2010__2012"}, - { "subject:2010..2012", "subject:2010__2012"} + { "subject:2010..2012", "subject:2010__2012"}, + { "(maildir:foo)", "(maildir:foo)"} }; for (i = 0; i != G_N_ELEMENTS(words); ++i) {