Skip to content

ls, du: don't panic on an empty time style after posix- strip#12634

Open
leeewee wants to merge 1 commit into
uutils:mainfrom
leeewee:fix-time-style-empty-unwrap
Open

ls, du: don't panic on an empty time style after posix- strip#12634
leeewee wants to merge 1 commit into
uutils:mainfrom
leeewee:fix-time-style-empty-unwrap

Conversation

@leeewee
Copy link
Copy Markdown
Contributor

@leeewee leeewee commented Jun 5, 2026

Fixes #12629
Fixes #12630

parse_time_style called .chars().next().unwrap() on a string left empty after stripping a posix- prefix or an empty --time-style= value (clap accepts posix- 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 --time

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) — 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 (the TIME_STYLE env path and the --time-style= argument path); both are fixed. Adds regression tests.

`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.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 5, 2026

GNU testsuite comparison:

Skip an intermittent issue tests/cut/bounded-memory (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/pr/bounded-memory is now passing!
Congrats! The gnu test tests/tail/pipe-f is now passing!

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

Labels

None yet

Projects

None yet

1 participant