string to parse without throwing an error.
#- Patch by Stas, test case by me.
. Added support for CURLOPT_MAX_RECV_SPEED_LARGE and
CURLOPT_MAX_SEND_SPEED_LARGE. FR #51815. (Pierrick)
+- Improved Date extension:
+ . Added the + modifier to parseFromFormat to allow trailing text in the
+ string to parse without throwing an error. (Stas, Derick)
+
- Improved DBA extension:
. Added Tokyo Cabinet abstract DB support. (Michael Maclean)
. Added Berkeley DB 5 support. (Johannes, Chris Jones)
-/* Generated by re2c 0.13.5 on Sat Nov 13 14:56:03 2010 */
+/* Generated by re2c 0.13.5 on Sun Dec 12 16:09:49 2010 */
#line 1 "ext/date/lib/parse_date.re"
/*
+----------------------------------------------------------------------+
timelib_sll tmp;
Scanner in;
Scanner *s = ∈
+ int allow_extra = 0;
memset(&in, 0, sizeof(in));
in.errors = malloc(sizeof(struct timelib_error_container));
timelib_eat_until_separator((char **) &ptr);
break;
+ case '+': /* allow extra chars in the format */
+ allow_extra = 1;
+ break;
+
default:
if (*fptr != *ptr) {
add_pbf_error(s, "The format separator does not match", string, begin);
fptr++;
}
if (*ptr) {
- add_pbf_error(s, "Trailing data", string, ptr);
+ if (allow_extra) {
+ add_pbf_warning(s, "Trailing data", string, ptr);
+ } else {
+ add_pbf_error(s, "Trailing data", string, ptr);
+ }
+ }
+ /* ignore trailing +'s */
+ while (*fptr == '+') {
+ fptr++;
}
if (*fptr) {
add_pbf_error(s, "Data missing", string, ptr);
timelib_sll tmp;
Scanner in;
Scanner *s = ∈
+ int allow_extra = 0;
memset(&in, 0, sizeof(in));
in.errors = malloc(sizeof(struct timelib_error_container));
timelib_eat_until_separator((char **) &ptr);
break;
+ case '+': /* allow extra chars in the format */
+ allow_extra = 1;
+ break;
+
default:
if (*fptr != *ptr) {
add_pbf_error(s, "The format separator does not match", string, begin);
fptr++;
}
if (*ptr) {
- add_pbf_error(s, "Trailing data", string, ptr);
+ if (allow_extra) {
+ add_pbf_warning(s, "Trailing data", string, ptr);
+ } else {
+ add_pbf_error(s, "Trailing data", string, ptr);
+ }
+ }
+ /* ignore trailing +'s */
+ while (*fptr == '+') {
+ fptr++;
}
if (*fptr) {
add_pbf_error(s, "Data missing", string, ptr);
--- /dev/null
+--TEST--
+Bug #51866 (Lenient parsing with parseFromFormat)
+--FILE--
+<?php
+$tests = array(
+ array( 'Y-m-d', '2001-11-29 13:20:01' ),
+ array( 'Y-m-d+', '2001-11-29 13:20:01' ),
+ array( 'Y-m-d +', '2001-11-29 13:20:01' ),
+ array( 'Y-m-d+', '2001-11-29' ),
+ array( 'Y-m-d +', '2001-11-29' ),
+ array( 'Y-m-d +', '2001-11-29 ' ),
+);
+foreach( $tests as $test )
+{
+ list($format, $str) = $test;
+ var_dump($format, $str);
+ $d = DateTime::createFromFormat($format, $str);
+ var_dump($d);
+ var_dump(DateTime::getLastErrors());
+
+ echo "\n\n";
+}
+--EXPECTF--
+string(5) "Y-m-d"
+string(19) "2001-11-29 13:20:01"
+bool(false)
+array(4) {
+ ["warning_count"]=>
+ int(0)
+ ["warnings"]=>
+ array(0) {
+ }
+ ["error_count"]=>
+ int(1)
+ ["errors"]=>
+ array(1) {
+ [10]=>
+ string(13) "Trailing data"
+ }
+}
+
+
+string(6) "Y-m-d+"
+string(19) "2001-11-29 13:20:01"
+object(DateTime)#2 (3) {
+ ["date"]=>
+ string(19) "2001-11-29 %d:%d:%d"
+ ["timezone_type"]=>
+ int(3)
+ ["timezone"]=>
+ string(13) "Europe/London"
+}
+array(4) {
+ ["warning_count"]=>
+ int(1)
+ ["warnings"]=>
+ array(1) {
+ [10]=>
+ string(13) "Trailing data"
+ }
+ ["error_count"]=>
+ int(0)
+ ["errors"]=>
+ array(0) {
+ }
+}
+
+
+string(7) "Y-m-d +"
+string(19) "2001-11-29 13:20:01"
+object(DateTime)#3 (3) {
+ ["date"]=>
+ string(19) "2001-11-29 %d:%d:%d"
+ ["timezone_type"]=>
+ int(3)
+ ["timezone"]=>
+ string(13) "Europe/London"
+}
+array(4) {
+ ["warning_count"]=>
+ int(1)
+ ["warnings"]=>
+ array(1) {
+ [11]=>
+ string(13) "Trailing data"
+ }
+ ["error_count"]=>
+ int(0)
+ ["errors"]=>
+ array(0) {
+ }
+}
+
+
+string(6) "Y-m-d+"
+string(10) "2001-11-29"
+object(DateTime)#2 (3) {
+ ["date"]=>
+ string(19) "2001-11-29 %d:%d:%d"
+ ["timezone_type"]=>
+ int(3)
+ ["timezone"]=>
+ string(13) "Europe/London"
+}
+array(4) {
+ ["warning_count"]=>
+ int(0)
+ ["warnings"]=>
+ array(0) {
+ }
+ ["error_count"]=>
+ int(0)
+ ["errors"]=>
+ array(0) {
+ }
+}
+
+
+string(7) "Y-m-d +"
+string(10) "2001-11-29"
+bool(false)
+array(4) {
+ ["warning_count"]=>
+ int(0)
+ ["warnings"]=>
+ array(0) {
+ }
+ ["error_count"]=>
+ int(1)
+ ["errors"]=>
+ array(1) {
+ [10]=>
+ string(12) "Data missing"
+ }
+}
+
+
+string(7) "Y-m-d +"
+string(11) "2001-11-29 "
+object(DateTime)#2 (3) {
+ ["date"]=>
+ string(19) "2001-11-29 %d:%d:%d"
+ ["timezone_type"]=>
+ int(3)
+ ["timezone"]=>
+ string(13) "Europe/London"
+}
+array(4) {
+ ["warning_count"]=>
+ int(0)
+ ["warnings"]=>
+ array(0) {
+ }
+ ["error_count"]=>
+ int(0)
+ ["errors"]=>
+ array(0) {
+ }
+}