Skip to content

Commit

Permalink
Fixed issue #17950: is_int(false) returns true (#2431)
Browse files Browse the repository at this point in the history
Dev: false and '' disallowed
  • Loading branch information
Shnoulle committed Oct 4, 2022
1 parent 0e80c9f commit bda5f09
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions application/helpers/expressions/em_core_helper.php
Expand Up @@ -2750,17 +2750,21 @@ function exprmgr_if($testDone, $iftrue, $iffalse = '')

/**
* Return true if the variable is an integer for LimeSurvey
* Can not really use is_int due to SQL DECIMAL system. This function can surely be improved
* Allow usage of numeric answercode as int
* Can not use is_int due to SQL DECIMAL system.
* @param string $arg
* @return integer
* @link http://php.net/is_int#82857
*/
function exprmgr_int($arg)
{
if (strpos($arg, ".")) {
$arg = preg_replace("/\.$/", "", rtrim(strval($arg), "0")); // DECIMAL from SQL return always .00000000, the remove all 0 and one . , see #09550
// DECIMAL from SQL return always .00000000, the remove all 0 and one . , see #09550
$arg = preg_replace("/\.$/", "", rtrim(strval($arg), "0"));
}
return (preg_match("/^-?[0-9]*$/", $arg)); // Allow 000 for value, @link https://bugs.limesurvey.org/view.php?id=9550 DECIMAL sql type.
// Allow 000 for value
// Disallow '' (and false) @link https://bugs.limesurvey.org/view.php?id=17950
return (preg_match("/^-?\d+$/", $arg));
}
/**
* Join together $args[0-N] with ', '
Expand Down

0 comments on commit bda5f09

Please sign in to comment.