From 977b3d31456fef4e95d9fe20261747ecbd9e0449 Mon Sep 17 00:00:00 2001 From: sam_marshall Date: Mon, 16 Jun 2008 14:07:47 +0000 Subject: [PATCH] MDL-15263 Fixed numeric entities remaining after html_to_text --- lib/simpletest/testweblib.php | 14 ++++++++++++++ lib/weblib.php | 8 +++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/simpletest/testweblib.php b/lib/simpletest/testweblib.php index 68e6d6b22f..aa704daaef 100644 --- a/lib/simpletest/testweblib.php +++ b/lib/simpletest/testweblib.php @@ -40,5 +40,19 @@ class web_test extends UnitTestCase { function test_s() { $this->assertEqual(s("This Breaks \" Strict"), "This Breaks " Strict"); } + + function test_format_text_email() { + $this->assertEqual('This is a test', + format_text_email('

This is a test

',FORMAT_HTML)); + $this->assertEqual('This is a test', + format_text_email('

This is a test

',FORMAT_HTML)); + $this->assertEqual('& so is this', + format_text_email('

& so is this

',FORMAT_HTML)); + $tl = textlib_get_instance(); + $this->assertEqual('Two bullets: '.$tl->code2utf8(8226).' '.$tl->code2utf8(8226), + format_text_email('

Two bullets: • •

',FORMAT_HTML)); + $this->assertEqual($tl->code2utf8(0x7fd2).$tl->code2utf8(0x7fd2), + format_text_email('

習習

',FORMAT_HTML)); + } } ?> diff --git a/lib/weblib.php b/lib/weblib.php index 5ae014b855..16d987d24f 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -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; } /** -- 2.39.5