diff --git a/question/engine/questionattempt.php b/question/engine/questionattempt.php index bde5115d062..4a2253ebcef 100644 --- a/question/engine/questionattempt.php +++ b/question/engine/questionattempt.php @@ -884,10 +884,10 @@ class question_attempt { case self::PARAM_MARK: // Special case to work around PARAM_NUMBER converting '' to 0. $mark = $this->get_submitted_var($name, PARAM_RAW_TRIMMED, $postdata); - if ($mark === '') { + if ($mark === '' || is_null($mark)) { return $mark; } else { - return $this->get_submitted_var($name, PARAM_NUMBER, $postdata); + return clean_param(str_replace(',', '.', $mark), PARAM_NUMBER); } case self::PARAM_FILES: diff --git a/question/engine/simpletest/testquestionattempt.php b/question/engine/simpletest/testquestionattempt.php index 84a4d4679ad..b4fe736b8b0 100644 --- a/question/engine/simpletest/testquestionattempt.php +++ b/question/engine/simpletest/testquestionattempt.php @@ -123,6 +123,16 @@ class question_attempt_test extends UnitTestCase { 'name', question_attempt::PARAM_MARK, array('name' => '123'))); } + public function test_get_submitted_var_param_mark_number_uk_decimal() { + $this->assertIdentical(123.45, $this->qa->get_submitted_var( + 'name', question_attempt::PARAM_MARK, array('name' => '123.45'))); + } + + public function test_get_submitted_var_param_mark_number_eu_decimal() { + $this->assertIdentical(123.45, $this->qa->get_submitted_var( + 'name', question_attempt::PARAM_MARK, array('name' => '123,45'))); + } + public function test_get_submitted_var_param_mark_invalid() { $this->assertIdentical(0.0, $this->qa->get_submitted_var( 'name', question_attempt::PARAM_MARK, array('name' => 'frog')));