Skip to content

Commit ff7c5f1

Browse files
authored
Solarium\Core\Query\Helper::escapeTerm() has to quote reserved terms (#1079)
Solarium\Core\Query\Helper::escapeTerm() has to quote reserved terms `AND`, `OR`, `TO` closes #1078
1 parent adcf811 commit ff7c5f1

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- Solarium\QueryType\Extract\Query::setFile() now supports file pointer resources
1111
- Solarium\QueryType\Extract\Result::getFile() and getFileMetadata() to access the retrieved data for `extractOnly=true`
1212

13+
### Fixed
14+
- Solarium\Core\Query\Helper::escapeTerm() has to quote reserved terms `AND`, `OR`, `TO`
15+
1316
### Changed
1417
- Solarium\Core\Client\Endpoint::setAuthentication() marks $password as #[\SensitiveParameter] (PHP 8 >= 8.2.0)
1518
- Solarium\Core\Client\Endpoint::setAuthorizationToken() marks $token as #[\SensitiveParameter] (PHP 8 >= 8.2.0)

src/Core/Query/Helper.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ public function __construct(QueryInterface $query = null)
7575
*/
7676
public function escapeTerm(string $input): string
7777
{
78-
$pattern = '/( |\+|-|&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\*|\?|:|\/|\\\)/';
78+
if (preg_match('/(^|\s)(AND|OR|TO)($|\s)/', strtoupper($input), $matches)) {
79+
return $this->escapePhrase($input);
80+
}
7981

80-
return preg_replace($pattern, '\\\$1', $input);
82+
return preg_replace('/( |\+|-|&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\*|\?|:|\/|\\\)/', '\\\$1', $input);
8183
}
8284

8385
/**

tests/Core/Query/HelperTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,17 @@ public function escapeTermProvider(): array
435435
':' => ['a:b', 'a\\:b'],
436436
'/' => ['a/b', 'a\\/b'],
437437
'\\' => ['a\b', 'a\\\b'],
438+
'and' => ['and', '"and"'],
439+
'AND' => ['AND', '"AND"'],
440+
'or' => ['or', '"or"'],
441+
'OR' => ['OR', '"OR"'],
442+
'to' => ['to', '"to"'],
443+
'TO' => ['TO', '"TO"'],
444+
' AnD ' => [' AnD ', '" AnD "'],
445+
'AND or' => ['AND or', '"AND or"'],
446+
'Animals and plants' => ['Animals and plants', '"Animals and plants"'],
447+
'boring' => ['boring', 'boring'],
448+
'Band' => ['Band', 'Band'],
438449
];
439450
}
440451

0 commit comments

Comments
 (0)