Skip to content

Commit 23ab257

Browse files
committed
Fixed bug #53879 (DateTime::createFromFormat() fails to parse cookie expiration date)
1 parent 504c60d commit 23ab257

File tree

8 files changed

+35
-13
lines changed

8 files changed

+35
-13
lines changed

ext/date/php_date.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,14 @@ PHP_RSHUTDOWN_FUNCTION(date)
752752

753753
#define DATE_FORMAT_ISO8601 "Y-m-d\\TH:i:sO"
754754

755+
/*
756+
* This comes from various sources that like to contradict. I'm going with the
757+
* format here because of:
758+
* http://msdn.microsoft.com/en-us/library/windows/desktop/aa384321%28v=vs.85%29.aspx
759+
* and http://curl.haxx.se/rfc/cookie_spec.html
760+
*/
761+
#define DATE_FORMAT_COOKIE "l, d-M-Y H:i:s T"
762+
755763
#define DATE_TZ_ERRMSG \
756764
"It is not safe to rely on the system's timezone settings. You are " \
757765
"*required* to use the date.timezone setting or the " \
@@ -783,7 +791,7 @@ PHP_MINIT_FUNCTION(date)
783791
* with the variations that the only legal time zone is GMT
784792
* and the separators between the elements of the date must be dashes."
785793
*/
786-
REGISTER_STRING_CONSTANT("DATE_COOKIE", DATE_FORMAT_RFC850, CONST_CS | CONST_PERSISTENT);
794+
REGISTER_STRING_CONSTANT("DATE_COOKIE", DATE_FORMAT_COOKIE, CONST_CS | CONST_PERSISTENT);
787795
REGISTER_STRING_CONSTANT("DATE_ISO8601", DATE_FORMAT_ISO8601, CONST_CS | CONST_PERSISTENT);
788796
REGISTER_STRING_CONSTANT("DATE_RFC822", DATE_FORMAT_RFC822, CONST_CS | CONST_PERSISTENT);
789797
REGISTER_STRING_CONSTANT("DATE_RFC850", DATE_FORMAT_RFC850, CONST_CS | CONST_PERSISTENT);
@@ -1948,7 +1956,7 @@ static void date_register_classes(TSRMLS_D)
19481956
zend_declare_class_constant_stringl(date_ce_date, const_name, sizeof(const_name)-1, value, sizeof(value)-1 TSRMLS_CC);
19491957

19501958
REGISTER_DATE_CLASS_CONST_STRING("ATOM", DATE_FORMAT_RFC3339);
1951-
REGISTER_DATE_CLASS_CONST_STRING("COOKIE", DATE_FORMAT_RFC850);
1959+
REGISTER_DATE_CLASS_CONST_STRING("COOKIE", DATE_FORMAT_COOKIE);
19521960
REGISTER_DATE_CLASS_CONST_STRING("ISO8601", DATE_FORMAT_ISO8601);
19531961
REGISTER_DATE_CLASS_CONST_STRING("RFC822", DATE_FORMAT_RFC822);
19541962
REGISTER_DATE_CLASS_CONST_STRING("RFC850", DATE_FORMAT_RFC850);

ext/date/tests/DateTime_format_basic2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var_dump( $date->format( DateTime::W3C) ) ;
3131
--EXPECT--
3232
*** Testing date_format() : basic functionality - formatting coinstants ***
3333
string(25) "2005-07-14T22:30:41+01:00"
34-
string(32) "Thursday, 14-Jul-05 22:30:41 BST"
34+
string(34) "Thursday, 14-Jul-2005 22:30:41 BST"
3535
string(24) "2005-07-14T22:30:41+0100"
3636
string(29) "Thu, 14 Jul 05 22:30:41 +0100"
3737
string(32) "Thursday, 14-Jul-05 22:30:41 BST"

ext/date/tests/DateTime_verify.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ array(11) {
160160
["ATOM"]=>
161161
string(13) "Y-m-d\TH:i:sP"
162162
["COOKIE"]=>
163-
string(16) "l, d-M-y H:i:s T"
163+
string(16) "l, d-M-Y H:i:s T"
164164
["ISO8601"]=>
165165
string(13) "Y-m-d\TH:i:sO"
166166
["RFC822"]=>
@@ -180,4 +180,4 @@ array(11) {
180180
["W3C"]=>
181181
string(13) "Y-m-d\TH:i:sP"
182182
}
183-
===DONE===
183+
===DONE===

ext/date/tests/bug52063.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ echo $a->format(DateTime::COOKIE);
1111
echo "\n";
1212
?>
1313
--EXPECTF--
14-
Thursday, 01-Jan-09 00:00:00 WET
15-
Thursday, 01-Jan-09 00:00:00 WET
14+
Thursday, 01-Jan-2009 00:00:00 WET
15+
Thursday, 01-Jan-2009 00:00:00 WET

ext/date/tests/bug53879.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug #53879 (DateTime::createFromFormat() fails to parse cookie expiration date)
3+
--FILE--
4+
<?php
5+
$date = DateTime::createFromFormat(DateTime::COOKIE, "Mon, 21-Jan-2041 15:24:52 GMT");
6+
print_r($date);
7+
?>
8+
--EXPECTF--
9+
DateTime Object
10+
(
11+
[date] => 2041-01-21 15:24:52
12+
[timezone_type] => 2
13+
[timezone] => GMT
14+
)

ext/date/tests/date_constants.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ Date constants
4141
--EXPECT--
4242
string(25) "2006-07-01T14:27:30+02:00"
4343
string(25) "2006-05-30T14:32:13+02:00"
44-
string(33) "Saturday, 01-Jul-06 14:27:30 CEST"
45-
string(32) "Tuesday, 30-May-06 14:32:13 CEST"
44+
string(35) "Saturday, 01-Jul-2006 14:27:30 CEST"
45+
string(34) "Tuesday, 30-May-2006 14:32:13 CEST"
4646
string(24) "2006-07-01T14:27:30+0200"
4747
string(24) "2006-05-30T14:32:13+0200"
4848
string(29) "Sat, 01 Jul 06 14:27:30 +0200"

ext/date/tests/gmdate_variation13.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ string(25) "2008-08-08T08:08:08+00:00"
4545
string(%d) "%s"
4646

4747
--DATE_COOKIE Constant--
48-
string(30) "Friday, 08-Aug-08 08:08:08 GMT"
48+
string(32) "Friday, 08-Aug-2008 08:08:08 GMT"
4949
string(%d) "%s"
5050

5151
--DATE_RFC822 Constant--
@@ -79,4 +79,4 @@ string(%d) "%s"
7979
--DATE_W3C Constant--
8080
string(25) "2008-08-08T08:08:08+00:00"
8181
string(%d) "%s"
82-
===DONE===
82+
===DONE===

ext/date/tests/test-parse-from-format.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ object(DateTime)#2 (3) {
3232
string(6) "+02:00"
3333
}
3434

35-
string(16) "l, d-M-y H:i:s T"
36-
string(36) "Tuesday, 08-Jul-08 22:14:12 GMT+0200"
35+
string(16) "l, d-M-Y H:i:s T"
36+
string(38) "Tuesday, 08-Jul-2008 22:14:12 GMT+0200"
3737
object(DateTime)#1 (3) {
3838
["date"]=>
3939
string(19) "2008-07-08 22:14:12"

0 commit comments

Comments
 (0)