Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-25018 stop html_to_text from breaking utf-8 multibyte characters.

  • Loading branch information...
commit 36a40748e18b369e71c69960b329d531cd53663d 1 parent 52f2924
@timhunt timhunt authored
View
6 lib/html2text.php
@@ -589,10 +589,8 @@ function _preg_callback($matches)
*/
function _strtoupper($str)
{
- if (function_exists('mb_strtoupper'))
- return mb_strtoupper($str);
- else
- return strtoupper($str);
+ $tl = textlib_get_instance();
+ return $tl->strtoupper($str);
}
}
View
23 lib/html2text_readme.txt
@@ -60,4 +60,25 @@ index b7e3e3e..96ef508 100644
}
}
- -- Tim Hunt 2010-08-04
+-- Tim Hunt 2010-08-04
+
+
+3- Use textlib, not crappy functions that break UTF-8, in the _strtoupper method.
+
+Index: lib/html2text.php
+--- lib/html2text.php 2 Sep 2010 12:49:29 -0000 1.16
++++ lib/html2text.php 2 Nov 2010 19:57:09 -0000
+@@ -580,9 +580,7 @@
+ */
+ function _strtoupper($str)
+ {
+- if (function_exists('mb_strtoupper'))
+- return mb_strtoupper($str);
+- else
+- return strtoupper($str);
++ $tl = textlib_get_instance();
++ return $tl->strtoupper($str);
+ }
+ }
+
+-- Tim Hunt 2010-11-02
View
10 lib/simpletest/testweblib.php
@@ -165,10 +165,10 @@ function test_convert_urls_into_links() {
//no link at all
'This is a story about moodle.coming to a cinema near you.'=>'This is a story about moodle.coming to a cinema near you.',
//URLs containing utf 8 characters
- 'http://Iñtërnâtiônàlizætiøn.com?ô=nëø'=>'<a href="http://Iñtërnâtiônàlizætiøn.com?ô=nëø" target="_blank">http://Iñtërnâtiônàlizætiøn.com?ô=nëø</a>',
- 'www.Iñtërnâtiônàlizætiøn.com?ô=nëø'=>'<a href="http://www.Iñtërnâtiônàlizætiøn.com?ô=nëø" target="_blank">www.Iñtërnâtiônàlizætiøn.com?ô=nëø</a>',
+ 'http://I�t�rn�ti�n�liz�ti�n.com?�=n��'=>'<a href="http://I�t�rn�ti�n�liz�ti�n.com?�=n��" target="_blank">http://I�t�rn�ti�n�liz�ti�n.com?�=n��</a>',
+ 'www.I�t�rn�ti�n�liz�ti�n.com?�=n��'=>'<a href="http://www.I�t�rn�ti�n�liz�ti�n.com?�=n��" target="_blank">www.I�t�rn�ti�n�liz�ti�n.com?�=n��</a>',
//text containing utf 8 characters outside of a url
- 'Iñtërnâtiônàlizætiøn is important to http://moodle.org'=>'Iñtërnâtiônàlizætiøn is important to <a href="http://moodle.org" target="_blank">http://moodle.org</a>',
+ 'I�t�rn�ti�n�liz�ti�n is important to http://moodle.org'=>'I�t�rn�ti�n�liz�ti�n is important to <a href="http://moodle.org" target="_blank">http://moodle.org</a>',
//too hard to identify without additional regexs
'moodle.org' => 'moodle.org',
//some text with no link between related html tags
@@ -251,5 +251,9 @@ public function test_html_to_text_nowrap() {
$long = "Here is a long string, more than 75 characters long, since by default html_to_text wraps text at 75 chars.";
$this->assertEqual($long, html_to_text($long, 0));
}
+
+ public function test_html_to_text_dont_screw_up_utf8() {
+ $this->assertEqual("\n\nAll the WORLD’S a stage.", html_to_text('<p>All the <strong>world’s</strong> a stage.</p>'));
+ }
}
?>
Please sign in to comment.
Something went wrong with that request. Please try again.