ls, du: don't panic on an empty time style after posix- strip#12634
Open
leeewee wants to merge 1 commit into
Open
ls, du: don't panic on an empty time style after posix- strip#12634leeewee wants to merge 1 commit into
leeewee wants to merge 1 commit into
Conversation
`ls -l --time-style=posix-`, `du --time --time-style=`, and `TIME_STYLE=posix- du --time` aborted with an `Option::unwrap()` panic: `parse_time_style` called `.chars().next().unwrap()` on a string left empty after stripping the `posix-` prefix or an empty `--time-style=` value (which clap accepts because `posix-` is non-empty before the strip). Test for the `+` prefix instead of unwrapping the first char, so an empty time style falls through to the existing ambiguous-argument error (`LsError::TimeStyleParseError` / `DuError::InvalidTimeStyleArg`), matching GNU (exit 2 for ls, 1 for du). du had two such sites (the `TIME_STYLE` env path and the `--time-style=` argument path); both are fixed.
|
GNU testsuite comparison: |
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.
Fixes #12629
Fixes #12630
parse_time_stylecalled.chars().next().unwrap()on a string left empty after stripping aposix-prefix or an empty--time-style=value (clap acceptsposix-since it's non-empty before the strip), so all of these aborted (SIGABRT) instead of erroring:ls -l --time-style=posix-du --time --time-style=TIME_STYLE=posix- du --timeTest for the
+prefix instead of unwrapping the first char, so an empty time style falls through to the existing ambiguous-argument error (LsError::TimeStyleParseError/DuError::InvalidTimeStyleArg) — the same message any other invalid time-style value already produces, and matching GNU's exit code (2 for ls, 1 for du). du had two such sites (theTIME_STYLEenv path and the--time-style=argument path); both are fixed. Adds regression tests.