From caf6b655e61a7730d90be32418f648f87f436034 Mon Sep 17 00:00:00 2001 From: Matheus Rodrigues Date: Thu, 10 Nov 2022 09:56:28 -0300 Subject: [PATCH] MDL-75874 aiken_html: correctly display HTML chars for Aiken questions Updates the Aiken Format class to process answers correctly, enabling support for special HTML characteres such as <, >, and &. Co-authored-by: Leticia Luz --- question/format/aiken/format.php | 3 +-- question/format/aiken/tests/aikenformat_test.php | 13 +++++++++++-- .../format/aiken/tests/fixtures/aiken_errors.txt | 7 ++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/question/format/aiken/format.php b/question/format/aiken/format.php index ce358124de4..ab76310b157 100644 --- a/question/format/aiken/format.php +++ b/question/format/aiken/format.php @@ -86,8 +86,7 @@ class qformat_aiken extends qformat_default { } // A choice. Trim off the label and space, then save. - $question->answer[] = $this->text_field( - htmlspecialchars(trim(substr($nowline, 2)), ENT_NOQUOTES)); + $question->answer[] = $this->text_field(substr($nowline, 2)); $question->fraction[] = 0; $question->feedback[] = $this->text_field(''); } else if (preg_match('/^ANSWER:/', $nowline)) { diff --git a/question/format/aiken/tests/aikenformat_test.php b/question/format/aiken/tests/aikenformat_test.php index 7f5d2bc70d9..9f8fc0538c9 100644 --- a/question/format/aiken/tests/aikenformat_test.php +++ b/question/format/aiken/tests/aikenformat_test.php @@ -59,16 +59,19 @@ class aikenformat_test extends question_testcase { $this->assertStringContainsString('Error importing question A question started but not finished', $output); $this->assertStringContainsString('Question not completed before next question start on line 18', $output); - // There are two expected questions. - $this->assertCount(2, $questions); + // There are three expected questions. + $this->assertCount(3, $questions); $q1 = null; $q2 = null; + $q3 = null; foreach ($questions as $question) { if ($question->name === 'A good question') { $q1 = $question; } else if ($question->name === 'A second good question') { $q2 = $question; + } else if ($question->name === 'A third good question with HTML chars such as > < &') { + $q3 = $question; } } @@ -83,5 +86,11 @@ class aikenformat_test extends question_testcase { $this->assertEquals(1, $q2->fraction[1]); $this->assertEquals('Incorrect (No space)', $q2->answer[0]['text']); $this->assertEquals('Correct (No space)', $q2->answer[1]['text']); + + // Check the third good question that has anwsers with special HTML chars such as <, >, and &. + $this->assertCount(2, $q3->answer); + $this->assertEquals(1, $q3->fraction[0]); + $this->assertEquals('Correct (< > &)', $q3->answer[0]['text']); + $this->assertEquals('Incorrect (< > &)', $q3->answer[1]['text']); } } diff --git a/question/format/aiken/tests/fixtures/aiken_errors.txt b/question/format/aiken/tests/fixtures/aiken_errors.txt index 92e6138aea1..21afe591c09 100644 --- a/question/format/aiken/tests/fixtures/aiken_errors.txt +++ b/question/format/aiken/tests/fixtures/aiken_errors.txt @@ -18,4 +18,9 @@ B) Incorrect-ish A second good question A)Incorrect (No space) B)Correct (No space) -ANSWER: B \ No newline at end of file +ANSWER: B + +A third good question with HTML chars such as > < & +A) Correct (< > &) +B) Incorrect (< > &) +ANSWER: A \ No newline at end of file