diff --git a/lib/tests/textlib_test.php b/lib/tests/textlib_test.php index 6ffcf06ff9e..d9daf1a714b 100644 --- a/lib/tests/textlib_test.php +++ b/lib/tests/textlib_test.php @@ -91,6 +91,10 @@ class core_textlib_testcase extends advanced_testcase { $this->assertSame(textlib::convert($utf8, 'utf-8', 'GB18030'), $str); $this->assertSame(textlib::convert($str, 'GB18030', 'utf-8'), $utf8); $this->assertSame(textlib::convert($utf8, 'utf-8', 'utf-8'), $utf8); + + $utf8 = "Žluťoučký koníček"; + $this->assertSame('Zlutouck\'y kon\'icek', core_text::convert($utf8, 'utf-8', 'ascii')); + $this->assertSame($utf8, core_text::convert($utf8.chr(130), 'utf-8', 'utf-8')); } /** diff --git a/lib/textlib.class.php b/lib/textlib.class.php index 37351e0ca0e..4fe83afb500 100644 --- a/lib/textlib.class.php +++ b/lib/textlib.class.php @@ -178,11 +178,16 @@ class textlib { return ''; } - if ($toCS === 'utf-8' and $fromCS === 'utf-8') { - return fix_utf8($text); + if ($fromCS === 'utf-8') { + $text = fix_utf8($text); + if ($toCS === 'utf-8') { + return $text; + } } - $result = iconv($fromCS, $toCS.'//TRANSLIT', $text); + // Prevent any error notices, do not use //IGNORE so that we get + // consistent result from Typo3 if iconv fails. + $result = @iconv($fromCS, $toCS.'//TRANSLIT', $text); if ($result === false or $result === '') { // note: iconv is prone to return empty string when invalid char encountered, or false if encoding unsupported