From 3695cfa93f351dc3b9e2f0d8c7ade222bd952596 Mon Sep 17 00:00:00 2001
From: thepurpleblob <thepurpleblob>
Date: Fri, 19 Sep 2008 10:01:47 +0000
Subject: [PATCH] MDL-16570 Use CDATA sections for text where required. More
 readable and less error prone.

Merged from MOODLE_19_STABLE
---
 question/format/xml/format.php | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/question/format/xml/format.php b/question/format/xml/format.php
index df5a6aaf6a..8f8edad9cf 100755
--- a/question/format/xml/format.php
+++ b/question/format/xml/format.php
@@ -692,8 +692,10 @@ class qformat_xml extends qformat_default {
     function writetext( $raw, $ilev=0, $short=true) {
         $indent = str_repeat( "  ",$ilev );
 
-        // encode the text to 'disguise' HTML content 
-        $raw = htmlspecialchars( $raw );
+        // if required add CDATA tags
+        if (!empty($raw) and (htmlspecialchars($raw)!=$raw)) {
+            $raw = "<![CDATA[$raw]]>";
+        }
 
         if ($short) {
             $xml = "$indent<text>$raw</text>\n";
-- 
2.39.5