Skip to content

Commit 36853c0

Browse files
Added test + some refactoring
1 parent 5f378de commit 36853c0

File tree

2 files changed

+65
-3
lines changed

2 files changed

+65
-3
lines changed

eZ/Publish/API/Repository/Tests/SearchServiceLocationTest.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,35 @@ protected function createMultipleCountriesContent()
101101
return $content;
102102
}
103103

104+
/**
105+
* Create test Content with non-printable characters in name.
106+
*
107+
* @return \eZ\Publish\API\Repository\Values\Content\Content
108+
*/
109+
protected function createFolderWithNonPrintableUtf8Characters()
110+
{
111+
$repository = $this->getRepository();
112+
$contentTypeService = $repository->getContentTypeService();
113+
$contentService = $repository->getContentService();
114+
115+
$contentType = $contentTypeService->loadContentTypeByIdentifier('folder');
116+
$createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
117+
$createStruct->remoteId = 'non-printable-char-folder-123';
118+
$createStruct->alwaysAvailable = false;
119+
$createStruct->setField(
120+
'name',
121+
utf8_decode("Non\x09Printable\x0EFolder")
122+
);
123+
124+
$locationCreateStruct = $repository->getLocationService()->newLocationCreateStruct(2);
125+
$draft = $contentService->createContent($createStruct, [$locationCreateStruct]);
126+
$content = $contentService->publishVersion($draft->getVersionInfo());
127+
128+
$this->refreshSearch($repository);
129+
130+
return $content;
131+
}
132+
104133
/**
105134
* Test for the findLocations() method.
106135
*
@@ -157,6 +186,35 @@ public function testFieldCollectionContainsNoMatch()
157186
$this->assertEquals(0, $result->totalCount);
158187
}
159188

189+
/**
190+
* Test for the findLocations() method.
191+
*
192+
* @see \eZ\Publish\API\Repository\SearchService::findLocations()
193+
*/
194+
public function testNonPrintableUtf8Characters()
195+
{
196+
$folder = $this->createFolderWithNonPrintableUtf8Characters();
197+
$query = new LocationQuery(
198+
[
199+
'query' => new Criterion\Field(
200+
'name',
201+
Criterion\Operator::EQ,
202+
utf8_decode("Non\x09Printable\x0EFolder")
203+
),
204+
]
205+
);
206+
207+
$repository = $this->getRepository();
208+
$searchService = $repository->getSearchService();
209+
$result = $searchService->findLocations($query);
210+
211+
$this->assertEquals(1, $result->totalCount);
212+
$this->assertEquals(
213+
$folder->contentInfo->mainLocationId,
214+
$result->searchHits[0]->valueObject->id
215+
);
216+
}
217+
160218
/**
161219
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
162220
*/

eZ/Publish/Core/Search/Common/FieldValueMapper/StringMapper.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
*/
1818
class StringMapper extends FieldValueMapper
1919
{
20+
public const REPLACE_WITH_SPACE_PATTERN = '([\x09\x0B\x0C]+)';
21+
public const REMOVE_PATTERN = '([\x00-\x08\x0E-\x1F]+)';
22+
23+
2024
/**
2125
* Check if field can be mapped.
2226
*
@@ -53,14 +57,14 @@ protected function convert($value)
5357
{
5458
// Replace tab, vertical tab, form-feed chars to single space.
5559
$value = preg_replace(
56-
'([\x09\x0B\x0C]+)',
60+
self::REPLACE_WITH_SPACE_PATTERN,
5761
' ',
5862
(string)$value
5963
);
6064

61-
// Remove non-printable characters (except LF and CR).
65+
// Remove non-printable characters.
6266
return preg_replace(
63-
'([\x00-\x08\x0E-\x1F]+)',
67+
self::REMOVE_PATTERN,
6468
'',
6569
(string)$value
6670
);

0 commit comments

Comments
 (0)