Skip to content

Raise ParseError for a date with fewer than three numbers in parse_date - #1510

Open
RavSinghChandan wants to merge 1 commit into
python-babel:masterfrom
RavSinghChandan:parse-date-missing-numbers
Open

RavSinghChandan wants to merge 1 commit into
python-babel:masterfrom
RavSinghChandan:parse-date-missing-numbers

Conversation

@RavSinghChandan

Copy link
Copy Markdown

parse_date('3/9', locale='en_US') raises IndexError: list index out of range. The same happens for '3/9/', for a year alone ('2024') and for '1.2' in de_DE, because the function takes the year, the month and the day from the first three numbers of the string without checking that there are three.

parse_date already raises ParseError for a date that does not exist ('2005-02-30') and for a string with no numbers, so a caller that catches ParseError around user input (a form field, a CLI argument) gets a crash for these. It now raises ParseError with the same message as the out-of-range case.

Added a test with five inputs, with the locale format and with a custom format. It fails without the change. The test suite passes.

This branch has not been deployed

No deployments
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.

1 participant