Skip to content

numfmt: only take a unit from the next field when converting this one - #17009

Open
seragAhmed wants to merge 2 commits into
uutils:mainfrom
seragAhmed:fix/16999-numfmt-space-separator
Open

seragAhmed wants to merge 2 commits into
uutils:mainfrom
seragAhmed:fix/16999-numfmt-space-separator

Conversation

@seragAhmed

Copy link
Copy Markdown
Contributor

With --unit-separator=' ', the whitespace splitter merged any field with a following suffix-like word, even when that field wasn't selected. In 42 R 8192 2048 the 42 R became one field, so --field=3 converted the resident memory column instead of the virtual one.

Now a field only takes the next word as its unit when it is one of the fields being converted, so unselected fields keep their numbering. Added a test with the rows from the issue.

Fixes #16999

@codspeed

codspeed Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 22 untouched benchmarks
⏩ 468 skipped benchmarks1


Comparing seragAhmed:fix/16999-numfmt-space-separator (40fb6cf) with main (f88b235)

Open in CodSpeed

Footnotes

  1. 468 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Comment thread src/uu/numfmt/src/format.rs Outdated
// otherwise a word like "R" would shift the numbering of later fields.
let mergeable = uucore::ranges::contain(&self.options.fields, field_number)
.then(|| split_mergeable_suffix(rest, self.options))
.flatten();

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 be if uucore::ranges::contain(..) && let Some(..) = split_mergeable_suffix(..), no? easier to read than then/flatten

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.

Done in f175da0.

With a blank --unit-separator, a field followed by a word that looks like a
suffix ("42 R") was merged with it even when the field was not selected,
which shifted the numbering of every later field.
@sylvestre
sylvestre force-pushed the fix/16999-numfmt-space-separator branch from f175da0 to 40fb6cf Compare December 1, 2026 16:17

This branch has not been deployed

No deployments
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: a space unit separator can make --field convert the wrong column

2 participants