From d625bd505aa94bc9f82ea9eeed699082f9119ea4 Mon Sep 17 00:00:00 2001 From: Kamil Madejski Date: Fri, 25 Oct 2019 12:14:32 +0200 Subject: [PATCH 1/2] EZP-30759: Creating content with terminal escape codes chars inside Searchable field will return 500 error when using Solr --- bundle/Resources/config/services.yml | 1 + .../BlockDocumentsBaseContentFields.php | 12 ++++++++++-- .../BlockDocumentsContentFields.php | 12 ++++++++++-- .../ContentDocumentFulltextFields.php | 12 ++++++++++-- .../ContentDocumentTranslatedContentNameField.php | 12 ++++++++++-- .../config/container/solr/field_mappers.yml | 4 ++++ 6 files changed, 45 insertions(+), 8 deletions(-) diff --git a/bundle/Resources/config/services.yml b/bundle/Resources/config/services.yml index a616c7921..ee99d4a94 100644 --- a/bundle/Resources/config/services.yml +++ b/bundle/Resources/config/services.yml @@ -2,6 +2,7 @@ parameters: ezpublish.solr.engine_factory.class: EzSystems\EzPlatformSolrSearchEngineBundle\ApiLoader\SolrEngineFactory ezpublish.solr.boost_factor_provider_factory.class: EzSystems\EzPlatformSolrSearchEngineBundle\ApiLoader\BoostFactorProviderFactory ez_search_engine_solr.default_connection: ~ + ez_search_engine_solr.invalid_characters_pattern: "#\\x1b[[][^A-Za-z]*[A-Za-z]#" services: ezpublish.solr.engine_factory: diff --git a/lib/FieldMapper/ContentFieldMapper/BlockDocumentsBaseContentFields.php b/lib/FieldMapper/ContentFieldMapper/BlockDocumentsBaseContentFields.php index adff8add9..82fd8c3dc 100644 --- a/lib/FieldMapper/ContentFieldMapper/BlockDocumentsBaseContentFields.php +++ b/lib/FieldMapper/ContentFieldMapper/BlockDocumentsBaseContentFields.php @@ -42,22 +42,30 @@ class BlockDocumentsBaseContentFields extends ContentFieldMapper */ protected $sectionHandler; + /** + * @var string + */ + private $invalidCharactersPattern; + /** * @param \eZ\Publish\SPI\Persistence\Content\Location\Handler $locationHandler * @param \eZ\Publish\SPI\Persistence\Content\Type\Handler $contentTypeHandler * @param \eZ\Publish\SPI\Persistence\Content\ObjectState\Handler $objectStateHandler * @param \eZ\Publish\SPI\Persistence\Content\Section\Handler $sectionHandler + * @param string $invalidCharactersPattern */ public function __construct( LocationHandler $locationHandler, ContentTypeHandler $contentTypeHandler, ObjectStateHandler $objectStateHandler, - SectionHandler $sectionHandler + SectionHandler $sectionHandler, + $invalidCharactersPattern ) { $this->locationHandler = $locationHandler; $this->contentTypeHandler = $contentTypeHandler; $this->objectStateHandler = $objectStateHandler; $this->sectionHandler = $sectionHandler; + $this->invalidCharactersPattern = $invalidCharactersPattern; } public function accept(Content $content) @@ -104,7 +112,7 @@ public function mapFields(Content $content) ), new Field( 'content_name', - $contentInfo->name, + preg_replace($this->invalidCharactersPattern, '', $contentInfo->name), new FieldType\StringField() ), new Field( diff --git a/lib/FieldMapper/ContentTranslationFieldMapper/BlockDocumentsContentFields.php b/lib/FieldMapper/ContentTranslationFieldMapper/BlockDocumentsContentFields.php index 50bb1d2d9..d64da1274 100644 --- a/lib/FieldMapper/ContentTranslationFieldMapper/BlockDocumentsContentFields.php +++ b/lib/FieldMapper/ContentTranslationFieldMapper/BlockDocumentsContentFields.php @@ -44,22 +44,30 @@ class BlockDocumentsContentFields extends ContentTranslationFieldMapper */ protected $boostFactorProvider; + /** + * @var string + */ + private $invalidCharactersPattern; + /** * @param \eZ\Publish\SPI\Persistence\Content\Type\Handler $contentTypeHandler * @param \eZ\Publish\Core\Search\Common\FieldRegistry $fieldRegistry * @param \eZ\Publish\Core\Search\Common\FieldNameGenerator $fieldNameGenerator * @param \EzSystems\EzPlatformSolrSearchEngine\FieldMapper\BoostFactorProvider $boostFactorProvider + * @param string $invalidCharactersPattern */ public function __construct( ContentTypeHandler $contentTypeHandler, FieldRegistry $fieldRegistry, FieldNameGenerator $fieldNameGenerator, - BoostFactorProvider $boostFactorProvider + BoostFactorProvider $boostFactorProvider, + $invalidCharactersPattern ) { $this->contentTypeHandler = $contentTypeHandler; $this->fieldRegistry = $fieldRegistry; $this->fieldNameGenerator = $fieldNameGenerator; $this->boostFactorProvider = $boostFactorProvider; + $this->invalidCharactersPattern = $invalidCharactersPattern; } public function accept(Content $content, $languageCode) @@ -102,7 +110,7 @@ public function mapFields(Content $content, $languageCode) $fieldDefinition->identifier, $contentType->identifier ), - $indexField->value, + preg_replace($this->invalidCharactersPattern, '', $indexField->value), $this->getIndexFieldType($contentType, $fieldDefinition, $indexField->type) ); } diff --git a/lib/FieldMapper/ContentTranslationFieldMapper/ContentDocumentFulltextFields.php b/lib/FieldMapper/ContentTranslationFieldMapper/ContentDocumentFulltextFields.php index f55252080..694420a96 100644 --- a/lib/FieldMapper/ContentTranslationFieldMapper/ContentDocumentFulltextFields.php +++ b/lib/FieldMapper/ContentTranslationFieldMapper/ContentDocumentFulltextFields.php @@ -50,22 +50,30 @@ class ContentDocumentFulltextFields extends ContentTranslationFieldMapper */ protected $boostFactorProvider; + /** + * @var string + */ + private $invalidCharactersPattern; + /** * @param \eZ\Publish\SPI\Persistence\Content\Type\Handler $contentTypeHandler * @param \eZ\Publish\Core\Search\Common\FieldRegistry $fieldRegistry * @param \eZ\Publish\Core\Search\Common\FieldNameGenerator $fieldNameGenerator * @param \EzSystems\EzPlatformSolrSearchEngine\FieldMapper\BoostFactorProvider $boostFactorProvider + * @param $invalidCharactersPattern */ public function __construct( ContentTypeHandler $contentTypeHandler, FieldRegistry $fieldRegistry, FieldNameGenerator $fieldNameGenerator, - BoostFactorProvider $boostFactorProvider + BoostFactorProvider $boostFactorProvider, + $invalidCharactersPattern ) { $this->contentTypeHandler = $contentTypeHandler; $this->fieldRegistry = $fieldRegistry; $this->fieldNameGenerator = $fieldNameGenerator; $this->boostFactorProvider = $boostFactorProvider; + $this->invalidCharactersPattern = $invalidCharactersPattern; } public function accept(Content $content, $languageCode) @@ -104,7 +112,7 @@ public function mapFields(Content $content, $languageCode) $fields[] = new Field( self::$fieldName, - $indexField->value, + preg_replace($this->invalidCharactersPattern, '', $indexField->value), $this->getIndexFieldType($contentType) ); } diff --git a/lib/FieldMapper/ContentTranslationFieldMapper/ContentDocumentTranslatedContentNameField.php b/lib/FieldMapper/ContentTranslationFieldMapper/ContentDocumentTranslatedContentNameField.php index 2428afee0..d962d4b20 100644 --- a/lib/FieldMapper/ContentTranslationFieldMapper/ContentDocumentTranslatedContentNameField.php +++ b/lib/FieldMapper/ContentTranslationFieldMapper/ContentDocumentTranslatedContentNameField.php @@ -37,16 +37,24 @@ class ContentDocumentTranslatedContentNameField extends ContentTranslationFieldM */ protected $boostFactorProvider; + /** + * @var string + */ + private $invalidCharactersPattern; + /** * @param \eZ\Publish\SPI\Persistence\Content\Type\Handler $contentTypeHandler * @param \EzSystems\EzPlatformSolrSearchEngine\FieldMapper\BoostFactorProvider $boostFactorProvider + * @param $invalidCharactersPattern */ public function __construct( ContentTypeHandler $contentTypeHandler, - BoostFactorProvider $boostFactorProvider + BoostFactorProvider $boostFactorProvider, + $invalidCharactersPattern ) { $this->contentTypeHandler = $contentTypeHandler; $this->boostFactorProvider = $boostFactorProvider; + $this->invalidCharactersPattern = $invalidCharactersPattern; } public function accept(Content $content, $languageCode) @@ -60,7 +68,7 @@ public function mapFields(Content $content, $languageCode) return []; } - $contentName = $content->versionInfo->names[$languageCode]; + $contentName = preg_replace($this->invalidCharactersPattern, '', $content->versionInfo->names[$languageCode]); $contentType = $this->contentTypeHandler->load( $content->versionInfo->contentInfo->contentTypeId ); diff --git a/lib/Resources/config/container/solr/field_mappers.yml b/lib/Resources/config/container/solr/field_mappers.yml index 96ac5358f..3646f459c 100644 --- a/lib/Resources/config/container/solr/field_mappers.yml +++ b/lib/Resources/config/container/solr/field_mappers.yml @@ -16,6 +16,7 @@ services: - '@ezpublish.spi.persistence.content_type_handler' - '@ezpublish.spi.persistence.object_state_handler' - '@ezpublish.spi.persistence.section_handler' + - '%ez_search_engine_solr.invalid_characters_pattern%' tags: - {name: ezpublish.search.solr.field_mapper.block} @@ -26,6 +27,7 @@ services: - '@ezpublish.search.common.field_registry' - '@ezpublish.search.common.field_name_generator' - '@ezpublish.search.solr.field_mapper.boost_factor_provider' + - '%ez_search_engine_solr.invalid_characters_pattern%' tags: - {name: ezpublish.search.solr.field_mapper.block_translation} @@ -53,6 +55,7 @@ services: - '@ezpublish.search.common.field_registry' - '@ezpublish.search.common.field_name_generator' - '@ezpublish.search.solr.field_mapper.boost_factor_provider' + - '%ez_search_engine_solr.invalid_characters_pattern%' tags: - {name: ezpublish.search.solr.field_mapper.content_translation} @@ -61,6 +64,7 @@ services: arguments: - '@ezpublish.spi.persistence.content_type_handler' - '@ezpublish.search.solr.field_mapper.boost_factor_provider' + - '%ez_search_engine_solr.invalid_characters_pattern%' tags: - {name: ezpublish.search.solr.field_mapper.content_translation} From 1437bbc16bc693016de70d1cd41e2607700d886d Mon Sep 17 00:00:00 2001 From: Kamil Madejski Date: Fri, 25 Oct 2019 15:08:45 +0200 Subject: [PATCH 2/2] Moved parameter to the right file --- bundle/Resources/config/services.yml | 1 - lib/Resources/config/container/solr/services.yml | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/Resources/config/services.yml b/bundle/Resources/config/services.yml index ee99d4a94..a616c7921 100644 --- a/bundle/Resources/config/services.yml +++ b/bundle/Resources/config/services.yml @@ -2,7 +2,6 @@ parameters: ezpublish.solr.engine_factory.class: EzSystems\EzPlatformSolrSearchEngineBundle\ApiLoader\SolrEngineFactory ezpublish.solr.boost_factor_provider_factory.class: EzSystems\EzPlatformSolrSearchEngineBundle\ApiLoader\BoostFactorProviderFactory ez_search_engine_solr.default_connection: ~ - ez_search_engine_solr.invalid_characters_pattern: "#\\x1b[[][^A-Za-z]*[A-Za-z]#" services: ezpublish.solr.engine_factory: diff --git a/lib/Resources/config/container/solr/services.yml b/lib/Resources/config/container/solr/services.yml index c4cf6455a..e0da3a55c 100644 --- a/lib/Resources/config/container/solr/services.yml +++ b/lib/Resources/config/container/solr/services.yml @@ -10,6 +10,7 @@ parameters: ezpublish.search.solr.field_mapper.location.class: EzSystems\EzPlatformSolrSearchEngine\FieldMapper\LocationFieldMapper\Aggregate ezpublish.search.solr.field_mapper.boost_factor_provider.class: EzSystems\EzPlatformSolrSearchEngine\FieldMapper\BoostFactorProvider ezpublish.search.solr.field_mapper.boost_factor_provider.map: [] + ez_search_engine_solr.invalid_characters_pattern: "#\\x1b[[][^A-Za-z]*[A-Za-z]#" services: ezpublish.search.solr.gateway.client.http.stream: