Skip to content

Commit b188d67

Browse files
author
euromark
committed
Make year range validation less strict by default.
1 parent d6733e3 commit b188d67

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/Cake/Test/Case/Utility/ValidationTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1462,10 +1462,11 @@ public function testDateY() {
14621462
$this->assertTrue(Validation::date('2008', array('y')));
14631463
$this->assertTrue(Validation::date('2013', array('y')));
14641464
$this->assertTrue(Validation::date('2104', array('y')));
1465+
$this->assertTrue(Validation::date('1899', array('y')));
14651466
$this->assertFalse(Validation::date('20009', array('y')));
14661467
$this->assertFalse(Validation::date(' 2012', array('y')));
14671468
$this->assertFalse(Validation::date('3000', array('y')));
1468-
$this->assertFalse(Validation::date('1899', array('y')));
1469+
$this->assertFalse(Validation::date('1799', array('y')));
14691470
}
14701471

14711472
/**

lib/Cake/Utility/Validation.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,9 @@ public static function custom($check, $regex = null) {
278278

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

0 commit comments

Comments
 (0)