Skip to content

Commit

Permalink
Merge 18e7869 into c76dd94
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Kalkbrenner committed Nov 14, 2018
2 parents c76dd94 + 18e7869 commit e9300d1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -4,7 +4,7 @@ All notable changes to the solarium library will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [master]
## [4.2.0]
### Added

### Changed
Expand All @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Removed

### Fixed
- If a term contains a space, the space needs to be quoted by Helper::escapeTerm()

### Security

Expand Down
4 changes: 2 additions & 2 deletions src/Core/Query/Helper.php
Expand Up @@ -59,15 +59,15 @@ public function __construct($query = null)
* If you want to use the input as a phrase please use the {@link phrase()}
* method, because a phrase requires much less escaping.\
*
* @see http://lucene.apache.org/java/docs/queryparsersyntax.html#Escaping%20Special%20Characters
* @see https://lucene.apache.org/core/7_5_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html#package.description
*
* @param string $input
*
* @return string
*/
public function escapeTerm($input)
{
$pattern = '/(\+|-|&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\*|\?|:|\/|\\\)/';
$pattern = '/( |\+|-|&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\*|\?|:|\/|\\\)/';

return preg_replace($pattern, '\\\$1', $input);
}
Expand Down
1 change: 1 addition & 0 deletions tests/Core/Query/HelperTest.php
Expand Up @@ -201,6 +201,7 @@ public function testFunctionCall()
public function testEscapeTerm()
{
$this->assertSame('a\\+b\/c', $this->helper->escapeTerm('a+b/c'));
$this->assertSame('a\ b', $this->helper->escapeTerm('a b'));
}

public function testEscapeTermNoEscape()
Expand Down

0 comments on commit e9300d1

Please sign in to comment.