← Back to team overview

mahara-contributors team mailing list archive

[Bug 588085] Re: param_integer fails for signed/negative integers

 

** Changed in: mahara
       Status: Fix Committed => Fix Released

-- 
param_integer fails for signed/negative integers
https://bugs.launchpad.net/bugs/588085
You received this bug notification because you are a member of Mahara
Contributors, which is subscribed to Mahara.

Status in Mahara ePortfolio: Fix Released

Bug description:
function param_integer in web.php uses the following preg_match to check if the passed var is an integer - problem is that this fails for negative integers:
preg_match('/^\d+$/',$value)

here's a check that seems to work for negative integers:
(is_numeric($x)? intval($x)==$x : false)

Unfortunately according to php.net docs, the maximum value returned by intval depends on the system. 32 bit systems have a maximum signed integer range of -2147483648 to 2147483647 - this would cause problems for integers outside this range.

perhaps we could just use an is_numeric call? - and not worry too much about specifically checking if it's an integer and rely on (int)$x to just return integers?

keen to get others thoughts on this - I haven't managed to write a regex that succeeds including signed integers - maybe someone else might have more success?





References