Skip to content

Commit

Permalink
Change implementation to ensure one of current use cases is not broke…
Browse files Browse the repository at this point in the history
…n. Add case with slash in regression integration test.
  • Loading branch information
wojtekn committed Oct 5, 2020
1 parent 970d179 commit 38c4a3e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/code/Magento/Search/Model/SynonymAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ private function getSearchPattern(array $words): string
{
$patterns = [];
for ($lastItem = count($words); $lastItem > 0; $lastItem--) {
$words = array_map(function ($word) {
return preg_quote($word, '/');
}, $words);
$phrase = implode("\s+", \array_slice($words, 0, $lastItem));
$phrase = preg_quote($phrase, '/');
$patterns[] = '^' . $phrase . ',';
$patterns[] = ',' . $phrase . ',';
$patterns[] = ',' . $phrase . '$';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public static function loadGetSynonymsForPhraseDataProvider()
'phrase' => 'schlicht',
'expectedResult' => [['schlicht', 'natürlich']]
],
'withSlashInSearchPhrase' => [
'phrase' => 'orange hill/peak',
'expectedResult' => [['orange', 'magento'], ['hill/peak']]
],
];
}

Expand Down

0 comments on commit 38c4a3e

Please sign in to comment.