From 29744739dff692a22273e54c4eda3447d65bc095 Mon Sep 17 00:00:00 2001 From: Touhidur Rahman Date: Wed, 17 Jul 2024 00:18:47 +0600 Subject: [PATCH] pkp/pkp-lib#7916 revert back symfony html sanitizer and bring back html purifier (#46) --- OAIMetadataFormat_JATS.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/OAIMetadataFormat_JATS.php b/OAIMetadataFormat_JATS.php index f6b8591..d5194d1 100644 --- a/OAIMetadataFormat_JATS.php +++ b/OAIMetadataFormat_JATS.php @@ -25,8 +25,6 @@ use APP\core\Services; use PKP\core\PKPString; use PKP\plugins\Hook; -use Symfony\Component\HtmlSanitizer\HtmlSanitizer; -use Symfony\Component\HtmlSanitizer\HtmlSanitizerConfig; class OAIMetadataFormat_JATS extends OAIMetadataFormat { /** @@ -325,17 +323,21 @@ protected function _mungeMetadata($doc, $journal, $article, $section, $issue) { } // Set the article abstract. - static $sanitizer = null; - if (!$sanitizer) { - $sanitizer = new \PKP\core\PKPHtmlSanitizer('p'); + static $purifier; + if (!$purifier) { + $config = \HTMLPurifier_Config::createDefault(); + $config->set('HTML.Allowed', 'p'); + $config->set('Cache.SerializerPath', 'cache'); + $purifier = new \HTMLPurifier($config); } + foreach ($articleMetaNode->getElementsByTagName('abstract') as $abstractNode) $articleMetaNode->removeChild($abstractNode); foreach ((array) $publication->getData('abstract') as $locale => $abstract) { if (empty($abstract)) continue; $isPrimary = $locale == $article->getLocale(); $abstractDoc = new \DOMDocument; if (strpos($abstract, '

')===null) $abstract = "

$abstract

"; - $abstractDoc->loadXML(($isPrimary?'':'') . $sanitizer->sanitize($abstract) . ($isPrimary?'':'')); + $abstractDoc->loadXML(($isPrimary?'':'') . $purifier->purify($abstract) . ($isPrimary?'':'')); $abstractNode = $this->_addChildInOrder($articleMetaNode, $doc->importNode($abstractDoc->documentElement, true)); if (!$isPrimary) $abstractNode->setAttribute('xml:lang', substr($locale,0,2)); }