Skip to content

Commit a2fa1b1

Browse files
committed
MAGETWO-44555: Exception in Advanced Search if used special symbols
- Fixed bug
1 parent 8b13f99 commit a2fa1b1

File tree

4 files changed

+6
-3
lines changed

4 files changed

+6
-3
lines changed

app/code/Magento/CatalogSearch/Model/Advanced/Request/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function bindRequestValue($attributeCode, $attributeValue)
2727
} elseif (!is_array($attributeValue)) {
2828
$this->bind($attributeCode, $attributeValue);
2929
} elseif (isset($attributeValue['like'])) {
30-
$this->bind($attributeCode, trim($attributeValue['like'], '%'));
30+
$this->bind($attributeCode, $attributeValue['like']);
3131
} elseif (isset($attributeValue['in'])) {
3232
$this->bind($attributeCode, $attributeValue['in']);
3333
} elseif (isset($attributeValue['in_set'])) {

app/code/Magento/CatalogSearch/Model/ResourceModel/Advanced.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function prepareCondition($attribute, $value)
8181
} else {
8282
if (strlen($value) > 0) {
8383
if (in_array($attribute->getBackendType(), ['varchar', 'text', 'static'])) {
84-
$condition = ['like' => '%' . $value . '%']; // text search
84+
$condition = ['like' => $value]; // text search
8585
} else {
8686
$condition = $value;
8787
}

lib/internal/Magento/Framework/DB/Helper/Mysql/Fulltext.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public function getMatchQuery($columns, $expression, $mode = self::FULLTEXT_MODE
6868

6969
$expression = $this->connection->quote($expression);
7070

71+
$expression = str_replace('%', '\\%', $expression);
72+
7173
$condition = self::MATCH . " ({$columns}) " . self::AGAINST . " ({$expression} {$mode})";
7274
return $condition;
7375
}

lib/internal/Magento/Framework/Search/Request/Cleaner.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ private function cleanQuery($queryName)
9090
}
9191
break;
9292
case QueryInterface::TYPE_MATCH:
93-
if (preg_match('/\$(.+)\$/si', $query['value'], $matches)) {
93+
if (preg_match('/\$(.+)\$/si', $query['value'], $matches)
94+
&& !preg_match('/^\$+$/si', $query['value'], $matches)) {
9495
unset($this->requestData['queries'][$queryName]);
9596
}
9697
break;

0 commit comments

Comments
 (0)