Skip to content

Commit 65d57b1

Browse files
committed
Generators HTML/Markdown: consistent encoding cross-PHP
The default value for the `$flags` parameter of the `htmlspecialchars()` function changed in PHP 8.1.0. Previously, the default was `ENT_COMPAT`. Now the default is `ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401`. The most notable differences are: * Single quotes will be encoded. * Invalid code unit sequences will be replace by a Unicode Replacement Character. For consistent output cross-version PHP, it is advised to always explicitly pass the `$flags` parameter` and not rely on the default value. Fixed now and using the _new_ `$flags` default value as the parameter value. This commit allows for the tests to have the same output expectations cross-version PHP. For end-users, the differences shouldn't have been noticeable.
1 parent 3f33a50 commit 65d57b1

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/Generators/HTML.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public function processSniff(DOMNode $doc)
235235
protected function printTextBlock(DOMNode $node)
236236
{
237237
$content = trim($node->nodeValue);
238-
$content = htmlspecialchars($content);
238+
$content = htmlspecialchars($content, (ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401));
239239

240240
// Use the correct line endings based on the OS.
241241
$content = str_replace("\n", PHP_EOL, $content);

src/Generators/Markdown.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ protected function processSniff(DOMNode $doc)
116116
protected function printTextBlock(DOMNode $node)
117117
{
118118
$content = trim($node->nodeValue);
119-
$content = htmlspecialchars($content);
119+
$content = htmlspecialchars($content, (ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401));
120120

121121
// Use the correct line endings based on the OS.
122122
$content = str_replace("\n", PHP_EOL, $content);

0 commit comments

Comments
 (0)