Skip to content

numfmt: accept '+', leading blanks and 'k' in unit sizes - #16892

Merged
sylvestre merged 2 commits into
uutils:mainfrom
binhvq:numfmt-unit-size-sign
Nov 27, 2026
Merged

sylvestre merged 2 commits into
uutils:mainfrom
binhvq:numfmt-unit-size-sign

Conversation

@binhvq

@binhvq binhvq commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

--from-unit and --to-unit rejected sizes like +5, 5 and 2k, and took an empty size as 1. parse_unit_size now skips leading blanks and one '+' before the digits, takes 'k' like 'K', and only accepts a bare suffix such as K when nothing comes before it, so '', K and +K are rejected.

Closes #16891

#[case::invalid_arg_number_with_ignore_returns_status_0(&["--invalid=ignore", "4Q"], "4Q\n")]
#[case::from_unit(&["--from-unit=512", "4"], "2048\n")]
#[case::to_unit(&["--to-unit=512", "2048"], "4\n")]
#[case::from_unit_with_plus_and_lowercase_k(&["--from-unit=+2k", "4"], "8000\n")]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please add a case with ki too? (e.g. --from-unit=2ki)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a --from-unit=2ki case (4 gives 8192).

@sylvestre
sylvestre merged commit 5b84528 into uutils:main Nov 27, 2026
250 of 252 checks passed
@sylvestre

Copy link
Copy Markdown
Contributor

Thanks for your PR

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.

numfmt: --from-unit/--to-unit reject a leading '+', blanks and 'k'

2 participants