From 26e1223d0b98f56cf288fb8fdf1acaa15047db2b Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Sun, 28 Aug 2011 00:09:45 +0200 Subject: [PATCH] ccl2rpn: more characters to escape (regexp-1). --- src/cclfind.c | 7 +++++-- test/test_ccl.c | 14 +++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/cclfind.c b/src/cclfind.c index f242169..6fd3144 100644 --- a/src/cclfind.c +++ b/src/cclfind.c @@ -213,6 +213,7 @@ void ccl_add_attr_string(struct ccl_rpn_node *p, const char *set, } +#define REGEX_CHARS "^[]{}()|.*+?!\"$" /** * search_term: Parse CCL search term. * cclp: CCL Parser @@ -386,11 +387,13 @@ static struct ccl_rpn_node *search_term_x(CCL_parser cclp, { if (j > 0 && src_str[j-1] == '\\') { - if (regex_trunc && strchr("()[]?*.", src_str[j])) + if (regex_trunc && strchr(REGEX_CHARS "\\", src_str[j])) { regex_trunc = 2; strcat(p->u.t.term, "\\\\"); } + if (src_str[j] == '\\') + strcat(p->u.t.term, "\\"); strxcat(p->u.t.term, src_str + j, 1); } else if (src_str[j] == '"') @@ -429,7 +432,7 @@ static struct ccl_rpn_node *search_term_x(CCL_parser cclp, } else if (src_str[j] != '\\') { - if (regex_trunc && strchr("()[]?*.", src_str[j])) + if (regex_trunc && strchr(REGEX_CHARS, src_str[j])) { regex_trunc = 2; strcat(p->u.t.term, "\\\\"); diff --git a/test/test_ccl.c b/test/test_ccl.c index 72370e3..76d76ba 100644 --- a/test/test_ccl.c +++ b/test/test_ccl.c @@ -260,12 +260,24 @@ void tst1(int pass) YAZ_CHECK(tst_ccl_query(bibset, "title=.", "@attr 5=102 @attr 1=/my/title \\\\. ")); - YAZ_CHECK(tst_ccl_query(bibset, "title=\\.", + YAZ_CHECK(tst_ccl_query(bibset, "title=.", "@attr 5=102 @attr 1=/my/title \\\\. ")); YAZ_CHECK(tst_ccl_query(bibset, "title=\".\"", "@attr 5=102 @attr 1=/my/title \\\\. ")); + YAZ_CHECK(tst_ccl_query(bibset, "title=?\\?", + "@attr 5=102 @attr 1=/my/title .*\\\\? ")); + + YAZ_CHECK(tst_ccl_query(bibset, "title=\"?\\?\"", + "@attr 5=102 @attr 1=/my/title \\\\?\\\\? ")); + + YAZ_CHECK(tst_ccl_query(bibset, "title=\\\\", + "@attr 5=102 @attr 1=/my/title \\\\\\\\ ")); + + YAZ_CHECK(tst_ccl_query(bibset, "\\\\", + "@attr 4=2 @attr 1=1016 \\\\ ")); + YAZ_CHECK(tst_ccl_query(bibset, "comb=a", "@or @attr 4=2 @attr 1=1016 a " "@attr 1=/my/title a ")); -- 1.7.10.4