derick                                   Sun, 07 Mar 2010 15:26:39 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=295928

Log:
- Fixed bug #40778 (DateInterval::format("%a") is always zero when an interval
  is created from an ISO string).

Bug: http://bugs.php.net/40778 (Closed) Cookies with secure parameter sent via 
HTTP
      
Changed paths:
    U   php/php-src/branches/PHP_5_3/NEWS
    U   php/php-src/branches/PHP_5_3/ext/date/lib/parse_iso_intervals.c
    U   php/php-src/branches/PHP_5_3/ext/date/lib/parse_iso_intervals.re
    U   php/php-src/branches/PHP_5_3/ext/date/php_date.c
    A   php/php-src/branches/PHP_5_3/ext/date/tests/bug49778.phpt
    U   php/php-src/trunk/ext/date/lib/parse_iso_intervals.c
    U   php/php-src/trunk/ext/date/lib/parse_iso_intervals.re
    U   php/php-src/trunk/ext/date/php_date.c
    A   php/php-src/trunk/ext/date/tests/bug49778.phpt

Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS	2010-03-07 15:25:24 UTC (rev 295927)
+++ php/php-src/branches/PHP_5_3/NEWS	2010-03-07 15:26:39 UTC (rev 295928)
@@ -28,6 +28,8 @@
 - Fixed bug #50383 (Exceptions thrown in __call / __callStatic do not include
   file and line in trace). (Felipe)
 - Fixed bug #50358 (Compile failure compiling ext/phar/util.lo). (Felipe)
+- Fixed bug #49778 (DateInterval::format("%a") is always zero when an interval
+  is created from an ISO string). (Derick)


 ?? ??? 20??, PHP 5.3.2

