Skip to content

Commit

Permalink
Generators HTML/Markdown: consistent encoding cross-PHP
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jrfnl committed Nov 23, 2024
1 parent 3f33a50 commit 9a45fbb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Generators/HTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public function processSniff(DOMNode $doc)
protected function printTextBlock(DOMNode $node)
{
$content = trim($node->nodeValue);
$content = htmlspecialchars($content);
$content = htmlspecialchars($content, (ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401));

// Use the correct line endings based on the OS.
$content = str_replace("\n", PHP_EOL, $content);
Expand Down
2 changes: 1 addition & 1 deletion src/Generators/Markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected function processSniff(DOMNode $doc)
protected function printTextBlock(DOMNode $node)
{
$content = trim($node->nodeValue);
$content = htmlspecialchars($content);
$content = htmlspecialchars($content, (ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401));

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

0 comments on commit 9a45fbb

Please sign in to comment.