From: Arnaud Le Blanc Date: Sun, 10 Aug 2008 13:25:53 +0000 (+0000) Subject: Fixed bug #45581 (htmlspecialchars() double encoding &#x hex items) X-Git-Tag: BEFORE_HEAD_NS_CHANGE~795 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eebec53bc09e5e249942353b166e87d8fcb8fb0f;p=php Fixed bug #45581 (htmlspecialchars() double encoding &#x hex items) --- diff --git a/ext/standard/html.c b/ext/standard/html.c index 62c4646090..abc8347499 100644 --- a/ext/standard/html.c +++ b/ext/standard/html.c @@ -1197,9 +1197,20 @@ encode_amp: } else { if (*s == '#') { /* numeric entities */ s++; - while (s < e) { - if (!isdigit(*s++)) { - goto encode_amp; + /* Hex (Z) */ + if (*s == 'x' || *s == 'X') { + s++; + while (s < e) { + if (!isxdigit(*s++)) { + goto encode_amp; + } + } + /* Dec (Z)*/ + } else { + while (s < e) { + if (!isdigit(*s++)) { + goto encode_amp; + } } } } else { /* text entities */ diff --git a/ext/standard/tests/strings/htmlentities18.phpt b/ext/standard/tests/strings/htmlentities18.phpt index 381cc838ed..d0492a8704 100644 --- a/ext/standard/tests/strings/htmlentities18.phpt +++ b/ext/standard/tests/strings/htmlentities18.phpt @@ -6,7 +6,8 @@ $tests = array( "abc", "abc&sfdsa", "test+s & some more D", - "&; & &#a; &9;", + "test+s & some more D", + "&; & &#a; &9; &#xyz;", "&kffjadfdhsjfhjasdhffasdfas;", "�", "&", @@ -26,8 +27,10 @@ unicode(13) "abc&sfdsa" unicode(13) "abc&sfdsa" unicode(33) "test+s & some more D" unicode(33) "test+s & some more D" -unicode(24) "&; &amp &#a; &9;" -unicode(24) "&; &amp &#a; &9;" +unicode(34) "test+s & some more D" +unicode(34) "test+s & some more D" +unicode(35) "&; &amp &#a; &9; &#xyz;" +unicode(35) "&; &amp &#a; &9; &#xyz;" unicode(32) "&kffjadfdhsjfhjasdhffasdfas;" unicode(32) "&kffjadfdhsjfhjasdhffasdfas;" unicode(16) "&#8787978789"