Permalink
Browse files

MDL-36571 qtype multichoice: don't corrupt unicode characters.

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 <br /> 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.
  • Loading branch information...
1 parent b969895 commit 0f36ae63506e807f9a1e32d05714d5287a256aa1 @timhunt timhunt committed Nov 19, 2012
Showing with 4 additions and 4 deletions.
  1. +4 −4 question/type/multichoice/question.php
@@ -126,10 +126,10 @@ public function check_file_access($qa, $options, $component, $filearea, $args, $
}
public function make_html_inline($html) {
- $html = preg_replace('~\s*<p>\s*~', '', $html);
- $html = preg_replace('~\s*</p>\s*~', '<br />', $html);
- $html = preg_replace('~<br />$~', '', $html);
- return $html;
+ $html = preg_replace('~\s*<p>\s*~u', '', $html);
+ $html = preg_replace('~\s*</p>\s*~u', '<br />', $html);
+ $html = preg_replace('~(<br\s*/?>)+$~u', '', $html);
+ return trim($html);
}
}

0 comments on commit 0f36ae6

Please sign in to comment.