[BUGFIX] Compatibility fix for get_html_translation_table()
authorMichael Stucki <michael.stucki@typo3.org>
Tue, 27 Nov 2012 00:12:31 +0000 (01:12 +0100)
committerDmitry Dulepov <dmitry@typo3.org>
Tue, 4 Dec 2012 11:38:22 +0000 (12:38 +0100)
t3lib_cs::entities_to_utf8() triggers a PHP warning on versions
lower than 5.3.4 because too many parameters were given.
See http://php.net/manual/en/function.get-html-translation-table.php

Change-Id: Ic302f2b8c2902ec8685dfb2d974273071bbbdcb7
Fixes: #39287
Releases: 6.0, 4.7
Reviewed-on: http://review.typo3.org/13504
Reviewed-by: Ernesto Baschny
Tested-by: Ernesto Baschny
Reviewed-by: Dmitry Dulepov
Tested-by: Dmitry Dulepov
typo3/sysext/core/Classes/Charset/CharsetConverter.php

index a260b9f..5d9ab45 100644 (file)
@@ -937,8 +937,16 @@ class CharsetConverter {
         * @todo Define visibility
         */
        public function entities_to_utf8($str, $alsoStdHtmlEnt = FALSE) {
+               // Workaround for #39287: 3rd parameter for get_html_translation_table() was only added in PHP 5.3.4 and later
+               // see http://php.net/manual/en/function.get-html-translation-table.php
+               $applyPhpCompatibilityFix = version_compare(phpversion(), '5.3.4', '<');
+
                if ($alsoStdHtmlEnt) {
-                       $trans_tbl = array_flip(get_html_translation_table(HTML_ENTITIES, ENT_COMPAT, 'UTF-8'));
+                       if ($applyPhpCompatibilityFix === TRUE) {
+                               $trans_tbl = array_flip(get_html_translation_table(HTML_ENTITIES, ENT_COMPAT));
+                       } else {
+                               $trans_tbl = array_flip(get_html_translation_table(HTML_ENTITIES, ENT_COMPAT, 'UTF-8'));
+                       }
                }
                $token = md5(microtime());
                $parts = explode($token, preg_replace('/(&([#[:alnum:]]*);)/', $token . '${2}' . $token, $str));
@@ -959,7 +967,11 @@ class CharsetConverter {
                                $parts[$k] = $this->UnumberToChar($v);
                        } elseif ($alsoStdHtmlEnt && isset($trans_tbl['&' . $v . ';'])) {
                                // Other entities:
-                               $parts[$k] = $trans_tbl['&' . $v . ';'];
+                               $v = $trans_tbl['&' . $v . ';'];
+                               if ($applyPhpCompatibilityFix === TRUE) {
+                                       $v = $this->utf8_encode($v, 'iso-8859-1');
+                               }
+                               $parts[$k] = $v;
                        } else {
                                // No conversion:
                                $parts[$k] = '&' . $v . ';';