From 896a790f69cef10fac4f8e08a84dfa3d72f0f777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20S=CC=8Ckoda?= Date: Mon, 7 Oct 2013 22:03:00 +0200 Subject: [PATCH] MDL-41197 normalize ascii text conversion --- lib/tests/textlib_test.php | 8 ++++++-- lib/textlib.class.php | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/tests/textlib_test.php b/lib/tests/textlib_test.php index e1b79f9317a..be0b867e817 100644 --- a/lib/tests/textlib_test.php +++ b/lib/tests/textlib_test.php @@ -93,8 +93,12 @@ class core_textlib_testcase extends advanced_testcase { $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')); + $this->assertSame('Zlutoucky konicek', textlib::convert($utf8, 'utf-8', 'ascii')); + $this->assertSame($utf8, textlib::convert($utf8.chr(130), 'utf-8', 'utf-8')); + $utf8 = "Der eine stößt den Speer zum Mann"; + $this->assertSame('Der eine stoesst den Speer zum Mann', textlib::convert($utf8, 'utf-8', 'ascii')); + $iso1 = textlib::convert($utf8, 'utf-8', 'iso-8859-1'); + $this->assertSame('Der eine stoesst den Speer zum Mann', textlib::convert($iso1, 'iso-8859-1', 'ascii')); } /** diff --git a/lib/textlib.class.php b/lib/textlib.class.php index 0801cf7b035..522a8313477 100644 --- a/lib/textlib.class.php +++ b/lib/textlib.class.php @@ -185,6 +185,11 @@ class textlib { } } + if ($toCS === 'ascii') { + // Try to normalize the conversion a bit. + $text = self::specialtoascii($text, $fromCS); + } + // 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);