diff --git a/lib/Doctrine/Validator.php b/lib/Doctrine/Validator.php index bab8fe82c..75e63dbbb 100644 --- a/lib/Doctrine/Validator.php +++ b/lib/Doctrine/Validator.php @@ -89,7 +89,7 @@ public function validateRecord(Doctrine_Record $record) */ public static function validateLength($value, $type, $maximumLength) { - if ($maximumLength === null ) { + if ($maximumLength === null || $value === null) { return true; } if ($type == 'timestamp' || $type == 'integer' || $type == 'enum') { diff --git a/tests/ValidatorTestCase.php b/tests/ValidatorTestCase.php index 92943fa29..28cb5fa5e 100644 --- a/tests/ValidatorTestCase.php +++ b/tests/ValidatorTestCase.php @@ -123,7 +123,19 @@ public function testIsValidType() $this->assertTrue(Doctrine_Validator::isValidType($var, 'object')); } - public function testValidate2() + public function testIsValidLength() + { + // Test length is less than maximum length + $this->assertTrue(Doctrine_Validator::validateLength(1.2345, "decimal", 5)); + + // Test null value is less than maximum length + $this->assertTrue(Doctrine_Validator::validateLength(null, "decimal", 4)); + + // Test length is greater than maximum length + $this->assertFalse(Doctrine_Validator::validateLength(1.2345, "decimal", 4)); + } + + public function testValidate2() { $test = new ValidatorTest(); $test->mymixed = "message";