From e710e460e94ce00256b89427e6615350ecfbee63 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Wed, 10 May 2017 12:01:40 -0500 Subject: [PATCH] Remove excess white spaces in Fill Blanks questions - refs BT#12630 --- main/exercise/exercise.class.php | 9 ++------- main/exercise/fill_blanks.class.php | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/main/exercise/exercise.class.php b/main/exercise/exercise.class.php index a6aea1a280..3813064468 100755 --- a/main/exercise/exercise.class.php +++ b/main/exercise/exercise.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 ' if (!$from_database) { - $studentAnswer = htmlentities( - api_utf8_encode($studentAnswer), - ENT_QUOTES - ); - // fix apostrophe - $studentAnswer = str_replace(''', ''', $studentAnswer); + $studentAnswer = FillBlanks::clearStudentAnswer($studentAnswer); } $isAnswerCorrect = 0; diff --git a/main/exercise/fill_blanks.class.php b/main/exercise/fill_blanks.class.php index 06b4770af0..1b1aa83d9f 100755 --- a/main/exercise/fill_blanks.class.php +++ b/main/exercise/fill_blanks.class.php @@ -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(''', ''', $answer); // fix apostrophe + $answer = api_preg_replace('/\s\s+/', ' ', $answer); // replace excess white spaces + + return trim($answer); + } }