MDL-41197 normalize ascii text conversion
authorPetr Škoda <commits@skodak.org>
Mon, 7 Oct 2013 19:57:07 +0000 (21:57 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 7 Oct 2013 21:54:05 +0000 (23:54 +0200)
lib/classes/text.php
lib/tests/text_test.php

index 1f79ae1..7b13d75 100644 (file)
@@ -185,6 +185,11 @@ class core_text {
             }
         }
 
+        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);
index 1ac11ca..9e6aca8 100644 (file)
@@ -90,8 +90,12 @@ class core_text_testcase extends advanced_testcase {
         $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('Zlutoucky konicek', core_text::convert($utf8, 'utf-8', 'ascii'));
         $this->assertSame($utf8, core_text::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', core_text::convert($utf8, 'utf-8', 'ascii'));
+        $iso1 = core_text::convert($utf8, 'utf-8', 'iso-8859-1');
+        $this->assertSame('Der eine stoesst den Speer zum Mann', core_text::convert($iso1, 'iso-8859-1', 'ascii'));
     }
 
     /**