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
This commit is contained in:
Michael Busch 2007-05-23 04:54:38 +00:00
parent b1eb460b7e
commit 45f760ea24
4 changed files with 9 additions and 2 deletions

View File

@ -128,6 +128,9 @@ Bug fixes
16. LUCENE-883: consecutive calls to Spellchecker.indexDictionary() 16. LUCENE-883: consecutive calls to Spellchecker.indexDictionary()
won't insert terms twice anymore. (Daniel Naber) 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 New features
1. LUCENE-759: Added two n-gram-producing TokenFilters. 1. LUCENE-759: Added two n-gram-producing TokenFilters.

View File

@ -803,7 +803,7 @@ public class QueryParser implements QueryParserConstants {
// These characters are part of the query syntax and must be escaped // These characters are part of the query syntax and must be escaped
if (c == '\\' || c == '+' || c == '-' || c == '!' || c == '(' || c == ')' || c == ':' if (c == '\\' || c == '+' || c == '-' || c == '!' || c == '(' || c == ')' || c == ':'
|| c == '^' || c == '[' || c == ']' || c == '\"' || c == '{' || c == '}' || c == '~' || c == '^' || c == '[' || c == ']' || c == '\"' || c == '{' || c == '}' || c == '~'
|| c == '*' || c == '?') { || c == '*' || c == '?' || c == '|' || c == '&') {
sb.append('\\'); sb.append('\\');
} }
sb.append(c); sb.append(c);

View File

@ -827,7 +827,7 @@ public class QueryParser {
// These characters are part of the query syntax and must be escaped // These characters are part of the query syntax and must be escaped
if (c == '\\' || c == '+' || c == '-' || c == '!' || c == '(' || c == ')' || c == ':' if (c == '\\' || c == '+' || c == '-' || c == '!' || c == '(' || c == ')' || c == ':'
|| c == '^' || c == '[' || c == ']' || c == '\"' || c == '{' || c == '}' || c == '~' || c == '^' || c == '[' || c == ']' || c == '\"' || c == '{' || c == '}' || c == '~'
|| c == '*' || c == '?') { || c == '*' || c == '?' || c == '|' || c == '&') {
sb.append('\\'); sb.append('\\');
} }
sb.append(c); sb.append(c);

View File

@ -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\\~ \\]"); 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() public void testTabNewlineCarriageReturn()