Skip to content

Commit 38c4a3e

Browse files
committed
Change implementation to ensure one of current use cases is not broken. Add case with slash in regression integration test.
1 parent 970d179 commit 38c4a3e

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

app/code/Magento/Search/Model/SynonymAnalyzer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,10 @@ private function getSearchPattern(array $words): string
137137
{
138138
$patterns = [];
139139
for ($lastItem = count($words); $lastItem > 0; $lastItem--) {
140+
$words = array_map(function ($word) {
141+
return preg_quote($word, '/');
142+
}, $words);
140143
$phrase = implode("\s+", \array_slice($words, 0, $lastItem));
141-
$phrase = preg_quote($phrase, '/');
142144
$patterns[] = '^' . $phrase . ',';
143145
$patterns[] = ',' . $phrase . ',';
144146
$patterns[] = ',' . $phrase . '$';

dev/tests/integration/testsuite/Magento/Search/Model/SynonymAnalyzerTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ public static function loadGetSynonymsForPhraseDataProvider()
7878
'phrase' => 'schlicht',
7979
'expectedResult' => [['schlicht', 'natürlich']]
8080
],
81+
'withSlashInSearchPhrase' => [
82+
'phrase' => 'orange hill/peak',
83+
'expectedResult' => [['orange', 'magento'], ['hill/peak']]
84+
],
8185
];
8286
}
8387

0 commit comments

Comments
 (0)