Remove excess white spaces in Fill Blanks questions - refs BT#12630

pull/2487/head
Angel Fernando Quiroz Campos 9 years ago
parent 9f437ff7dd
commit e710e460e9
  1. 9
      main/exercise/exercise.class.php
  2. 14
      main/exercise/fill_blanks.class.php

@ -3676,19 +3676,14 @@ class Exercise
if (!$switchableAnswerSet) {
// not switchable answer, must be in the same place than teacher order
for ($i = 0; $i < count($listCorrectAnswers['tabwords']); $i++) {
$studentAnswer = isset($choice[$i]) ? trim($choice[$i]) : '';
$studentAnswer = isset($choice[$i]) ? $choice[$i] : '';
$correctAnswer = $listCorrectAnswers['tabwords'][$i];
// This value is the user input, not escaped while correct answer is escaped by fckeditor
// Works with cyrillic alphabet and when using ">" chars see #7718 #7610 #7618
// ENT_QUOTES is used in order to transform ' to &#039;
if (!$from_database) {
$studentAnswer = htmlentities(
api_utf8_encode($studentAnswer),
ENT_QUOTES
);
// fix apostrophe
$studentAnswer = str_replace('&#039;', '&#39;', $studentAnswer);
$studentAnswer = FillBlanks::clearStudentAnswer($studentAnswer);
}
$isAnswerCorrect = 0;

@ -1322,4 +1322,18 @@ class FillBlanks extends Question
return $isCorrect;
}
/**
* Clear the answer entered by student
* @param string $answer
* @return string
*/
public static function clearStudentAnswer($answer)
{
$answer = htmlentities(api_utf8_encode($answer), ENT_QUOTES);
$answer = str_replace('&#039;', '&#39;', $answer); // fix apostrophe
$answer = api_preg_replace('/\s\s+/', ' ', $answer); // replace excess white spaces
return trim($answer);
}
}

Loading…
Cancel
Save