diff --git a/cake/libs/sanitize.php b/cake/libs/sanitize.php index 3e35b324a..32f4fc441 100644 --- a/cake/libs/sanitize.php +++ b/cake/libs/sanitize.php @@ -72,7 +72,7 @@ class Sanitize{ */ function escape($string, $connection = 'default') { $db =& ConnectionManager::getDataSource($connection); - if (is_numeric($string)) { + if (is_numeric($string) || $string === null) { return $string; } $string = substr($db->value($string), 1); diff --git a/cake/tests/cases/libs/sanitize.test.php b/cake/tests/cases/libs/sanitize.test.php index ade669e56..746d5137a 100644 --- a/cake/tests/cases/libs/sanitize.test.php +++ b/cake/tests/cases/libs/sanitize.test.php @@ -50,6 +50,15 @@ class SanitizeTest extends UnitTestCase { $resultNumeric = Sanitize::escape('#1234.23', 'default'); $this->assertEqual($resultNumeric, '#1234.23'); + + $resultNull = Sanitize::escape(null, 'default'); + $this->assertEqual($resultNull, null); + + $resultNull = Sanitize::escape(false, 'default'); + $this->assertEqual($resultNull, false); + + $resultNull = Sanitize::escape(true, 'default'); + $this->assertEqual($resultNull, true); } function testClean() { @@ -77,7 +86,7 @@ class SanitizeTest extends UnitTestCase { $expected = 'test & "quote" \'other\' ;.$ symbol.' . "\r" . 'another line'; $result = Sanitize::clean($string, array('encode' => false, 'escape' => false, 'carriage' => false)); $this->assertEqual($result, $expected); - + $array = array(array('test & "quote" \'other\' ;.$ symbol.' . "\r" . 'another line')); $expected = array(array('test & "quote" 'other' ;.$ symbol.another line')); $result = Sanitize::clean($array); @@ -87,13 +96,6 @@ class SanitizeTest extends UnitTestCase { $expected = array(array('test & "quote" \'other\' ;.$ $ symbol.another line')); $result = Sanitize::clean($array, array('encode' => false, 'escape' => false)); $this->assertEqual($result, $expected); - - - - - - - } } ?>