Skip to content

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

Merged
cakebaker merged 1 commit into
uutils:mainfrom
leeewee:fix-time-style-empty-unwrap
Jun 18, 2026
Merged

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

Conversation

@leeewee

@leeewee leeewee commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

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

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown

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!

@cakebaker cakebaker merged commit a34ea4d into uutils:main Jun 18, 2026
139 of 174 checks passed
@cakebaker

Copy link
Copy Markdown
Contributor

Thanks!

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

Labels

None yet

Projects

None yet

2 participants