Skip to content

Commit f2546ba

Browse files
Merge remote-tracking branch 'origin/MC-35095' into 2.4-develop-pr36
2 parents 180686d + 2746def commit f2546ba

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

app/code/Magento/Elasticsearch/SearchAdapter/Query/ValueTransformer/TextTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function transform(string $value): string
5757
*/
5858
private function escape(string $value): string
5959
{
60-
$pattern = '/(\+|-|&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\*|\?|:|\\\)/';
60+
$pattern = '/(\+|-|&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\/|\*|\?|:|\\\)/';
6161
$replace = '\\\$1';
6262

6363
return preg_replace($pattern, $replace, $value);
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Elasticsearch\Test\Unit\SearchAdapter\Query\ValueTransformer;
9+
10+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
11+
use Magento\Elasticsearch\SearchAdapter\Query\ValueTransformer\TextTransformer;
12+
use PHPUnit\Framework\TestCase;
13+
14+
/**
15+
* Test value transformer
16+
*/
17+
class TextTransformerTest extends TestCase
18+
{
19+
/**
20+
* @var TextTransformer
21+
*/
22+
protected $model;
23+
24+
/**
25+
* Setup method
26+
* @return void
27+
*/
28+
public function setUp(): void
29+
{
30+
$objectManagerHelper = new ObjectManagerHelper($this);
31+
$this->model = $objectManagerHelper->getObject(
32+
TextTransformer::class,
33+
[
34+
'$preprocessors' => [],
35+
]
36+
);
37+
}
38+
39+
/**
40+
* Test transform value
41+
*
42+
* @param string $value
43+
* @param string $expected
44+
* @return void
45+
* @dataProvider valuesDataProvider
46+
*/
47+
public function testTransform(string $value, string $expected): void
48+
{
49+
$result = $this->model->transform($value);
50+
$this->assertEquals($expected, $result);
51+
}
52+
53+
/**
54+
* Values data provider
55+
*
56+
* @return array
57+
*/
58+
public function valuesDataProvider(): array
59+
{
60+
return [
61+
['Laptop^camera{microphone}', 'Laptop\^camera\{microphone\}'],
62+
['Birthday 25-Pack w/ Greatest of All Time Cupcake', 'Birthday 25\-Pack w\/ Greatest of All Time Cupcake'],
63+
['Retro vinyl record ~d123 *star', 'Retro vinyl record \~d123 \*star'],
64+
];
65+
}
66+
}

0 commit comments

Comments
 (0)