From d0f6848e6600f9c96ce16930835000b976b87f84 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Tue, 15 Dec 2009 12:34:12 +0000 Subject: [PATCH] Fixed bu #50392 (date_create_from_format() enforces 6 digits for 'u' format character) --- NEWS | 2 ++ ext/date/lib/parse_date.c | 8 ++--- ext/date/lib/parse_date.re | 6 ++-- ext/date/tests/bug50392.phpt | 63 ++++++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 7 deletions(-) create mode 100644 ext/date/tests/bug50392.phpt diff --git a/NEWS b/NEWS index cbfe15a9bf3..3554e964a35 100644 --- a/NEWS +++ b/NEWS @@ -40,6 +40,8 @@ PHP NEWS seg fault). (davbrown4 at yahoo dot com, Felipe) - Fixed bug #50351 (performance regression handling objects, ten times slower in 5.3 than in 5.2). (Dmitry) +- Fixed bug #50392 (date_create_from_format() enforces 6 digits for 'u' + format character). (Ilia) - Fixed bug #50345 (nanosleep not detected properly on some solaris versions). (Jani) - Fixed bug #50340 (php.ini parser does not allow spaces in ini keys). (Jani) diff --git a/ext/date/lib/parse_date.c b/ext/date/lib/parse_date.c index cfb24502f59..c02d9463110 100644 --- a/ext/date/lib/parse_date.c +++ b/ext/date/lib/parse_date.c @@ -1,4 +1,4 @@ -/* Generated by re2c 0.13.5 on Wed Jul 29 16:20:12 2009 */ +/* Generated by re2c 0.13.5 on Mon Dec 14 07:41:45 2009 */ #line 1 "ext/date/lib/parse_date.re" /* +----------------------------------------------------------------------+ @@ -24086,15 +24086,15 @@ timelib_time *timelib_parse_from_format(char *format, char *string, int len, tim add_pbf_error(s, "A two digit second could not be found", string, begin); } break; - case 'u': /* six digit millisecond */ + case 'u': /* up to six digit millisecond */ { double f; char *tptr; TIMELIB_CHECK_NUMBER; tptr = ptr; - if ((f = timelib_get_nr((char **) &ptr, 6)) == TIMELIB_UNSET || ptr - tptr != 6) { - add_pbf_error(s, "A six digit millisecond could not be found", string, begin); + if ((f = timelib_get_nr((char **) &ptr, 6)) == TIMELIB_UNSET || (ptr - tptr) < 1) { + add_pbf_error(s, "At least a single digit millisecond could not be found", string, begin); } else { s->time->f = (f / 1000000); } diff --git a/ext/date/lib/parse_date.re b/ext/date/lib/parse_date.re index 2fadb7b92e5..400de37927e 100644 --- a/ext/date/lib/parse_date.re +++ b/ext/date/lib/parse_date.re @@ -1943,15 +1943,15 @@ timelib_time *timelib_parse_from_format(char *format, char *string, int len, tim add_pbf_error(s, "A two digit second could not be found", string, begin); } break; - case 'u': /* six digit millisecond */ + case 'u': /* up to six digit millisecond */ { double f; char *tptr; TIMELIB_CHECK_NUMBER; tptr = ptr; - if ((f = timelib_get_nr((char **) &ptr, 6)) == TIMELIB_UNSET || ptr - tptr != 6) { - add_pbf_error(s, "A six digit millisecond could not be found", string, begin); + if ((f = timelib_get_nr((char **) &ptr, 6)) == TIMELIB_UNSET || (ptr - tptr) < 1) { + add_pbf_error(s, "At least a single digit millisecond could not be found", string, begin); } else { s->time->f = (f / 1000000); } diff --git a/ext/date/tests/bug50392.phpt b/ext/date/tests/bug50392.phpt new file mode 100644 index 00000000000..8d10923e039 --- /dev/null +++ b/ext/date/tests/bug50392.phpt @@ -0,0 +1,63 @@ +--TEST-- +Bug #50392 date_create_from_format enforces 6 digits for 'u' format character +--FILE-- + +--EXPECT-- +bool(false) +object(DateTime)#2 (3) { + ["date"]=> + string(19) "2009-03-01 18:00:00" + ["timezone_type"]=> + int(3) + ["timezone"]=> + string(17) "Europe/Bratislava" +} +object(DateTime)#2 (3) { + ["date"]=> + string(19) "2009-03-01 18:00:00" + ["timezone_type"]=> + int(3) + ["timezone"]=> + string(17) "Europe/Bratislava" +} +object(DateTime)#2 (3) { + ["date"]=> + string(19) "2009-03-01 18:00:00" + ["timezone_type"]=> + int(3) + ["timezone"]=> + string(17) "Europe/Bratislava" +} +object(DateTime)#2 (3) { + ["date"]=> + string(19) "2009-03-01 18:00:00" + ["timezone_type"]=> + int(3) + ["timezone"]=> + string(17) "Europe/Bratislava" +} +object(DateTime)#2 (3) { + ["date"]=> + string(19) "2009-03-01 18:00:00" + ["timezone_type"]=> + int(3) + ["timezone"]=> + string(17) "Europe/Bratislava" +} +object(DateTime)#2 (3) { + ["date"]=> + string(19) "2009-03-01 18:00:00" + ["timezone_type"]=> + int(3) + ["timezone"]=> + string(17) "Europe/Bratislava" +} +bool(false)