MDL-42519 qformat_xml: Correctly export questions containing ]]>

This commit is contained in:
Tim Hunt 2014-12-22 15:04:09 +00:00
parent 981f06fad5
commit 46e4c35aa9
2 changed files with 38 additions and 0 deletions

View file

@ -1055,6 +1055,10 @@ class qformat_xml extends qformat_default {
*/
public function xml_escape($string) {
if (!empty($string) && htmlspecialchars($string) != $string) {
// If the string contains something that looks like the end
// of a CDATA section, then we need to avoid errors by splitting
// the string between two CDATA sections.
$string = str_replace(']]>', ']]]]><![CDATA[>', $string);
return "<![CDATA[{$string}]]>";
} else {
return $string;