From 4c1a35e34c9cdc8dfd5a2d346ee5c183ab93d11e Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Mon, 19 Nov 2012 17:21:00 +0000 Subject: [PATCH] MDL-36571 qtype multichoice: don't corrupt unicode characters. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit It seems that \s includes non-breaking space, and the typical one-byte representation of that is the same as some parts of multibyte unicode characters. Therefore, you need to include the u modifer on the regular expressions. Also, remove any number of
at the end of the answer. Thanks to Joseph Rézeau and Jean-Michel Vedrine for working out what the problem was, and how to fix it. --- question/type/multichoice/question.php | 8 ++++---- question/type/multichoice/tests/question_test.php | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/question/type/multichoice/question.php b/question/type/multichoice/question.php index afca6a47740..8dd70861160 100644 --- a/question/type/multichoice/question.php +++ b/question/type/multichoice/question.php @@ -126,10 +126,10 @@ abstract class qtype_multichoice_base extends question_graded_automatically { } public function make_html_inline($html) { - $html = preg_replace('~\s*

\s*~', '', $html); - $html = preg_replace('~\s*

\s*~', '
', $html); - $html = preg_replace('~
$~', '', $html); - return $html; + $html = preg_replace('~\s*

\s*~u', '', $html); + $html = preg_replace('~\s*

\s*~u', '
', $html); + $html = preg_replace('~()+$~u', '', $html); + return trim($html); } } diff --git a/question/type/multichoice/tests/question_test.php b/question/type/multichoice/tests/question_test.php index fe5ba514efe..cbd3827f5ea 100644 --- a/question/type/multichoice/tests/question_test.php +++ b/question/type/multichoice/tests/question_test.php @@ -147,6 +147,8 @@ class qtype_multichoice_single_question_test extends advanced_testcase { $this->assertEquals("Frog
XXX Graph", $mc->make_html_inline("

Frog

\n\r

XXX Graph

")); + $this->assertEquals('Frog', $mc->make_html_inline('

Frog

')); + $this->assertEquals('Frog
†', $mc->make_html_inline('

Frog

†

')); } } -- 2.43.0