Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-31248: Fixed handling non-printable characters for Search #2904

Merged
merged 10 commits into from
May 6, 2020
45 changes: 34 additions & 11 deletions eZ/Publish/API/Repository/Tests/SearchServiceLocationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
*/
namespace eZ\Publish\API\Repository\Tests;

use eZ\Publish\API\Repository\Exceptions\NotImplementedException;
use eZ\Publish\API\Repository\Tests\SetupFactory\Legacy;
use eZ\Publish\API\Repository\Tests\SetupFactory\LegacyElasticsearch;
use eZ\Publish\API\Repository\Values\Content\Content;
use eZ\Publish\Core\Repository\Values\Content\Location;
use eZ\Publish\API\Repository\Values\Content\LocationQuery;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
use eZ\Publish\API\Repository\Values\Content\Query\SortClause;
use eZ\Publish\API\Repository\Values\Content\Search\SearchResult;
use eZ\Publish\API\Repository\Values\Content\Search\SearchHit;
use eZ\Publish\API\Repository\Exceptions\NotImplementedException;
use eZ\Publish\API\Repository\Values\Content\Search\SearchResult;
use eZ\Publish\Core\Repository\Values\Content\Location;

/**
* Test case for Location operations in the SearchService.
Expand Down Expand Up @@ -55,7 +56,7 @@ public function testFindFacetedLocation(LocationQuery $query, $fixture)
/**
* Create test Content with ezcountry field having multiple countries selected.
*
* @return Content
* @return \eZ\Publish\API\Repository\Values\Content\Content
*/
protected function createMultipleCountriesContent()
{
Expand Down Expand Up @@ -209,6 +210,35 @@ public function testNonPrintableUtf8Characters(): void
);
}

/**
* @covers \eZ\Publish\API\Repository\SearchService::findLocations
*/
public function testEscapedNonPrintableUtf8Characters(): void
{
$setupFactory = $this->getSetupFactory();
if ($setupFactory instanceof Legacy) {
andrerom marked this conversation as resolved.
Show resolved Hide resolved
$this->markTestSkipped(
'Field Value mappers are not used with Legacy Search Engine'
);
}

$query = new LocationQuery(
[
'query' => new Criterion\Field(
'name',
Criterion\Operator::EQ,
'Non PrintableFolder'
),
]
);

$repository = $this->getRepository();
$searchService = $repository->getSearchService();
$result = $searchService->findLocations($query);

$this->assertEquals(1, $result->totalCount);
}

/**
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
*/
Expand Down Expand Up @@ -276,8 +306,6 @@ public function testFindLocationsWithNonSearchableField()
}

/**
* @param \eZ\Publish\API\Repository\Values\Content\Search\SearchResult $result
*
* @return array
*/
protected function mapResultLocationIds(SearchResult $result)
Expand Down Expand Up @@ -1188,7 +1216,6 @@ public function testVisibilityCriterionWithHiddenContent()
/**
* Assert that query result matches the given fixture.
*
* @param LocationQuery $query
* @param string $fixture
* @param null|callable $closure
*/
Expand Down Expand Up @@ -1261,8 +1288,6 @@ protected function assertQueryFixture(LocationQuery $query, $fixture, $closure =
/**
* Show a simplified view of the search result for manual introspection.
*
* @param SearchResult $result
*
* @return string
*/
protected function printResult(SearchResult $result)
Expand All @@ -1280,8 +1305,6 @@ protected function printResult(SearchResult $result)
*
* This leads to saner comparisons of results, since we do not get the full
* content objects every time.
*
* @param SearchResult $result
*/
protected function simplifySearchResult(SearchResult $result)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
namespace eZ\Publish\Core\Search\Common\FieldValueMapper;

use eZ\Publish\Core\Search\Common\FieldValueMapper;
use eZ\Publish\SPI\Search\FieldType;
use eZ\Publish\SPI\Search\Field;
use eZ\Publish\SPI\Search\FieldType;

/**
* Common string field value mapper implementation.
Expand All @@ -20,12 +20,9 @@ class StringMapper extends FieldValueMapper
public const REPLACE_WITH_SPACE_PATTERN = '([\x09\x0B\x0C]+)';
public const REMOVE_PATTERN = '([\x00-\x08\x0E-\x1F]+)';


/**
* Check if field can be mapped.
*
* @param \eZ\Publish\SPI\Search\Field $field
*
* @return bool
*/
public function canMap(Field $field)
Expand All @@ -37,8 +34,6 @@ public function canMap(Field $field)
/**
* Map field value to a proper search engine representation.
*
* @param \eZ\Publish\SPI\Search\Field $field
*
* @return mixed
*/
public function map(Field $field)
Expand Down