From ef5e1151c18bca3aea5a15e2013333dea166bf00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20S=CC=8Ckoda?= Date: Fri, 4 Oct 2013 10:59:41 +0200 Subject: [PATCH] MDL-41197 ignore all problems when converting texts --- lib/classes/text.php | 11 ++++++++--- lib/tests/text_test.php | 4 ++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/classes/text.php b/lib/classes/text.php index 9ce3ea4e8c9..1f79ae1ecb0 100644 --- a/lib/classes/text.php +++ b/lib/classes/text.php @@ -178,11 +178,16 @@ class core_text { 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 diff --git a/lib/tests/text_test.php b/lib/tests/text_test.php index fb33750405b..1ac11ca16d2 100644 --- a/lib/tests/text_test.php +++ b/lib/tests/text_test.php @@ -88,6 +88,10 @@ class core_text_testcase extends advanced_testcase { $this->assertSame($str, core_text::convert($utf8, 'utf-8', 'GB18030')); $this->assertSame($utf8, core_text::convert($str, 'GB18030', 'utf-8')); $this->assertSame($utf8, core_text::convert($utf8, 'utf-8', 'utf-8')); + + $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')); } /**