From: Ilia Alshanetsky Date: Tue, 15 Dec 2009 12:34:12 +0000 (+0000) Subject: Fixed bu #50392 (date_create_from_format() enforces 6 digits for 'u' format character) X-Git-Tag: php-5.4.0alpha1~191^2~2216 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=312d703cce57c12a29af3b0b568c8a10810f50bc;p=php Fixed bu #50392 (date_create_from_format() enforces 6 digits for 'u' format character) --- diff --git a/ext/date/lib/parse_date.c b/ext/date/lib/parse_date.c index c1beb48edf..a540589f89 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:40:36 2009 */ +/* Generated by re2c 0.13.5 on Tue Dec 15 07:32:15 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 a4daa3c37f..3c96581f62 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 0000000000..8d10923e03 --- /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)