]> granicus.if.org Git - php/commitdiff
Fixed bug #53879 (DateTime::createFromFormat() fails to parse cookie expiration date)
authorDerick Rethans <github@derickrethans.nl>
Wed, 27 Nov 2013 21:59:46 +0000 (21:59 +0000)
committerDerick Rethans <github@derickrethans.nl>
Wed, 27 Nov 2013 21:59:46 +0000 (21:59 +0000)
ext/date/php_date.c
ext/date/tests/DateTime_format_basic2.phpt
ext/date/tests/DateTime_verify.phpt
ext/date/tests/bug52063.phpt
ext/date/tests/bug53879.phpt [new file with mode: 0644]
ext/date/tests/date_constants.phpt
ext/date/tests/gmdate_variation13.phpt
ext/date/tests/test-parse-from-format.phpt

index 7e4de09c1ec7e812d9efa400df7b88bd29b30d4b..b7da07c7bdba9e6c10289c5dde1a7ab8a9e7fd9a 100644 (file)
@@ -752,6 +752,14 @@ PHP_RSHUTDOWN_FUNCTION(date)
 
 #define DATE_FORMAT_ISO8601  "Y-m-d\\TH:i:sO"
 
+/*
+ * This comes from various sources that like to contradict. I'm going with the
+ * format here because of:
+ * http://msdn.microsoft.com/en-us/library/windows/desktop/aa384321%28v=vs.85%29.aspx
+ * and http://curl.haxx.se/rfc/cookie_spec.html
+ */
+#define DATE_FORMAT_COOKIE   "l, d-M-Y H:i:s T"
+
 #define DATE_TZ_ERRMSG \
        "It is not safe to rely on the system's timezone settings. You are " \
        "*required* to use the date.timezone setting or the " \
@@ -783,7 +791,7 @@ PHP_MINIT_FUNCTION(date)
  *   with the variations that the only legal time zone is GMT
  *   and the separators between the elements of the date must be dashes."
  */
-       REGISTER_STRING_CONSTANT("DATE_COOKIE",  DATE_FORMAT_RFC850,  CONST_CS | CONST_PERSISTENT);
+       REGISTER_STRING_CONSTANT("DATE_COOKIE",  DATE_FORMAT_COOKIE,  CONST_CS | CONST_PERSISTENT);
        REGISTER_STRING_CONSTANT("DATE_ISO8601", DATE_FORMAT_ISO8601, CONST_CS | CONST_PERSISTENT);
        REGISTER_STRING_CONSTANT("DATE_RFC822",  DATE_FORMAT_RFC822,  CONST_CS | CONST_PERSISTENT);
        REGISTER_STRING_CONSTANT("DATE_RFC850",  DATE_FORMAT_RFC850,  CONST_CS | CONST_PERSISTENT);
@@ -1948,7 +1956,7 @@ static void date_register_classes(TSRMLS_D)
        zend_declare_class_constant_stringl(date_ce_date, const_name, sizeof(const_name)-1, value, sizeof(value)-1 TSRMLS_CC);
 
        REGISTER_DATE_CLASS_CONST_STRING("ATOM",    DATE_FORMAT_RFC3339);
-       REGISTER_DATE_CLASS_CONST_STRING("COOKIE",  DATE_FORMAT_RFC850);
+       REGISTER_DATE_CLASS_CONST_STRING("COOKIE",  DATE_FORMAT_COOKIE);
        REGISTER_DATE_CLASS_CONST_STRING("ISO8601", DATE_FORMAT_ISO8601);
        REGISTER_DATE_CLASS_CONST_STRING("RFC822",  DATE_FORMAT_RFC822);
        REGISTER_DATE_CLASS_CONST_STRING("RFC850",  DATE_FORMAT_RFC850);
index d7adaa5df8871b8b595a1ef6419209d6df362b8c..016fa7b6b2815a69c267af00f0e23eea5f2ac783 100644 (file)
@@ -31,7 +31,7 @@ var_dump( $date->format( DateTime::W3C) ) ;
 --EXPECT--
 *** Testing date_format() : basic functionality - formatting coinstants ***
 string(25) "2005-07-14T22:30:41+01:00"
-string(32) "Thursday, 14-Jul-05 22:30:41 BST"
+string(34) "Thursday, 14-Jul-2005 22:30:41 BST"
 string(24) "2005-07-14T22:30:41+0100"
 string(29) "Thu, 14 Jul 05 22:30:41 +0100"
 string(32) "Thursday, 14-Jul-05 22:30:41 BST"
