diff options
-rw-r--r-- | mysql-test/r/date_formats.result | 9 | ||||
-rw-r--r-- | mysql-test/t/date_formats.test | 8 | ||||
-rw-r--r-- | sql/item_timefunc.cc | 7 |
3 files changed, 21 insertions, 3 deletions
diff --git a/mysql-test/r/date_formats.result b/mysql-test/r/date_formats.result index bbe3aee1fb0..0f7f23b7f2c 100644 --- a/mysql-test/r/date_formats.result +++ b/mysql-test/r/date_formats.result @@ -571,4 +571,13 @@ DATE_FORMAT('%Y-%m-%d %H:%i:%s', 1151414896) NULL Warnings: Warning 1292 Truncated incorrect datetime value: '%Y-%m-%d %H:%i:%s' +select str_to_date('04 /30/2004', '%m /%d/%Y'); +str_to_date('04 /30/2004', '%m /%d/%Y') +2004-04-30 +select str_to_date('04/30 /2004', '%m /%d /%Y'); +str_to_date('04/30 /2004', '%m /%d /%Y') +2004-04-30 +select str_to_date('04/30/2004 ', '%m/%d/%Y '); +str_to_date('04/30/2004 ', '%m/%d/%Y ') +2004-04-30 "End of 4.1 tests" diff --git a/mysql-test/t/date_formats.test b/mysql-test/t/date_formats.test index a81487d273d..3054ec53faa 100644 --- a/mysql-test/t/date_formats.test +++ b/mysql-test/t/date_formats.test @@ -326,4 +326,12 @@ SELECT TIME_FORMAT("25:00:00", '%l %p'); # SELECT DATE_FORMAT('%Y-%m-%d %H:%i:%s', 1151414896); +# +# Bug #22029: str_to_date returning NULL +# + +select str_to_date('04 /30/2004', '%m /%d/%Y'); +select str_to_date('04/30 /2004', '%m /%d /%Y'); +select str_to_date('04/30/2004 ', '%m/%d/%Y '); + --echo "End of 4.1 tests" diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 0bba00cbeec..d79dd2a4b44 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -290,15 +290,16 @@ static bool extract_date_time(DATE_TIME_FORMAT *format, for (; ptr != end && val != val_end; ptr++) { + /* Skip pre-space between each argument */ + while (val != val_end && my_isspace(cs, *val)) + val++; + if (*ptr == '%' && ptr+1 != end) { int val_len; char *tmp; error= 0; - /* Skip pre-space between each argument */ - while (val != val_end && my_isspace(cs, *val)) - val++; val_len= (uint) (val_end - val); switch (*++ptr) { |