diff --git a/application/helpers/expressions/em_core_helper.php b/application/helpers/expressions/em_core_helper.php index a0ab5045050..86de74919fd 100644 --- a/application/helpers/expressions/em_core_helper.php +++ b/application/helpers/expressions/em_core_helper.php @@ -333,18 +333,22 @@ public function RDP_EvaluateBinary(array $token) } list($bMismatchType, $bBothNumeric, $bBothString) = $this->getMismatchInformation($arg1, $arg2); $isForcedString = false; - // Set bBothString if one is forced to be string, only if both can be numeric. Mimic JS and PHP - $aForceStringArray = array('DQ_STRING', 'SQ_STRING', 'STRING'); // Question can return NUMBER or WORD : DQ and SQ is string entered by user, STRING is WORD with +"" - if ($bBothNumeric) { - if ((isset($arg1[2]) && in_array($arg1[2], $aForceStringArray) || (isset($arg2[2]) && in_array($arg2[2], $aForceStringArray)))) { + /* @var array argument as forced string, arg type is at 2. + * Question can return NUMBER or WORD : DQ and SQ is string entered by user, STRING is WORD with +"" + */ + $aForceStringArray = array('DQ_STRING', 'SQ_STRING', 'STRING'); // + if (in_array($arg1[2], $aForceStringArray) || in_array($arg2[2], $aForceStringArray)) { + $isForcedString = true; + // Set bBothString if one is forced to be string, only if both can be numeric. Mimic JS and PHP + if ($bBothNumeric) { $bBothNumeric = false; $bBothString = true; $bMismatchType = false; $arg1[0] = strval($arg1[0]); $arg2[0] = strval($arg2[0]); - $isForcedString = true; } } + switch (strtolower($token[0])) { case 'or': case '||': @@ -356,12 +360,6 @@ public function RDP_EvaluateBinary(array $token) break; case '==': case 'eq': - if($bMismatchType) { - $this->RDP_AddWarning(new EMWarningInvalidComparison($token)); - } - if($isForcedString) { - $this->RDP_AddWarning(new EMWarningInvalidComparison($token)); - } $result = array(($arg1[0] == $arg2[0]), $token[1], 'NUMBER'); break; case '!=': @@ -371,7 +369,9 @@ public function RDP_EvaluateBinary(array $token) case '<': case 'lt': if ($bMismatchType) { - $this->RDP_AddWarning(new EMWarningInvalidComparison($token)); + if($isForcedString) { + $this->RDP_AddWarning(new EMWarningInvalidComparison($token)); + } $result = array(false, $token[1], 'NUMBER'); } elseif(!$bBothNumeric && $bBothString) { if($isForcedString) { @@ -385,7 +385,9 @@ public function RDP_EvaluateBinary(array $token) case '<='; case 'le': if ($bMismatchType) { - $this->RDP_AddWarning(new EMWarningInvalidComparison($token)); + if($isForcedString) { + $this->RDP_AddWarning(new EMWarningInvalidComparison($token)); + } $result = array(false, $token[1], 'NUMBER'); } else { // Need this explicit comparison in order to be in agreement with JavaScript @@ -404,7 +406,9 @@ public function RDP_EvaluateBinary(array $token) case '>': case 'gt': if ($bMismatchType) { - $this->RDP_AddWarning(new EMWarningInvalidComparison($token)); + if($isForcedString) { + $this->RDP_AddWarning(new EMWarningInvalidComparison($token)); + } $result = array(false, $token[1], 'NUMBER'); } else { // Need this explicit comparison in order to be in agreement with JavaScript : still needed since we use ==='' ? @@ -423,7 +427,9 @@ public function RDP_EvaluateBinary(array $token) case '>='; case 'ge': if ($bMismatchType) { - $this->RDP_AddWarning(new EMWarningInvalidComparison($token)); + if($isForcedString) { + $this->RDP_AddWarning(new EMWarningInvalidComparison($token)); + } $result = array(false, $token[1], 'NUMBER'); } elseif(!$bBothNumeric && $bBothString) { if($isForcedString) {