Modified: php/php-src/branches/PHP_5_3/ext/date/lib/parse_iso_intervals.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/date/lib/parse_iso_intervals.c	2010-03-07 15:25:24 UTC (rev 295927)
+++ php/php-src/branches/PHP_5_3/ext/date/lib/parse_iso_intervals.c	2010-03-07 15:26:39 UTC (rev 295928)
@@ -1,10 +1,10 @@
-/* Generated by re2c 0.13.5 on Tue May  5 09:42:15 2009 */
+/* Generated by re2c 0.13.5 on Sun Mar  7 14:12:01 2010 */
 #line 1 "ext/date/lib/parse_iso_intervals.re"
 /*
    +----------------------------------------------------------------------+
    | PHP Version 5                                                        |
    +----------------------------------------------------------------------+
-   | Copyright (c) 1997-2006 The PHP Group                                |
+   | Copyright (c) 1997-2010 The PHP Group                                |
    +----------------------------------------------------------------------+
    | This source file is subject to version 3.01 of the PHP license,      |
    | that is bundled with this package in the file LICENSE, and is        |
@@ -1118,6 +1118,7 @@
 	in.period->weekday = 0;
 	in.period->weekday_behavior = 0;
 	in.period->first_last_day_of = 0;
+	in.period->days = TIMELIB_UNSET;

 	in.recurrences = 1;


Modified: php/php-src/branches/PHP_5_3/ext/date/lib/parse_iso_intervals.re
===================================================================
--- php/php-src/branches/PHP_5_3/ext/date/lib/parse_iso_intervals.re	2010-03-07 15:25:24 UTC (rev 295927)
+++ php/php-src/branches/PHP_5_3/ext/date/lib/parse_iso_intervals.re	2010-03-07 15:26:39 UTC (rev 295928)
@@ -512,6 +512,7 @@
 	in.period->weekday = 0;
 	in.period->weekday_behavior = 0;
 	in.period->first_last_day_of = 0;
+	in.period->days = TIMELIB_UNSET;

 	in.recurrences = 1;


Modified: php/php-src/branches/PHP_5_3/ext/date/php_date.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/date/php_date.c	2010-03-07 15:25:24 UTC (rev 295927)
+++ php/php-src/branches/PHP_5_3/ext/date/php_date.c	2010-03-07 15:26:39 UTC (rev 295928)
@@ -2240,7 +2240,13 @@
 	PHP_DATE_INTERVAL_ADD_PROPERTY("i", i);
 	PHP_DATE_INTERVAL_ADD_PROPERTY("s", s);
 	PHP_DATE_INTERVAL_ADD_PROPERTY("invert", invert);
-	PHP_DATE_INTERVAL_ADD_PROPERTY("days", days);
+	if (intervalobj->diff->days != -99999) {
+		PHP_DATE_INTERVAL_ADD_PROPERTY("days", days);
+	} else {
+		MAKE_STD_ZVAL(zv);
+		ZVAL_FALSE(zv);
+		zend_hash_update(props, "days", 5, &zv, sizeof(zval), NULL);
+	}

 	return props;
 }
@@ -3598,7 +3604,13 @@
 				case 'S': length = slprintf(buffer, 32, "%02d", (int) t->s); break;
 				case 's': length = slprintf(buffer, 32, "%d", (int) t->s); break;

-				case 'a': length = slprintf(buffer, 32, "%d", (int) t->days); break;
+				case 'a': {
+					if ((int) t->days != -99999) {
+						length = slprintf(buffer, 32, "%d", (int) t->days);
+					} else {
+						length = slprintf(buffer, 32, "(unknown)");
+					}
+				} break;
 				case 'r': length = slprintf(buffer, 32, "%s", t->invert ? "-" : ""); break;
 				case 'R': length = slprintf(buffer, 32, "%c", t->invert ? '-' : '+'); break;


Added: php/php-src/branches/PHP_5_3/ext/date/tests/bug49778.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/date/tests/bug49778.phpt	                        (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/date/tests/bug49778.phpt	2010-03-07 15:26:39 UTC (rev 295928)
@@ -0,0 +1,30 @@
+--TEST--
+Bug #49778 (DateInterval::format("%a") is always zero when an interval is created from an ISO string)
+--FILE--
+<?php
+$i=new DateInterval('P7D');
+var_dump($i);
+echo $i->format("%d"), "\n";
+echo $i->format("%a"), "\n";
+?>
+--EXPECT--
+object(DateInterval)#1 (8) {
+  ["y"]=>
+  int(0)
+  ["m"]=>
+  int(0)
+  ["d"]=>
+  int(7)
+  ["h"]=>
+  int(0)
+  ["i"]=>
+  int(0)
+  ["s"]=>
+  int(0)
+  ["invert"]=>
+  int(0)
+  ["days"]=>
+  bool(false)
+}
+7
+(unknown)

Modified: php/php-src/trunk/ext/date/lib/parse_iso_intervals.c
===================================================================
--- php/php-src/trunk/ext/date/lib/parse_iso_intervals.c	2010-03-07 15:25:24 UTC (rev 295927)
+++ php/php-src/trunk/ext/date/lib/parse_iso_intervals.c	2010-03-07 15:26:39 UTC (rev 295928)
@@ -1,10 +1,10 @@
-/* Generated by re2c 0.13.5 on Sat Aug  2 15:43:19 2008 */
+/* Generated by re2c 0.13.5 on Sun Mar  7 15:09:39 2010 */
 #line 1 "ext/date/lib/parse_iso_intervals.re"
 /*
    +----------------------------------------------------------------------+
    | PHP Version 6                                                        |
    +----------------------------------------------------------------------+
-   | Copyright (c) 1997-2006 The PHP Group                                |
+   | Copyright (c) 1997-2010 The PHP Group                                |
    +----------------------------------------------------------------------+
    | This source file is subject to version 3.01 of the PHP license,      |
    | that is bundled with this package in the file LICENSE, and is        |
@@ -270,6 +270,11 @@
 	}                              \
 }

+/* date parser's scan function too large for VC6 - VC7.x
+   drop the optimization solves the problem */
+#ifdef PHP_WIN32
+#pragma optimize( "", off )
+#endif
 static int scan(Scanner *s)
 {
 	uchar *cursor = s->cur;
@@ -278,11 +283,11 @@
 std:
 	s->tok = cursor;
 	s->len = 0;
-#line 306 "ext/date/lib/parse_iso_intervals.re"
+#line 311 "ext/date/lib/parse_iso_intervals.re"



-#line 286 "ext/date/lib/parse_iso_intervals.c"
+#line 291 "ext/date/lib/parse_iso_intervals.c"
 {
 	YYCTYPE yych;
 	unsigned int yyaccept = 0;
@@ -352,12 +357,12 @@
 	if (yych <= '9') goto yy98;
 yy3:
 	YYDEBUG(3, *YYCURSOR);
-#line 419 "ext/date/lib/parse_iso_intervals.re"
+#line 424 "ext/date/lib/parse_iso_intervals.re"
 	{
 		add_error(s, "Unexpected character");
 		goto std;
 	}
-#line 361 "ext/date/lib/parse_iso_intervals.c"
+#line 366 "ext/date/lib/parse_iso_intervals.c"
 yy4:
 	YYDEBUG(4, *YYCURSOR);
 	yyaccept = 0;
@@ -374,7 +379,7 @@
 	if (yych == 'T') goto yy14;
 yy6:
 	YYDEBUG(6, *YYCURSOR);
-#line 346 "ext/date/lib/parse_iso_intervals.re"
+#line 351 "ext/date/lib/parse_iso_intervals.re"
 	{
 		timelib_sll nr;
 		int         in_time = 0;
@@ -415,26 +420,26 @@
 		TIMELIB_DEINIT;
 		return TIMELIB_PERIOD;
 	}
-#line 419 "ext/date/lib/parse_iso_intervals.c"
+#line 424 "ext/date/lib/parse_iso_intervals.c"
 yy7:
 	YYDEBUG(7, *YYCURSOR);
 	++YYCURSOR;
 	YYDEBUG(8, *YYCURSOR);
-#line 408 "ext/date/lib/parse_iso_intervals.re"
+#line 413 "ext/date/lib/parse_iso_intervals.re"
 	{
 		goto std;
 	}
-#line 428 "ext/date/lib/parse_iso_intervals.c"
+#line 433 "ext/date/lib/parse_iso_intervals.c"
 yy9:
 	YYDEBUG(9, *YYCURSOR);
 	++YYCURSOR;
 	YYDEBUG(10, *YYCURSOR);
-#line 413 "ext/date/lib/parse_iso_intervals.re"
+#line 418 "ext/date/lib/parse_iso_intervals.re"
 	{
 		s->pos = cursor; s->line++;
 		goto std;
 	}
-#line 438 "ext/date/lib/parse_iso_intervals.c"
+#line 443 "ext/date/lib/parse_iso_intervals.c"
 yy11:
 	YYDEBUG(11, *YYCURSOR);
 	yych = *++YYCURSOR;
@@ -764,7 +769,7 @@
 	YYDEBUG(57, *YYCURSOR);
 	++YYCURSOR;
 	YYDEBUG(58, *YYCURSOR);
-#line 388 "ext/date/lib/parse_iso_intervals.re"
+#line 393 "ext/date/lib/parse_iso_intervals.re"
 	{
 		DEBUG_OUTPUT("combinedrep");
 		TIMELIB_INIT;
@@ -783,7 +788,7 @@
 		TIMELIB_DEINIT;
 		return TIMELIB_PERIOD;
 	}
-#line 787 "ext/date/lib/parse_iso_intervals.c"
+#line 792 "ext/date/lib/parse_iso_intervals.c"
 yy59:
 	YYDEBUG(59, *YYCURSOR);
 	yych = *++YYCURSOR;
@@ -912,7 +917,7 @@
 	YYDEBUG(83, *YYCURSOR);
 	++YYCURSOR;
 	YYDEBUG(84, *YYCURSOR);
-#line 322 "ext/date/lib/parse_iso_intervals.re"
+#line 327 "ext/date/lib/parse_iso_intervals.re"
 	{
 		timelib_time *current;

@@ -935,7 +940,7 @@
 		TIMELIB_DEINIT;
 		return TIMELIB_ISO_DATE;
 	}
-#line 939 "ext/date/lib/parse_iso_intervals.c"
+#line 944 "ext/date/lib/parse_iso_intervals.c"
 yy85:
 	YYDEBUG(85, *YYCURSOR);
 	yych = *++YYCURSOR;
@@ -1013,7 +1018,7 @@
 	if (yych <= '9') goto yy98;
 yy100:
 	YYDEBUG(100, *YYCURSOR);
-#line 311 "ext/date/lib/parse_iso_intervals.re"
+#line 316 "ext/date/lib/parse_iso_intervals.re"
 	{
 		DEBUG_OUTPUT("recurrences");
 		TIMELIB_INIT;
@@ -1023,11 +1028,14 @@
 		s->have_recurrences = 1;
 		return TIMELIB_PERIOD;
 	}
-#line 1027 "ext/date/lib/parse_iso_intervals.c"
+#line 1032 "ext/date/lib/parse_iso_intervals.c"
 }
-#line 423 "ext/date/lib/parse_iso_intervals.re"
+#line 428 "ext/date/lib/parse_iso_intervals.re"

 }
