From 1110aed46ad98a3b1d71977e63b83f81e75a67d0 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Wed, 11 Jun 2014 16:14:38 +0800 Subject: [PATCH] MDL-45763 Question types: Allow saving '0' as question text. --- question/type/questiontypebase.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/question/type/questiontypebase.php b/question/type/questiontypebase.php index 73fd706e3ef..cd5c43423e7 100644 --- a/question/type/questiontypebase.php +++ b/question/type/questiontypebase.php @@ -339,7 +339,10 @@ class question_type { $question->length = $this->actual_number_of_questions($question); $question->penalty = isset($form->penalty) ? $form->penalty : 0; - if (empty($form->questiontext['text'])) { + // The trim call below has the effect of casting any strange values received, + // like null or false, to an appropriate string, so we only need to test for + // missing values. Be careful not to break the value '0' here. + if (!isset($form->questiontext['text'])) { $question->questiontext = ''; } else { $question->questiontext = trim($form->questiontext['text']);