MDL-15263 Fixed numeric entities remaining after html_to_text
authorsam_marshall <sam_marshall>
Mon, 16 Jun 2008 14:07:47 +0000 (14:07 +0000)
committersam_marshall <sam_marshall>
Mon, 16 Jun 2008 14:07:47 +0000 (14:07 +0000)
lib/simpletest/testweblib.php
lib/weblib.php

index 68e6d6b22f9913fe0bd3061182c58ef56611575e..aa704daaefbba7bc710d34d406005214ff52666f 100644 (file)
@@ -40,5 +40,19 @@ class web_test extends UnitTestCase {
     function test_s() {
           $this->assertEqual(s("This Breaks \" Strict"), "This Breaks &quot; Strict"); 
     }
+    
+    function test_format_text_email() {
+        $this->assertEqual('This is a test',
+            format_text_email('<p>This is a <strong>test</strong></p>',FORMAT_HTML));
+        $this->assertEqual('This is a test',
+            format_text_email('<p class="frogs">This is a <strong class=\'fishes\'>test</strong></p>',FORMAT_HTML));
+        $this->assertEqual('& so is this',
+            format_text_email('<p>&amp; so is this</p>',FORMAT_HTML));
+        $tl = textlib_get_instance();
+        $this->assertEqual('Two bullets: '.$tl->code2utf8(8226).' '.$tl->code2utf8(8226),
+            format_text_email('<p>Two bullets: &#x2022; &#8226;</p>',FORMAT_HTML));
+        $this->assertEqual($tl->code2utf8(0x7fd2).$tl->code2utf8(0x7fd2),
+            format_text_email('<p>&#x7fd2;&#x7FD2;</p>',FORMAT_HTML));
+    }
 }
 ?>
index 5ae014b8559907fab3160d6b2f1b1c0e26f1bee3..16d987d24f4a3cd0fd855bb25228e8a1d39a0ede 100644 (file)
@@ -2128,7 +2128,13 @@ function html_to_text($html) {
 
     require_once($CFG->libdir .'/html2text.php');
 
-    return html2text($html);
+    $result = html2text($html);
+    
+    // html2text does not fix numerical entities so handle those here.
+    $tl=textlib_get_instance();
+    $result = $tl->entities_to_utf8($result,false);
+    
+    return $result;
 }
 
 /**