+#ifdef PHP_WIN32
+#pragma optimize( "", on )
+#endif

 #define YYMAXFILL 20

@@ -1110,6 +1118,7 @@
 	in.period->weekday = 0;
 	in.period->weekday_behavior = 0;
 	in.period->first_last_day_of = 0;
+	in.period->days = TIMELIB_UNSET;

 	in.recurrences = 1;


Modified: php/php-src/trunk/ext/date/lib/parse_iso_intervals.re
===================================================================
--- php/php-src/trunk/ext/date/lib/parse_iso_intervals.re	2010-03-07 15:25:24 UTC (rev 295927)
+++ php/php-src/trunk/ext/date/lib/parse_iso_intervals.re	2010-03-07 15:26:39 UTC (rev 295928)
@@ -512,6 +512,7 @@
 	in.period->weekday = 0;
 	in.period->weekday_behavior = 0;
 	in.period->first_last_day_of = 0;
+	in.period->days = TIMELIB_UNSET;

 	in.recurrences = 1;


Modified: php/php-src/trunk/ext/date/php_date.c
===================================================================
--- php/php-src/trunk/ext/date/php_date.c	2010-03-07 15:25:24 UTC (rev 295927)
+++ php/php-src/trunk/ext/date/php_date.c	2010-03-07 15:26:39 UTC (rev 295928)
@@ -2347,7 +2347,13 @@
 	PHP_DATE_INTERVAL_ADD_PROPERTY("i", i);
 	PHP_DATE_INTERVAL_ADD_PROPERTY("s", s);
 	PHP_DATE_INTERVAL_ADD_PROPERTY("invert", invert);
