Skip to content

Commit

Permalink
Plugin: Fix encoding answers in Test2Pdf plugin - refs BT#20496
Browse files Browse the repository at this point in the history
  • Loading branch information
cfasanando committed Jan 20, 2023
1 parent 4f989dc commit 865408c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion plugin/test2pdf/src/download-pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@
foreach ($infoAnswer as $key2 => $value2) {
$listAnswerInfo = getAnswerFillInBlanks($value2['answer']);
if (!empty($listAnswerInfo['words'])) {
$answers .= implode(', ', $listAnswerInfo['words']);
$answersList = implode(', ', $listAnswerInfo['words']);
$answers .= clearStudentAnswer($answersList);
}
}
} else {
Expand Down
17 changes: 17 additions & 0 deletions plugin/test2pdf/src/test2pdf.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,23 @@ function escapeForRegexp($inChar)
}
}

/**
* Clear the answer entered.
*
* @param string $answer
*
* @return string
*/
function clearStudentAnswer($answer)
{
$answer = api_html_entity_decode($answer);
$answer = api_preg_replace('/\s\s+/', ' ', $answer); // replace excess white spaces
$answer = str_replace(''', ''', $answer);
$answer = strtr($answer, array_flip(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES)));

return trim($answer);
}

/**
* Remove all html tag.
*
Expand Down

0 comments on commit 865408c

Please sign in to comment.