diff --git a/phpmyfaq/src/phpMyFAQ/Helper/FaqHelper.php b/phpmyfaq/src/phpMyFAQ/Helper/FaqHelper.php index c482b1a712..8d9a8c581b 100644 --- a/phpmyfaq/src/phpMyFAQ/Helper/FaqHelper.php +++ b/phpmyfaq/src/phpMyFAQ/Helper/FaqHelper.php @@ -18,6 +18,7 @@ namespace phpMyFAQ\Helper; use DOMDocument; +use DOMXPath; use Exception; use ParsedownExtra; use phpMyFAQ\Category; @@ -245,6 +246,14 @@ public function cleanUpContent(string $content): string $scriptTags->item($i)->parentNode->removeChild($scriptTags->item($i)); } - return preg_replace(['/\r/', '/\n/'], '', $document->saveHTML()); + $xpath = new DOMXPath($document); + $onAttributes = $xpath->query("//*/@*[starts-with(name(), 'on')]"); + foreach ($onAttributes as $onAttribute) { + $onAttribute->ownerElement->removeAttributeNode($onAttribute); + } + + $body = $xpath->query('body')->item(0); + + return preg_replace(['/\r/', '/\n/'], '', $document->saveHTML($body)); } } diff --git a/tests/phpMyFAQ/Helper/FaqHelperTest.php b/tests/phpMyFAQ/Helper/FaqHelperTest.php index ead622c621..1de4335720 100644 --- a/tests/phpMyFAQ/Helper/FaqHelperTest.php +++ b/tests/phpMyFAQ/Helper/FaqHelperTest.php @@ -62,8 +62,8 @@ public function testCreateFaqUrl(): void public function testCleanUpContent(): void { - $content = '

Some text

'; - $expectedOutput = '

Some text

'; + $content = '

Some text

'; + $expectedOutput = '

Some text

'; $actualOutput = $this->faqHelper->cleanUpContent($content);