From 45f760ea24501335948cf22b08737afd5491a794 Mon Sep 17 00:00:00 2001 From: Michael Busch Date: Wed, 23 May 2007 04:54:38 +0000 Subject: [PATCH] LUCENE-881: QueryParser.escape() now also escapes the characters '|' and '&' git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@540839 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 3 +++ src/java/org/apache/lucene/queryParser/QueryParser.java | 2 +- src/java/org/apache/lucene/queryParser/QueryParser.jj | 2 +- src/test/org/apache/lucene/queryParser/TestQueryParser.java | 4 ++++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 039016081fe..fe90a72c860 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -128,6 +128,9 @@ Bug fixes 16. LUCENE-883: consecutive calls to Spellchecker.indexDictionary() won't insert terms twice anymore. (Daniel Naber) +17. LUCENE-881: QueryParser.escape() now also escapes the characters + '|' and '&' which are part of the queryparser syntax. (Michael Busch) + New features 1. LUCENE-759: Added two n-gram-producing TokenFilters. diff --git a/src/java/org/apache/lucene/queryParser/QueryParser.java b/src/java/org/apache/lucene/queryParser/QueryParser.java index 742a6a9b121..2379ef74263 100644 --- a/src/java/org/apache/lucene/queryParser/QueryParser.java +++ b/src/java/org/apache/lucene/queryParser/QueryParser.java @@ -803,7 +803,7 @@ public class QueryParser implements QueryParserConstants { // These characters are part of the query syntax and must be escaped if (c == '\\' || c == '+' || c == '-' || c == '!' || c == '(' || c == ')' || c == ':' || c == '^' || c == '[' || c == ']' || c == '\"' || c == '{' || c == '}' || c == '~' - || c == '*' || c == '?') { + || c == '*' || c == '?' || c == '|' || c == '&') { sb.append('\\'); } sb.append(c); diff --git a/src/java/org/apache/lucene/queryParser/QueryParser.jj b/src/java/org/apache/lucene/queryParser/QueryParser.jj index 30565728adc..9272ef61f1b 100644 --- a/src/java/org/apache/lucene/queryParser/QueryParser.jj +++ b/src/java/org/apache/lucene/queryParser/QueryParser.jj @@ -827,7 +827,7 @@ public class QueryParser { // These characters are part of the query syntax and must be escaped if (c == '\\' || c == '+' || c == '-' || c == '!' || c == '(' || c == ')' || c == ':' || c == '^' || c == '[' || c == ']' || c == '\"' || c == '{' || c == '}' || c == '~' - || c == '*' || c == '?') { + || c == '*' || c == '?' || c == '|' || c == '&') { sb.append('\\'); } sb.append(c); diff --git a/src/test/org/apache/lucene/queryParser/TestQueryParser.java b/src/test/org/apache/lucene/queryParser/TestQueryParser.java index a019771d7a1..7c1550772ea 100644 --- a/src/test/org/apache/lucene/queryParser/TestQueryParser.java +++ b/src/test/org/apache/lucene/queryParser/TestQueryParser.java @@ -616,6 +616,10 @@ public class TestQueryParser extends TestCase { assertEscapedQueryEquals("[ a - TO a+ ]", null, "\\[ a \\- TO a\\+ \\]"); assertEscapedQueryEquals("[ a : TO a~ ]", null, "\\[ a \\: TO a\\~ \\]"); assertEscapedQueryEquals("[ a\\ TO a* ]", null, "\\[ a\\\\ TO a\\* \\]"); + + // LUCENE-881 + assertEscapedQueryEquals("|| abc ||", a, "\\|\\| abc \\|\\|"); + assertEscapedQueryEquals("&& abc &&", a, "\\&\\& abc \\&\\&"); } public void testTabNewlineCarriageReturn()