Skip to content

Commit a757e8d

Browse files
committed
Merge pull request #592 from lalop/master
escape / with \\
2 parents 99fbfbf + 343d726 commit a757e8d

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/Elastica/Util.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@ public static function escapeTerm($term)
4444
{
4545
$result = $term;
4646
// \ escaping has to be first, otherwise escaped later once again
47-
$chars = array('\\', '+', '-', '&&', '||', '!', '(', ')', '{', '}', '[', ']', '^', '"', '~', '*', '?', ':', '/');
47+
$chars = array('\\', '+', '-', '&&', '||', '!', '(', ')', '{', '}', '[', ']', '^', '"', '~', '*', '?', ':');
4848

4949
foreach ($chars as $char) {
5050
$result = str_replace($char, '\\' . $char, $result);
5151
}
5252

53+
// since elastisearch uses lucene 4.0 / needs to be escaped by \\
54+
$result = str_replace('/', '\\\\/', $result);
55+
5356
return $result;
5457
}
5558

test/lib/Elastica/Test/UtilTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function getEscapeTermPairs()
3232
public function testEscapeTermSpecialCharacters()
3333
{
3434
$before = '\\+-&&||!(){}[]^"~*?:/';
35-
$after = '\\\\\\+\\-\\&&\\||\\!\\(\\)\\{\\}\\[\\]\\^\\"\\~\\*\\?\\:\\/';
35+
$after = '\\\\\\+\\-\\&&\\||\\!\\(\\)\\{\\}\\[\\]\\^\\"\\~\\*\\?\\:\\\\/';
3636

3737
$this->assertEquals(Util::escapeTerm($before), $after);
3838
}

0 commit comments

Comments
 (0)