Skip to content

Commit

Permalink
MDL-75874 aiken_html: correctly display HTML chars for Aiken questions
Browse files Browse the repository at this point in the history
Updates the Aiken Format class to process answers correctly, enabling
support for special HTML characteres such as <, >, and &.

Co-authored-by: Leticia Luz <[email protected]>
  • Loading branch information
matheusot and leadrielli committed Nov 10, 2022
1 parent 35f39c4 commit caf6b65
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
3 changes: 1 addition & 2 deletions question/format/aiken/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ public function readquestions($lines) {
}

// 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)) {
Expand Down
13 changes: 11 additions & 2 deletions question/format/aiken/tests/aikenformat_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,19 @@ public function test_readquestions() {
$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;
}
}

Expand All @@ -83,5 +86,11 @@ public function test_readquestions() {
$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 (&lt; &gt; &amp;)', $q3->answer[0]['text']);
$this->assertEquals('Incorrect (&lt; &gt; &amp;)', $q3->answer[1]['text']);
}
}
7 changes: 6 additions & 1 deletion question/format/aiken/tests/fixtures/aiken_errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ B) Incorrect-ish
A second good question
A)Incorrect (No space)
B)Correct (No space)
ANSWER: B
ANSWER: B

A third good question with HTML chars such as > < &
A) Correct (< > &)
B) Incorrect (< > &)
ANSWER: A

0 comments on commit caf6b65

Please sign in to comment.