date: reject a date string with two timezone abbreviations#12883
Merged
Conversation
`date -d "EST EST"` (and similar like `EST PST`) was accepted and produced a date, while GNU `date` rejects it as an invalid date. The trailing-abbreviation parser stripped the last timezone token and then parsed the remainder. For "EST EST" the remainder was the bare abbreviation "EST", which `parse_datetime` happily resolves to "now", so the whole string was wrongly accepted. Factor the abbreviation lookup into `resolve_tz_abbreviation` and, after stripping the trailing abbreviation, bail out when what remains is itself a bare timezone abbreviation. Such double-timezone inputs then fall through to the standard parser, which rejects them — matching GNU. A single trailing abbreviation (e.g. "2024-01-15 10:30 EST") and a bare abbreviation (e.g. "EST") keep working. Fixes uutils#12875
|
GNU testsuite comparison: |
Contributor
|
Thanks for your PR! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #12875.
date -d "EST EST"was accepted and produced a date, while GNUdaterejects it:Cause
try_parse_with_abbreviationstrips a trailing timezone abbreviation and parsesthe remainder. For
"EST EST"the remainder is the bare abbreviation"EST",which
parse_datetimeresolves to "now", so the whole string was wrongly accepted.Change
resolve_tz_abbreviation.bare timezone abbreviation. These double-timezone inputs then fall through to the
standard parser, which already rejects them — matching GNU.
Single and bare abbreviations are unaffected:
Checks
test_date_double_timezone_is_invalid; alltest_date_tz_abbreviation_*tests still pass (9/9).cargo fmtclean,cargo clippy -p uu_date --all-targetsclean.