From 2ff9116587de175f074cc97a2fabd7fa7a6cf724 Mon Sep 17 00:00:00 2001 From: Denis Chenu Date: Thu, 31 Oct 2013 14:16:13 +0100 Subject: [PATCH] Dev: fixed issue #08324: Broken numeric interpretation of answer codes. Dev: this reopen #07805: because "1" is string in JS --- application/helpers/expressions/em_core_helper.php | 14 ++++++++------ scripts/expressions/em_javascript.js | 3 +-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/application/helpers/expressions/em_core_helper.php b/application/helpers/expressions/em_core_helper.php index aaba89123f1..db95e881472 100644 --- a/application/helpers/expressions/em_core_helper.php +++ b/application/helpers/expressions/em_core_helper.php @@ -254,7 +254,7 @@ private function RDP_AddError($errMsg, $token) * @return boolean - false if there is any error, else true */ - private function RDP_EvaluateBinary(array $token) + private function RDP_EvaluateBinary(array $token) { if (count($this->RDP_stack) < 2) { @@ -270,18 +270,20 @@ private function RDP_EvaluateBinary(array $token) } // Set bothnumeric only if set to numeric // Not sure if needed to test if [2] is set. : TODO review - $bNumericArg1 = ((is_numeric($arg1[0]) || $arg1[0] == '') && (!isset($arg1[2]) || $arg1[2]=='NUMBER')); - $bNumericArg2 = ((is_numeric($arg2[0]) || $arg2[0] == '') && (!isset($arg2[2]) || $arg2[2]=='NUMBER')); + $bNumericArg1 = (is_numeric($arg1[0]) || $arg1[0] == ''); + $bNumericArg2 = (is_numeric($arg2[0]) || $arg2[0] == ''); $bStringArg1 = !$bNumericArg1 || $arg1[0] == ''; $bStringArg2 = !$bNumericArg2 || $arg2[0] == ''; $bBothNumeric = ($bNumericArg1 && $bNumericArg2); $bBothString = ($bStringArg1 && $bStringArg2); $bMismatchType=(!$bBothNumeric && !$bBothString); - if($bMismatchType){// Try same than JS: if can be numeric: convert to numeric else false - if((is_numeric($arg1[0]) || $arg1[0] == '') && (is_numeric($arg2[0]) || $arg2[0] == '')) + if($bMismatchType){ + if(!((isset($arg2[2]) && $arg2[2]=='NUMBER') || (isset($arg1[2]) && $arg1[2]=='NUMBER'))) { - $bBothNumeric=true; + $bBothString=true; $bMismatchType=false; + $arg1[0]=strval($arg1[0]); + $arg2[0]=strval($arg2[0]); } } switch(strtolower($token[0])) diff --git a/scripts/expressions/em_javascript.js b/scripts/expressions/em_javascript.js index 7fe81b3eed3..789e5976d11 100644 --- a/scripts/expressions/em_javascript.js +++ b/scripts/expressions/em_javascript.js @@ -530,7 +530,6 @@ function LEMval(alias) if (value === '') { return ''; } - if (suffix == 'value' || suffix == 'valueNAOK') { // if in assessment mode, this returns the assessment value // in non-assessment mode, this is identical to .code @@ -612,7 +611,7 @@ function LEMval(alias) if (value.length > 0 && value[0]==0) { return value; // so keep 0 prefixes on numbers } - return ''+value; // convert it to string return type: because we need string compare + return +value; // convert it to numeric } } case 'rowdivid':