Skip to content

Commit

Permalink
Make year range validation less strict by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
euromark committed Jul 26, 2014
1 parent d6733e3 commit b188d67
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/Cake/Test/Case/Utility/ValidationTest.php
Expand Up @@ -1462,10 +1462,11 @@ public function testDateY() {
$this->assertTrue(Validation::date('2008', array('y')));
$this->assertTrue(Validation::date('2013', array('y')));
$this->assertTrue(Validation::date('2104', array('y')));
$this->assertTrue(Validation::date('1899', array('y')));
$this->assertFalse(Validation::date('20009', array('y')));
$this->assertFalse(Validation::date(' 2012', array('y')));
$this->assertFalse(Validation::date('3000', array('y')));
$this->assertFalse(Validation::date('1899', array('y')));
$this->assertFalse(Validation::date('1799', array('y')));
}

/**
Expand Down
6 changes: 4 additions & 2 deletions lib/Cake/Utility/Validation.php
Expand Up @@ -278,7 +278,9 @@ public static function custom($check, $regex = null) {

/**
* Date validation, determines if the string passed is a valid date.
* keys that expect full month, day and year will validate leap years
* keys that expect full month, day and year will validate leap years.
*
* Years are valid from 1800 to 2999.
*
* ### Formats:
*
Expand All @@ -304,7 +306,7 @@ public static function date($check, $format = 'ymd', $regex = null) {
}
$month = '(0[123456789]|10|11|12)';
$separator = '([- /.])';
$fourDigitYear = '(([1][9][0-9][0-9])|([2][0-9][0-9][0-9]))';
$fourDigitYear = '(([1][8-9][0-9][0-9])|([2][0-9][0-9][0-9]))';
$twoDigitYear = '([0-9]{2})';
$year = '(?:' . $fourDigitYear . '|' . $twoDigitYear . ')';

Expand Down

0 comments on commit b188d67

Please sign in to comment.