Skip to content

Commit

Permalink
Dev: fixed issue #08324: Broken numeric interpretation of answer codes.
Browse files Browse the repository at this point in the history
Dev: this reopen #07805: because "1" is string in JS
  • Loading branch information
Shnoulle committed Oct 31, 2013
1 parent 8e2a338 commit 2ff9116
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
14 changes: 8 additions & 6 deletions application/helpers/expressions/em_core_helper.php
Expand Up @@ -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)
{
Expand All @@ -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]))
Expand Down
3 changes: 1 addition & 2 deletions scripts/expressions/em_javascript.js
Expand Up @@ -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
Expand Down Expand Up @@ -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':
Expand Down

0 comments on commit 2ff9116

Please sign in to comment.