Skip to content

Commit

Permalink
Merge pull request #2675 from mficzel/bugfix/augmenterHandlesUnicodeC…
Browse files Browse the repository at this point in the history
…haractersCorrectly

BUGFIX: HTML augmenter preserves multibyte characters in attributes
  • Loading branch information
kdambekalns committed Sep 3, 2019
2 parents 57977a2 + fa57e7e commit b06c25a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Classes/Service/HtmlAugmenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected function getHtmlRootElement($html)
$domDocument = new \DOMDocument('1.0', 'UTF-8');
// ignore parsing errors
$useInternalErrorsBackup = libxml_use_internal_errors(true);
$domDocument->loadHTML($html);
$domDocument->loadHTML((substr($html, 0, 5) === '<?xml') ? $html : '<?xml encoding="UTF-8"?>' . $html);
$xPath = new \DOMXPath($domDocument);
$rootElement = $xPath->query('//html/body/*');
if ($useInternalErrorsBackup !== true) {
Expand Down
7 changes: 7 additions & 0 deletions Tests/Unit/Service/HtmlAugmenterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ public function __toString() {
'exclusiveAttributes' => null,
'expectedResult' => '<p data-bar="öäüß" data-foo="öäüß">valid characters are decoded</p>',
),
[
'html' => '<p data-foo="öäüß🦆">valid characters are untouched</p>',
'attributes' => ['data-bar' => 'öäüß🦆'],
'fallbackTagName' => null,
'exclusiveAttributes' => null,
'expectedResult' => '<p data-bar="öäüß🦆" data-foo="öäüß🦆">valid characters are untouched</p>',
],

// exclusive attributes
array(
Expand Down

0 comments on commit b06c25a

Please sign in to comment.