Commit 7e4116b4 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Sanatize.php: fixed bug by sanatizing int values. Added negtive integers to be valid integers.

parent 446165d0
......@@ -33,8 +33,14 @@ class Sanatize {
switch ($sanatizeClass) {
case SANATIZE_DEFAULT:
case SANATIZE_DIGIT:
if (!ctype_digit($value))
$newvalue = (string)$value;
// remove '-'
if (substr($newvalue, 0, 1) === "-") {
$newvalue = substr($newvalue, 1);
}
if (!ctype_digit($newvalue)) {
$value = '';
}
break;
case SANATIZE_ALNUMX:
......
......@@ -27,6 +27,11 @@ class SanatizeTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals('1', Sanatize::sanatize('1', SANATIZE_ALNUMX), "SANATIZE_ALNUMX fails");
$this->assertEquals('1', Sanatize::sanatize('1', SANATIZE_ALL), "SANATIZE_ALL fails");
# Check '-3'
$this->assertEquals('-3', Sanatize::sanatize('-3', SANATIZE_DIGIT), "SANATIZE_DIGIT fails");
$this->assertEquals('-3', Sanatize::sanatize('-3', SANATIZE_ALNUMX), "SANATIZE_ALNUMX fails");
$this->assertEquals('-3', Sanatize::sanatize('-3', SANATIZE_ALL), "SANATIZE_ALL fails");
# Check 'a'
$this->assertEquals('', Sanatize::sanatize('a', SANATIZE_DIGIT), "SANATIZE_DIGIT fails");
$this->assertEquals('a', Sanatize::sanatize('a', SANATIZE_ALNUMX), "SANATIZE_ALNUMX fails");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment