]> granicus.if.org Git - php/commitdiff
Fix bug #64011 (get_html_translation_table())
authorGustavo Lopes <glopes@nebm.ist.utl.pt>
Fri, 18 Jan 2013 11:07:21 +0000 (12:07 +0100)
committerGustavo Lopes <glopes@nebm.ist.utl.pt>
Fri, 18 Jan 2013 11:10:27 +0000 (12:10 +0100)
get_html_translation_table() with encoding ISO-8859-1 and HTMLENTITIES
was broken. Only entities for characters U+0000 to U+0040 were being
included in the result.

ext/standard/html.c
ext/standard/tests/strings/get_html_translation_table_basic10.phpt [new file with mode: 0644]

index 79a6737ca500d403c588fee29fbc6a1dafc11dfb..414fa65c91d3b7a40c9f7db7422e1ca05acb0033 100644 (file)
@@ -1628,8 +1628,8 @@ PHP_FUNCTION(get_html_translation_table)
                        unsigned i, j, k,
                                         max_i, max_j, max_k;
                        /* no mapping to unicode required */
-                       if (CHARSET_SINGLE_BYTE(charset)) {
-                               max_i = 1; max_j = 1; max_k = 64;
+                       if (CHARSET_SINGLE_BYTE(charset)) { /* ISO-8859-1 */
+                               max_i = 1; max_j = 4; max_k = 64;
                        } else {
                                max_i = 0x1E; max_j = 64; max_k = 64;
                        }
diff --git a/ext/standard/tests/strings/get_html_translation_table_basic10.phpt b/ext/standard/tests/strings/get_html_translation_table_basic10.phpt
new file mode 100644 (file)
index 0000000..a5a3568
--- /dev/null
@@ -0,0 +1,121 @@
+--TEST--
+Test get_html_translation_table() function: htmlentities/HTML 4/ISO-8859-1 (bug #64011)
+--FILE--
+<?php
+
+function so($a,$b) { return ord($a) - ord($b); }
+
+$table = HTML_ENTITIES;
+$tt = get_html_translation_table($table, ENT_COMPAT, "ISO-8859-1");
+uksort( $tt, 'so' );
+var_dump( count($tt) );
+print_r( $tt );
+echo "Done\n";
+
+?>
+--EXPECT--
+int(100)
+Array
+(
+    ["] => &quot;
+    [&] => &amp;
+    [<] => &lt;
+    [>] => &gt;
+    [ ] => &nbsp;
+    [¡] => &iexcl;
+    [¢] => &cent;
+    [£] => &pound;
+    [¤] => &curren;
+    [¥] => &yen;
+    [¦] => &brvbar;
+    [§] => &sect;
+    [¨] => &uml;
+    [©] => &copy;
+    [ª] => &ordf;
+    [«] => &laquo;
+    [¬] => &not;
+    [­] => &shy;
+    [®] => &reg;
+    [¯] => &macr;
+    [°] => &deg;
+    [±] => &plusmn;
+    [²] => &sup2;
+    [³] => &sup3;
+    [´] => &acute;
+    [µ] => &micro;
+    [¶] => &para;
+    [·] => &middot;
+    [¸] => &cedil;
+    [¹] => &sup1;
+    [º] => &ordm;
+    [»] => &raquo;
+    [¼] => &frac14;
+    [½] => &frac12;
+    [¾] => &frac34;
+    [¿] => &iquest;
+    [À] => &Agrave;
+    [Á] => &Aacute;
+    [Â] => &Acirc;
+    [Ã] => &Atilde;
+    [Ä] => &Auml;
+    [Å] => &Aring;
+    [Æ] => &AElig;
+    [Ç] => &Ccedil;
+    [È] => &Egrave;
+    [É] => &Eacute;
+    [Ê] => &Ecirc;
+    [Ë] => &Euml;
+    [Ì] => &Igrave;
+    [Í] => &Iacute;
+    [Î] => &Icirc;
+    [Ï] => &Iuml;
+    [Ð] => &ETH;
+    [Ñ] => &Ntilde;
+    [Ò] => &Ograve;
+    [Ó] => &Oacute;
+    [Ô] => &Ocirc;
+    [Õ] => &Otilde;
+    [Ö] => &Ouml;
+    [×] => &times;
+    [Ø] => &Oslash;
+    [Ù] => &Ugrave;
+    [Ú] => &Uacute;
+    [Û] => &Ucirc;
+    [Ü] => &Uuml;
+    [Ý] => &Yacute;
+    [Þ] => &THORN;
+    [ß] => &szlig;
+    [à] => &agrave;
+    [á] => &aacute;
+    [â] => &acirc;
+    [ã] => &atilde;
+    [ä] => &auml;
+    [å] => &aring;
+    [æ] => &aelig;
+    [ç] => &ccedil;
+    [è] => &egrave;
+    [é] => &eacute;
+    [ê] => &ecirc;
+    [ë] => &euml;
+    [ì] => &igrave;
+    [í] => &iacute;
+    [î] => &icirc;
+    [ï] => &iuml;
+    [ð] => &eth;
+    [ñ] => &ntilde;
+    [ò] => &ograve;
+    [ó] => &oacute;
+    [ô] => &ocirc;
+    [õ] => &otilde;
+    [ö] => &ouml;
+    [÷] => &divide;
+    [ø] => &oslash;
+    [ù] => &ugrave;
+    [ú] => &uacute;
+    [û] => &ucirc;
+    [ü] => &uuml;
+    [ý] => &yacute;
+    [þ] => &thorn;
+    [ÿ] => &yuml;
+)
+Done