-	PHP_DATE_INTERVAL_ADD_PROPERTY("days", days);
+	if (intervalobj->diff->days != -99999) {
+		PHP_DATE_INTERVAL_ADD_PROPERTY("days", days);
+	} else {
+		MAKE_STD_ZVAL(zv);
+		ZVAL_FALSE(zv);
+		zend_hash_update(props, "days", 5, &zv, sizeof(zval), NULL);
+	}

 	return props;
 }
@@ -3727,7 +3733,13 @@
 				case 'S': length = slprintf(buffer, 32, "%02d", (int) t->s); break;
 				case 's': length = slprintf(buffer, 32, "%d", (int) t->s); break;

-				case 'a': length = slprintf(buffer, 32, "%d", (int) t->days); break;
+				case 'a': {
+					if ((int) t->days != -99999) {
+						length = slprintf(buffer, 32, "%d", (int) t->days);
+					} else {
+						length = slprintf(buffer, 32, "(unknown)");
+					}
+				} break;
 				case 'r': length = slprintf(buffer, 32, "%s", t->invert ? "-" : ""); break;
 				case 'R': length = slprintf(buffer, 32, "%c", t->invert ? '-' : '+'); break;


Added: php/php-src/trunk/ext/date/tests/bug49778.phpt
===================================================================
--- php/php-src/trunk/ext/date/tests/bug49778.phpt	                        (rev 0)
+++ php/php-src/trunk/ext/date/tests/bug49778.phpt	2010-03-07 15:26:39 UTC (rev 295928)
@@ -0,0 +1,30 @@
+--TEST--
+Bug #49778 (DateInterval::format("%a") is always zero when an interval is created from an ISO string)
+--FILE--
+<?php
+$i=new DateInterval('P7D');
+var_dump($i);
+echo $i->format("%d"), "\n";
+echo $i->format("%a"), "\n";
+?>
+--EXPECT--
+object(DateInterval)#1 (8) {
+  ["y"]=>
+  int(0)
+  ["m"]=>
+  int(0)
+  ["d"]=>
+  int(7)
+  ["h"]=>
+  int(0)
+  ["i"]=>
+  int(0)
+  ["s"]=>
+  int(0)
+  ["invert"]=>
+  int(0)
+  ["days"]=>
+  bool(false)
+}
+7
+(unknown)
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to