Skip to content

Commit e057627

Browse files
committed
Merge branch 'MAGETWO-99655' of https://github.com/magento-tango/magento2ce into PR_2019_06_18
2 parents 0dc9315 + 21fd3d1 commit e057627

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

app/code/Magento/Search/Model/ResourceModel/SynonymReader.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private function queryByPhrase($phrase)
8787
{
8888
$matchQuery = $this->fullTextSelect->getMatchQuery(
8989
['synonyms' => 'synonyms'],
90-
$phrase,
90+
$this->escapePhrase($phrase),
9191
Fulltext::FULLTEXT_MODE_BOOLEAN
9292
);
9393
$query = $this->getConnection()->select()->from(
@@ -97,6 +97,18 @@ private function queryByPhrase($phrase)
9797
return $this->getConnection()->fetchAll($query);
9898
}
9999

100+
/**
101+
* Cut trailing plus or minus sign, and @ symbol, using of which causes InnoDB to report a syntax error.
102+
*
103+
* @see https://dev.mysql.com/doc/refman/5.7/en/fulltext-boolean.html
104+
* @param string $phrase
105+
* @return string
106+
*/
107+
private function escapePhrase(string $phrase): string
108+
{
109+
return preg_replace('/@+|[@+-]+$|[<>]/', '', $phrase);
110+
}
111+
100112
/**
101113
* A private helper function to retrieve matching synonym groups per scope
102114
*

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,31 @@ public static function loadByPhraseDataProvider()
4848
['synonyms' => 'queen,monarch', 'store_id' => 1, 'website_id' => 0],
4949
['synonyms' => 'british,english', 'store_id' => 1, 'website_id' => 0]
5050
]
51-
]
51+
],
52+
[
53+
'query_value', []
54+
],
55+
[
56+
'query_value+', []
57+
],
58+
[
59+
'query_value-', []
60+
],
61+
[
62+
'query_@value', []
63+
],
64+
[
65+
'query_value+@', []
66+
],
67+
[
68+
'<', []
69+
],
70+
[
71+
'>', []
72+
],
73+
[
74+
'<english>', [['synonyms' => 'british,english', 'store_id' => 1, 'website_id' => 0]]
75+
],
5276
];
5377
}
5478

0 commit comments

Comments
 (0)