index a03911f5c829818b556b0e78a83516b3250ea2b8..c7909747292ac3cf1cccc07c7512383db6a3eacc 100644 (file)
@@ -160,7 +160,7 @@ array(11) {
   ["ATOM"]=>
   string(13) "Y-m-d\TH:i:sP"
   ["COOKIE"]=>
-  string(16) "l, d-M-y H:i:s T"
+  string(16) "l, d-M-Y H:i:s T"
   ["ISO8601"]=>
   string(13) "Y-m-d\TH:i:sO"
   ["RFC822"]=>
@@ -180,4 +180,4 @@ array(11) {
   ["W3C"]=>
   string(13) "Y-m-d\TH:i:sP"
 }
-===DONE===
\ No newline at end of file
+===DONE===
index af9da9e429d4f21cf549afbbc05b8652a7ae0744..7364a8061225c58f68f258d403ae930a9e5981d9 100644 (file)
@@ -11,5 +11,5 @@ echo $a->format(DateTime::COOKIE);
 echo "\n";
 ?>
 --EXPECTF--
-Thursday, 01-Jan-09 00:00:00 WET
-Thursday, 01-Jan-09 00:00:00 WET
+Thursday, 01-Jan-2009 00:00:00 WET
+Thursday, 01-Jan-2009 00:00:00 WET
diff --git a/ext/date/tests/bug53879.phpt b/ext/date/tests/bug53879.phpt
new file mode 100644 (file)
index 0000000..64c0f18
--- /dev/null
@@ -0,0 +1,14 @@
+--TEST--
+Bug #53879 (DateTime::createFromFormat() fails to parse cookie expiration date)
+--FILE--
+<?php
+$date = DateTime::createFromFormat(DateTime::COOKIE, "Mon, 21-Jan-2041 15:24:52 GMT");
+print_r($date);
+?>
+--EXPECTF--
+DateTime Object
+(
+    [date] => 2041-01-21 15:24:52
+    [timezone_type] => 2
+    [timezone] => GMT
+)
index 132e24159bf84b961b5fd50d23609e575b7293f2..b9fce8c78bd0a6d82a19d34b4cca6b3caffa81e5 100644 (file)
@@ -41,8 +41,8 @@ Date constants
 --EXPECT--
 string(25) "2006-07-01T14:27:30+02:00"
 string(25) "2006-05-30T14:32:13+02:00"
-string(33) "Saturday, 01-Jul-06 14:27:30 CEST"
-string(32) "Tuesday, 30-May-06 14:32:13 CEST"
+string(35) "Saturday, 01-Jul-2006 14:27:30 CEST"
+string(34) "Tuesday, 30-May-2006 14:32:13 CEST"
 string(24) "2006-07-01T14:27:30+0200"
 string(24) "2006-05-30T14:32:13+0200"
 string(29) "Sat, 01 Jul 06 14:27:30 +0200"
index 5a19ae268e0128c2285c60bdb5b74c20eaaaf627..1d1f434ecee0ec0e354833624a5a30cccd592165 100644 (file)
@@ -45,7 +45,7 @@ string(25) "2008-08-08T08:08:08+00:00"
 string(%d) "%s"
 
 --DATE_COOKIE Constant--
-string(30) "Friday, 08-Aug-08 08:08:08 GMT"
+string(32) "Friday, 08-Aug-2008 08:08:08 GMT"
 string(%d) "%s"
 
 --DATE_RFC822 Constant--
@@ -79,4 +79,4 @@ string(%d) "%s"
 --DATE_W3C Constant--
 string(25) "2008-08-08T08:08:08+00:00"
 string(%d) "%s"
-===DONE===
\ No newline at end of file
+===DONE===
index 2bf9c4e1b8262378f9dcef5c8077c16d68b4f2fd..5bb5fe53256416044fa6ee3bfdc83357acfc9e34 100644 (file)
@@ -32,8 +32,8 @@ object(DateTime)#2 (3) {
   string(6) "+02:00"
 }
 
-string(16) "l, d-M-y H:i:s T"
-string(36) "Tuesday, 08-Jul-08 22:14:12 GMT+0200"
+string(16) "l, d-M-Y H:i:s T"
+string(38) "Tuesday, 08-Jul-2008 22:14:12 GMT+0200"
 object(DateTime)#1 (3) {
   ["date"]=>
   string(19) "2008-07-08 22:14:12"