You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
htmlspecialchars_decode() ENT_SUBSTITUTE flag has no effect #9582
The htmlspecialchars() function has an ENT_SUBSTITUTE flag (enabled by default since PHP 8.1) that changes its behavior when encountering invalid code unit sequences:
(Appearance on your terminal may vary; it actually just returns the incomplete code unit sequence. On my system, in php -a it looks empty, while PsySH renders it as Ã.)
According to 3v4l, this behavior has been the same since htmlspecialchars_decode() was introduced (from 5.1.0 all the way to 8.2rc2), so perhaps instead of changing the behavior, this should just be considered a documentation bug (remove the flag from the documentation)?
There is no encoding parameter in htmlspecialchars_decode and therefore ENT_SUBSTITUTE cannot be applied.
If you don't know your input string you will have to validate with htmlspecialchars and after htmlspecialchars_decode
Activity
lucaswerkmeister commentedon Sep 20, 2022
(The code example assumes UTF-8.
substr( 'abcdeä', 0, 6 )might not produce an incomplete code unit sequence under other encodings.)hormus commentedon Sep 24, 2022
There is no encoding parameter in htmlspecialchars_decode and therefore ENT_SUBSTITUTE cannot be applied.
If you don't know your input string you will have to validate with htmlspecialchars and after htmlspecialchars_decode
Example 2:
Expected result: