-
Bug
-
Resolution: Won't Fix
-
Minor
-
None
-
2.4.10, 2.6.2
-
MOODLE_24_STABLE, MOODLE_26_STABLE
-
MDL-45520_master -
The html2text _convert_blockquotes is broken in multiple ways. One of those ways results in the potential splitting of multibyte characters, which, in some cases, leads to database exception (e.g., mysql "Incorrect string value")
The most serious defect is that the method modifies the $text string in a loop but logic assumes that the character indexes in the string have not changed.
I could find not unit test that covers _convert_blockquotes. Here are a couple that I wrote. The expected values are just my best guess as to what the intent is. They are not necessarily correct. The actual output is much worse, however.
class html2text_blockquote_testcase extends basic_testcase {
|
|
public function test_single_blockquote() {
|
|
$text = '<div><blockquote>1z2z3z4z5z6z7z8z</blockquote></div>';
|
|
$result = html_to_text($text, 0, false);
|
$this->assertEquals("1z2z3z4z5z6z7z8z\n\n", $result);
|
}
|
|
public function test_multiple_blockquotes() {
|
|
$text = '<div><blockquote>1z2z3z4z5z6z7z8z9z0z</blockquote><blockquote>1x2x3x4x5x6x7x8x9x0x</blockquote><blockquote>1c2c3c4c5c6c7c8c9c0c</blockquote><blockquote>1v2v3v4v5v6v7v8v9v0v</blockquote><blockquote>Φa√bΦc√dΦe√fΦg√hΦi√jΦk√</blockquote></div>';
|
$result = html_to_text($text, 0, false);
|
$this->assertEquals("1z2z3z4z5z6z7z8z9z0z\n\n1x2x3x4x5x6x7x8x9x0x\n\n1c2c3c4c5c6c7c8c9c0c\n\n1v2v3v4v5v6v7v8v9v0v\n\nΦa√bΦc√dΦe√fΦg√hΦi√jΦk√\n\n", $result);
|
}
|
}
|
Here is a run from current 2.6:
$ vendor/bin/phpunit lib/tests/html2text_blockquote_test.php
Moodle 2.6.2+ (Build: 20140502), mysqli, 790bc67e72b1719d1a51bce1c9fdf4edcafcb698
PHPUnit 3.7.35 by Sebastian Bergmann.Configuration read from /home/colin/prj/moodle/git/dev26/phpunit.xml
FF
Time: 496 ms, Memory: 63.75Mb
There were 2 failures:
1) html2text_blockquote_testcase::test_single_blockquote
Failed asserting that two strings are equal.
— Expected
+++ Actual
@@ @@
-'1z2z3z4z5z6z7z8z
-
+'> 1z2z3z4z5z6z7z8z
'/home/colin/prj/moodle/git/dev26/lib/tests/html2text_blockquote_test.php:12
/home/colin/prj/moodle/git/dev26/lib/phpunit/classes/basic_testcase.php:64To re-run:
vendor/bin/phpunit html2text_blockquote_testcase lib/tests/html2text_blockquote_test.php2) html2text_blockquote_testcase::test_multiple_blockquotes
Failed asserting that two strings are equal.
— Expected
+++ Actual
@@ @@
-'1z2z3z4z5z6z7z8z9z0z
+'> 1z2z3z4z5z6z7z8z9z0z-1x2x3x4x5x6x7x8x9x0x
+> 1x2x3x4x5x6x7x8x9x0x
+1v2v3v-1c2c3c4c5c6c7c8c9c0c
+> 0v
+bΦc√dΦe√fΦg-1v2v3v4v5v6v7v8v9v0v
-
-Φa√bΦc√dΦe√fΦg√hΦi√jΦk√
-
+> �k√
'/home/colin/prj/moodle/git/dev26/lib/tests/html2text_blockquote_test.php:19
/home/colin/prj/moodle/git/dev26/lib/phpunit/classes/basic_testcase.php:64To re-run:
vendor/bin/phpunit html2text_blockquote_testcase lib/tests/html2text_blockquote_test.phpFAILURES!
Tests: 2, Assertions: 2, Failures: 2.
I associated this ticket with the Quiz component because I see this problem on quiz essay questions. In fact, the fallout from the resulting database exception in the cron caused a site outage in a 2.4 instance.
- will be (partly) resolved by
-
MDL-53393 Upgrade HTML2Text to 4.0.1 for Moodle 3.1 release
-
- Closed
-