-
Notifications
You must be signed in to change notification settings - Fork 732
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #795 from topikito/escape-new-symbols
[RFR] Escape new symbols in Util::escapeTerm (fixes #794)
- Loading branch information
Showing
2 changed files
with
6 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
* @author Nicolas Ruflin <[email protected]> | ||
* @author Thibault Duplessis <[email protected]> | ||
* @author Oleg Zinchenko <[email protected]> | ||
* @author Roberto Nygaard <[email protected]> | ||
*/ | ||
class Util | ||
{ | ||
|
@@ -35,9 +36,10 @@ public static function replaceBooleanWordsAndEscapeTerm($term) | |
|
||
/** | ||
* Escapes the following terms (because part of the query language) | ||
* + - && || ! ( ) { } [ ] ^ " ~ * ? : \ | ||
* + - && || ! ( ) { } [ ] ^ " ~ * ? : \ < > | ||
* | ||
* @link http://lucene.apache.org/java/2_4_0/queryparsersyntax.html#Escaping%20Special%20Characters | ||
* @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#_reserved_characters | ||
* | ||
* @param string $term Query term to escape | ||
* @return string Escaped query term | ||
|
@@ -46,7 +48,7 @@ public static function escapeTerm($term) | |
{ | ||
$result = $term; | ||
// \ escaping has to be first, otherwise escaped later once again | ||
$chars = array('\\', '+', '-', '&&', '||', '!', '(', ')', '{', '}', '[', ']', '^', '"', '~', '*', '?', ':', '/'); | ||
$chars = array('\\', '+', '-', '&&', '||', '!', '(', ')', '{', '}', '[', ']', '^', '"', '~', '*', '?', ':', '/', '<', '>'); | ||
|
||
foreach ($chars as $char) { | ||
$result = str_replace($char, '\\'.$char, $result); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters