Skip to content
/ server Public
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions mysql-test/main/mdev-38792.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SET sql_mode = 'ORACLE';
SELECT TO_DATE('2002 AD', 'YYYY - AD') FROM DUAL;
TO_DATE('2002 AD', 'YYYY - AD')
2002-03-15 00:00:00
SELECT TO_DATE('2002 - AD', 'YYYY AD') FROM DUAL;
TO_DATE('2002 - AD', 'YYYY AD')
2002-03-15 00:00:00
SELECT TO_DATE('2002 - AD', 'YYYY-AD') FROM DUAL;
TO_DATE('2002 - AD', 'YYYY-AD')
2002-03-15 00:00:00
11 changes: 11 additions & 0 deletions mysql-test/main/mdev-38792.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# TO_DATE: Inconsistent treatment of different separators in the date and format strings
SET sql_mode = 'ORACLE';

# case 1:
SELECT TO_DATE('2002 AD', 'YYYY - AD') FROM DUAL;

# case 2: The fixed bug:
SELECT TO_DATE('2002 - AD', 'YYYY AD') FROM DUAL;

# case 3:
SELECT TO_DATE('2002 - AD', 'YYYY-AD') FROM DUAL;
15 changes: 15 additions & 0 deletions sql/item_timefunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,21 @@ extract_oracle_date_time(THD *thd, uint16 *format_ptr,
continue;
}

/*
MDEV-38792: TO_DATE: Inconsistent treatment of different separators in the date and format strings.
Skip punctuation and spaces in the input string before matching the next
format token, but avoid skipping a '-' sign if it's followed by a digit
(as it might be part of a negative year in SYYYY).
*/
while (val < val_end && !my_isalnum(val_cs, *val))
{
if (*val == '-' && (val + 1 < val_end) && my_isdigit(val_cs, *(val + 1)))
{
break;
}
val++;
}

error= 0;
if (!(val_len= (uint) (val_end - val)))
goto error;
Expand Down