Skip to content

fix(parser): skip extra numeric tokens in fuzzy mode instead of overflowing YMD#1480

Open
armorbreak001 wants to merge 1 commit into
dateutil:masterfrom
armorbreak001:fix/fuzzy-numeric-tokens-overflow
Open

fix(parser): skip extra numeric tokens in fuzzy mode instead of overflowing YMD#1480
armorbreak001 wants to merge 1 commit into
dateutil:masterfrom
armorbreak001:fix/fuzzy-numeric-tokens-overflow

Conversation

@armorbreak001
Copy link
Copy Markdown

When fuzzy parsing a string like 04/04/04 +32423, trailing numeric tokens encountered after a complete YMD date has been parsed were appended to the ymd list unconditionally. This caused resolve_ymd() to fail with "More than three YMD values", which in turn made parse() raise ParserError even though a valid date was present in the string.

In fuzzy mode, extra numeric tokens that would overflow YMD should be skipped (similar to how non-numeric junk tokens are handled) rather than causing the entire parse to fail.

Before:

>>> from dateutil.parser import parse
>>> parse("04/04/04 +32423", fuzzy_with_tokens=True)
ParserError: Unknown string format: 04/04/04 +32423

After:

>>> parse("04/04/04 +32423", fuzzy_with_tokens=True)
(datetime.datetime(2004, 4, 4, 0, 0), (" +",))

Fixes #95

…lowing YMD

When fuzzy parsing a string like '04/04/04 +32423', trailing numeric
tokens after a complete YMD date was parsed would be appended to the
ymd list unconditionally, causing resolve_ymd() to fail with
'More than three YMD values'. In fuzzy mode, these extra numeric
tokens should be skipped rather than causing a parse failure.

Fixes dateutil#95
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fuzzy parse whas a problem with numbers in tokens.

1 participant