Skip to content

Commit

Permalink
Fixed issue #15564: Warnings shown for valid comparaison
Browse files Browse the repository at this point in the history
Dev: remove warnings for ==
Dev: add warnings for bMismatchType only if there forced string
  • Loading branch information
Shnoulle committed Nov 14, 2019
1 parent 048c7d6 commit 05eb117
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions application/helpers/expressions/em_core_helper.php
Expand Up @@ -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 '||':
Expand All @@ -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 '!=':
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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 ==='' ?
Expand All @@ -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) {
Expand Down

0 comments on commit 05eb117

Please sign in to comment.