Skip to content

Commit

Permalink
pkp/pkp-lib#7916 revert back symfony html sanitizer and bring back ht…
Browse files Browse the repository at this point in the history
…ml purifier
  • Loading branch information
touhidurabir authored and asmecher committed Jul 16, 2024
1 parent 64175a3 commit c7099bc
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions classes/ArticleBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
use PKP\config\Config;
use PKP\core\PKPString;
use PKP\search\SearchFileParser;
use Symfony\Component\HtmlSanitizer\HtmlSanitizer;
use Symfony\Component\HtmlSanitizer\HtmlSanitizerConfig;

class ArticleBody extends \DOMDocument
{
Expand Down Expand Up @@ -49,12 +47,15 @@ public function create(Submission $submission):\DOMNode
$filepath = $fileService->get($galleyFile->getData('fileId'))->path;
$mimeType = $fileService->fs->mimeType($filepath);
if (in_array($mimeType, ['text/html'])) {
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);
}
// Remove non-paragraph content
$text = $sanitizer->sanitize(file_get_contents(Config::getVar('files', 'files_dir') . '/' . $filepath));
$text = $purifier->purify(file_get_contents(Config::getVar('files', 'files_dir') . '/' . $filepath));

// Remove empty paragraphs
} else {
Expand Down

0 comments on commit c7099bc

Please sign in to comment.