From 209442ce2445c973c8589fdf564a7bea34c47900 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Sat, 5 Mar 2011 19:51:38 +0000 Subject: [PATCH 1/2] MDL-26517 HTML tags visible in the response history table and quiz reports. --- question/type/essay/questiontype.php | 10 ++++++++++ question/type/questiontype.php | 6 ++++-- question/type/shortanswer/questiontype.php | 8 ++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/question/type/essay/questiontype.php b/question/type/essay/questiontype.php index 102b26f1bc2..6cb505f1329 100644 --- a/question/type/essay/questiontype.php +++ b/question/type/essay/questiontype.php @@ -127,6 +127,16 @@ class question_essay_qtype extends default_questiontype { return true; } + /** + * @param string response is a response. + * @return formatted response + */ + function format_response($response, $format) { + $safeformatoptions = new stdClass(); + $safeformatoptions->para = false; + return format_text($response, FORMAT_MOODLE, $safeformatoptions); + } + /** * Runs all the code required to set up and save an essay question for testing purposes. * Alternate DB table prefix may be used to facilitate data deletion. diff --git a/question/type/questiontype.php b/question/type/questiontype.php index 11843cdbf4d..defbe1bf00f 100644 --- a/question/type/questiontype.php +++ b/question/type/questiontype.php @@ -1348,13 +1348,15 @@ class default_questiontype { } return $toreturn; } + /** * @param string response is a response. * @return formatted response */ - function format_response($response, $format){ - return s($response); + function format_response($response, $format) { + return $this->format_text($response, $format); } + /** * Renders the question for printing and returns the LaTeX source produced * diff --git a/question/type/shortanswer/questiontype.php b/question/type/shortanswer/questiontype.php index 1388f5e4970..66ed308122a 100644 --- a/question/type/shortanswer/questiontype.php +++ b/question/type/shortanswer/questiontype.php @@ -223,6 +223,14 @@ class question_shortanswer_qtype extends default_questiontype { return preg_match($regexp, trim($string)); } + /** + * @param string response is a response. + * @return formatted response + */ + function format_response($response, $format){ + return s($response); + } + /* * Override the parent class method, to remove escaping from asterisks. */ From 71575a152cea82c647375e36c2397cb2619d1182 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Mon, 7 Mar 2011 11:57:38 +0000 Subject: [PATCH 2/2] MDL-26517 display responses in reports by converting to plain text. Following Eloy's testing, that seems to be the only safe way. It is also consistent with what has been done in Moodle 2.1. --- question/type/essay/questiontype.php | 2 +- question/type/questiontype.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/question/type/essay/questiontype.php b/question/type/essay/questiontype.php index 6cb505f1329..0bfc86ae5a5 100644 --- a/question/type/essay/questiontype.php +++ b/question/type/essay/questiontype.php @@ -134,7 +134,7 @@ class question_essay_qtype extends default_questiontype { function format_response($response, $format) { $safeformatoptions = new stdClass(); $safeformatoptions->para = false; - return format_text($response, FORMAT_MOODLE, $safeformatoptions); + return s(html_to_text(format_text($response, FORMAT_MOODLE, $safeformatoptions), 0, false)); } /** diff --git a/question/type/questiontype.php b/question/type/questiontype.php index defbe1bf00f..e5dacab5ab7 100644 --- a/question/type/questiontype.php +++ b/question/type/questiontype.php @@ -1354,7 +1354,7 @@ class default_questiontype { * @return formatted response */ function format_response($response, $format) { - return $this->format_text($response, $format); + return s(html_to_text($this->format_text($response, $format), 0, false)); } /**