From 71712c94245ebaedd2d05af648ff5fb977268184 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Wed, 21 Sep 2011 14:37:50 +0100 Subject: [PATCH] MDL-29462 html_to_text('0') gives '', not '0'. Conflicts: lib/simpletest/testweblib.php --- lib/html2text.php | 2 +- lib/html2text_readme.txt | 15 +++++++++++++++ lib/simpletest/testweblib.php | 8 ++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/html2text.php b/lib/html2text.php index e58ada905e2..720893d069c 100644 --- a/lib/html2text.php +++ b/lib/html2text.php @@ -341,7 +341,7 @@ class html2text */ function html2text( $source = '', $from_file = false, $do_links = true, $width = 75 ) { - if ( !empty($source) ) { + if ($source !== '') { $this->set_html($source, $from_file); } diff --git a/lib/html2text_readme.txt b/lib/html2text_readme.txt index f88f17d1eb0..196aa0c5d01 100644 --- a/lib/html2text_readme.txt +++ b/lib/html2text_readme.txt @@ -82,3 +82,18 @@ Index: lib/html2text.php } -- Tim Hunt 2010-11-02 + +4 - Make sure html2text does not destroy '0'. + +index e2d0dff..9cc213d 100644 +--- a/lib/html2text.php ++++ b/lib/html2text.php +@@ -335,7 +335,7 @@ class html2text + */ + function html2text( $source = '', $from_file = false, $do_links = true, $wi { +- if ( !empty($source) ) { ++ if ($source !== '') { + $this->set_html($source, $from_file); + } + +-- Tim Hunt 2011-09-21 diff --git a/lib/simpletest/testweblib.php b/lib/simpletest/testweblib.php index e2b9b77ffc6..7009f8b2413 100644 --- a/lib/simpletest/testweblib.php +++ b/lib/simpletest/testweblib.php @@ -255,5 +255,13 @@ END; public function test_html_to_text_dont_screw_up_utf8() { $this->assertEqual("\n\nAll the WORLD’S a stage.", html_to_text('

All the world’s a stage.

')); } + + public function test_html_to_text_trailing_whitespace() { + $this->assertEqual('With trailing whitespace and some more text', html_to_text("With trailing whitespace \nand some more text", 0)); + } + + public function test_html_to_text_0() { + $this->assertIdentical('0', html_to_text('0')); + } } ?>