diff --git a/composer.json b/composer.json index a338c5c..d824d01 100644 --- a/composer.json +++ b/composer.json @@ -25,5 +25,13 @@ } }, "minimum-stability": "dev", - "prefer-stable": true + "prefer-stable": true, + "config": { + "allow-plugins": { + "composer/installers": true, + "silverstripe/vendor-plugin": true, + "silverstripe/recipe-plugin": true, + "dealerdirect/phpcodesniffer-composer-installer": true + } + } } diff --git a/src/Jobs/OaiRecordUpdateJob.php b/src/Jobs/OaiRecordUpdateJob.php index 060b4a2..cc71c50 100644 --- a/src/Jobs/OaiRecordUpdateJob.php +++ b/src/Jobs/OaiRecordUpdateJob.php @@ -96,7 +96,7 @@ protected function updateOaiRecord(DataObject $dataObject): void $errors[] = sprintf('Unsupported OAI field provided: %s', $oaiField); } - $oaiRecord->{$oaiField} = $dataObject->relField($dataObjectField); + $oaiRecord->{$oaiField} = $this->sanitiseContent($dataObject->relField($dataObjectField)); } if ($errors) { @@ -160,4 +160,18 @@ protected function getOaiRecord(): ?OaiRecord return $oaiRecord; } + /** + * @param mixed $content + * @return mixed + */ + protected function sanitiseContent($content) + { + if (!is_string($content)) { + return $content; + } + + // Attempt to remove any illegal characters + return preg_replace('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', ' ', $content); + } + }