|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-04-02 20:18 UTC] rowan dot collins at gmail dot com
[2021-04-02 21:03 UTC] ASchmidt at Anamera dot net
-Summary: htmlspecialchars double-encodes "
+Summary: htmlspecialchars double-encodes '
[2021-04-02 21:03 UTC] ASchmidt at Anamera dot net
[2021-04-06 08:32 UTC] cmb@php.net
[2021-04-06 12:41 UTC] ASchmidt at Anamera dot net
-Summary: htmlspecialchars double-encodes '
+Summary: htmlspecialchars double-encodes vs. ' and €
[2021-04-06 12:41 UTC] ASchmidt at Anamera dot net
[2021-12-02 10:12 UTC] cmb@php.net
-Operating System: Windows
+Operating System: *
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 23:00:01 2025 UTC |
Description: ------------ According to manual "when double_encode is turned off PHP will not encode existing html entities". No pre-condition is stated. However, " is double-encoded, UNLESS flag ENT_HTML5 is set. Setting either ENT_COMPAT or ENT_NOQUOTES or ENT_QUOTES does NOT alter the outcome, nor is any other entity subject to this bug; it appears to be a unique combination of " and the lack of ENT_HTML5. Test script: --------------- declare(strict_types=1); $text = 'ampersand(&), double quote("), single quote('), less than(<), greater than(>), numeric entities(&"'<>)'; $result1 = htmlspecialchars( $text, ENT_COMPAT | ENT_SUBSTITUTE, 'UTF-8', false ); $result2 = htmlspecialchars( $text, ENT_NOQUOTES | ENT_SUBSTITUTE, 'UTF-8', false ); $result3 = htmlspecialchars( $text, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8', false ); $result4 = htmlspecialchars( $text, ENT_QUOTES | ENT_HTML5 | ENT_SUBSTITUTE, 'UTF-8', false ); echo "<br />\r\n", $result1, "<br />\r\n", $result2, "<br />\r\n", $result3, "<br />\r\n", $result4, "<br />\r\n"; Expected result: ---------------- Four identical rows of: ampersand(&), double quote("), single quote("), less than(<), greater than(>), numeric entities(&"'<>) Actual result: -------------- ampersand(&), double quote("), single quote('), less than(<), greater than(>), numeric entities(&"'<>) ampersand(&), double quote("), single quote('), less than(<), greater than(>), numeric entities(&"'<>) ampersand(&), double quote("), single quote('), less than(<), greater than(>), numeric entities(&"'<>) ampersand(&), double quote("), single quote('), less than(<), greater than(>), numeric entities(&"'<>) Only the LAST line (with ENT_HTML5 set) does NOT double-encode.