Skip to content

Commit b21693a

Browse files
committed
Prevent multiple quotations of the same word
1 parent a1e5689 commit b21693a

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private function getSearchPattern(array $words): string
138138
$patterns = [];
139139
for ($lastItem = count($words); $lastItem > 0; $lastItem--) {
140140
$words = array_map(function ($word) {
141-
return preg_quote($word, '/');
141+
return preg_quote(stripslashes($word), '/');
142142
}, $words);
143143
$phrase = implode("\s+", \array_slice($words, 0, $lastItem));
144144
$patterns[] = '^' . $phrase . ',';

app/code/Magento/Search/Test/Unit/Model/SynonymAnalyzerTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,42 @@ public function testGetSynonymsForPhraseEmptyPhrase()
8484
$actual = $this->synonymAnalyzer->getSynonymsForPhrase($phrase);
8585
$this->assertEquals($expected, $actual);
8686
}
87+
88+
/**
89+
* @test
90+
*
91+
* Phrase that is long and has quotes in it scenario
92+
*/
93+
public function testLongQuotedPhrase()
94+
{
95+
$phrase = 'LSS 3/8"X3/4"X25\' EZ-PULL 1/2" INS SWEAT LINESET W/90 END BEND SUCTION LINE INSULATED';
96+
$expected = [
97+
0 => [ 0 => "LSS" ],
98+
1 => [ 0 => "3/8\"X3/4\"X25'" ],
99+
2 => [ 0 => "EZ-PULL" ],
100+
3 => [ 0 => "1/2\"" ],
101+
4 => [ 0 => "INS" ],
102+
5 => [ 0 => "SWEAT" ],
103+
6 => [ 0 => "LINESET" ],
104+
7 => [ 0 => "W/90" ],
105+
8 => [ 0 => "END" ],
106+
9 => [ 0 => "BEND", 1 => "TWIST" ],
107+
10 => [ 0 => "SUCTION", 1 => "WEIGHT" ],
108+
11 => [ 0 => "LINE" ],
109+
12 => [ 0 => "INSULATED" ]
110+
];
111+
$this->synReaderModel->expects($this->once())
112+
->method('loadByPhrase')
113+
->with($phrase)
114+
->willReturnSelf();
115+
$this->synReaderModel->expects($this->once())
116+
->method('getData')
117+
->willReturn([
118+
['synonyms' => 'BEND,TWIST'],
119+
['synonyms' => 'SUCTION,WEIGHT'],
120+
]);
121+
122+
$actual = $this->synonymAnalyzer->getSynonymsForPhrase($phrase);
123+
$this->assertEquals($expected, $actual);
124+
}
87125
}

0 commit comments

Comments
 (0)