Skip to content

Commit 5fe627f

Browse files
committed
Merge pull request #722 from jkbnerad/master
Fixed replacing reserved words.
2 parents e6d4424 + 19a6418 commit 5fe627f

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

changes.txt

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
CHANGES
22

3+
2014-11-13
4+
- fixed reserved words in queries which composed of upper case letters (Util::replaceBooleanWords)
5+
36
2014-10-31
47
- Adding PSR-4 autoloading support
58

lib/Elastica/Util.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static function escapeTerm($term)
6565
*/
6666
public static function replaceBooleanWords($term)
6767
{
68-
$replacementMap = array('AND'=>'&&', 'OR'=>'||', 'NOT'=>'!');
68+
$replacementMap = array(' AND '=>' && ', ' OR '=>' || ', ' NOT '=>' !');
6969
$result = strtr($term, $replacementMap);
7070

7171
return $result;

test/lib/Elastica/Test/UtilTest.php

+20
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,26 @@ public function getEscapeTermPairs()
2929
);
3030
}
3131

32+
/**
33+
* @dataProvider getReplaceBooleanWordsPairs
34+
*/
35+
public function testReplaceBooleanWords($before, $after)
36+
{
37+
$this->assertEquals($after, Util::replaceBooleanWords($before));
38+
}
39+
40+
public function getReplaceBooleanWordsPairs()
41+
{
42+
return array(
43+
array('to be OR not to be', 'to be || not to be'),
44+
array('ORIGINAL GIFTS', 'ORIGINAL GIFTS'),
45+
array('Black AND White', 'Black && White'),
46+
array('TIMBERLAND Men`s', 'TIMBERLAND Men`s'),
47+
array('hello NOT kitty', 'hello !kitty'),
48+
array('SEND NOTIFICATION', 'SEND NOTIFICATION')
49+
);
50+
}
51+
3252
public function testEscapeTermSpecialCharacters()
3353
{
3454
$before = '\\+-&&||!(){}[]^"~*?:/';

0 commit comments

Comments
 (0)