]> granicus.if.org Git - php/commitdiff
MFH: Fixed bug #45581 (htmlspecialchars() double encoding &#x hex items)
authorArnaud Le Blanc <lbarnaud@php.net>
Sun, 10 Aug 2008 13:26:25 +0000 (13:26 +0000)
committerArnaud Le Blanc <lbarnaud@php.net>
Sun, 10 Aug 2008 13:26:25 +0000 (13:26 +0000)
NEWS
ext/standard/html.c
ext/standard/tests/strings/htmlentities18.phpt

diff --git a/NEWS b/NEWS
index 719e9d17684edb47c8ec792346da6128720a292e..95f33f2b6f07a5e40643585c4f779c26246e2afa 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,7 @@ PHP                                                                        NEWS
   (Jani)
 - Fixed bug #45691 (Some per-dir or runtime settings may leak into other
   requests). (Moriyoshi)
+- Fixed bug #45581 (htmlspecialchars() double encoding &#x hex items). (Arnaud)
 - Fixed bug #45568 (ISAPI doesn't properly clear auth_digest in header).
   (Patch by: navara at emclient dot com)
 - Fixed bug #45556 (Return value from callback isn't freed). (Felipe)
index b544184fb86b938e8a648a54ebf70b994c05b1c1..386a63fe2e19a303f50fef37cbd74330cfd335db 100644 (file)
@@ -1199,9 +1199,20 @@ encode_amp:
                                        } else {
                                                if (*s == '#') { /* numeric entities */
                                                        s++;
-                                                       while (s < e) {
-                                                               if (!isdigit(*s++)) {
-                                                                       goto encode_amp;
+                                                       /* Hex (&#x5A;) */
+                                                       if (*s == 'x' || *s == 'X') {
+                                                               s++;
+                                                               while (s < e) {
+                                                                       if (!isxdigit(*s++)) {
+                                                                               goto encode_amp;
+                                                                       }
+                                                               }
+                                                       /* Dec (&#90;)*/
+                                                       } else {
+                                                               while (s < e) {
+                                                                       if (!isdigit(*s++)) {
+                                                                               goto encode_amp;
+                                                                       }
                                                                }
                                                        }
                                                } else { /* text entities */
index ab3df05da87b80a246ef37674d797371b47d01bf..8970be8a083ab2939f43fe90f0d3b81132c967f5 100644 (file)
@@ -6,7 +6,8 @@ $tests = array(
        "abc",
        "abc&amp;sfdsa",
        "test&#043;s &amp; some more &#68;",
-       "&; &amp &#a; &9;",
+       "test&#x2b;s &amp; some more &#X44;",
+       "&; &amp &#a; &9; &#xyz;",
        "&kffjadfdhsjfhjasdhffasdfas;",
        "&#8787978789",
        "&",
@@ -26,8 +27,10 @@ string(13) "abc&amp;sfdsa"
 string(13) "abc&amp;sfdsa"
 string(33) "test&#043;s &amp; some more &#68;"
 string(33) "test&#043;s &amp; some more &#68;"
-string(24) "&; &amp;amp &amp;#a; &9;"
-string(24) "&; &amp;amp &amp;#a; &9;"
+string(34) "test&#x2b;s &amp; some more &#X44;"
+string(34) "test&#x2b;s &amp; some more &#X44;"
+string(35) "&; &amp;amp &amp;#a; &9; &amp;#xyz;"
+string(35) "&; &amp;amp &amp;#a; &9; &amp;#xyz;"
 string(32) "&amp;kffjadfdhsjfhjasdhffasdfas;"
 string(32) "&amp;kffjadfdhsjfhjasdhffasdfas;"
 string(16) "&amp;#8787978789"