Repository navigation
numfmt: handle --invalid one field at a time - #15639
Open
ozenyunus35 wants to merge 1 commit into
Open
ozenyunus35 wants to merge 1 commit into
ozenyunus35 wants to merge 1 commit into
Conversation
With --invalid=fail/warn/ignore, the first field that could not be converted made the whole line be printed unchanged, and only that field was reported. Like GNU, report each invalid field, write it as it is, and still convert the other fields of the line. Fixes uutils#15575
sylvestre
force-pushed
the
numfmt-invalid-per-field
branch
from
October 25, 2026 13:21
7bbde5b to
a864a57
Compare
This branch has not been deployed
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 #15575
With
--invalid=fail,warnorignore, the field writers stopped at the first selected field that was not a number.format_and_writethen printed the original line, so the valid fields on that line were not converted, and only the first invalid field got a diagnostic. GNU converts every valid field, writes each invalid field as it is, and prints one diagnostic per invalid field.The writers in
format.rsnow handle an invalid field themselves, through a smallreport_invalid_fieldhelper:abortreturns the error, as before. The line stops there, with the output written so far.failandwarnprint the diagnostic, andignoreprints nothing. Then the field is written unchanged, with the blanks before it (or as the raw bytes with-d), and the loop goes on.The writers return whether a field was invalid, so
--debugstill prints "failed to convert some of the input numbers". The output is no longer buffered in the non-abort modes, since a line is never replaced after the fact now. A line that is not valid UTF-8 (without-d) is still echoed whole, as before.I added
test_invalid_field_does_not_stop_the_line, which coversfail,warnwith-d:, andignorewith blanks before an invalid field. It fails without the change, and alltest_numfmttests and theuu_numfmtunit tests pass.I also compared 40 cases with GNU 9.12 in the
Clocale, checking stdout, stderr and the exit code. They cover all four--invalidmodes,-d,--padding,--format,--suffix,--header,--debug,--to-unit,-z, tabs and leading blanks, and invalid fields such as12abc,1e3and1000Q. Onmain, most of them differ. With this change, 37 match. The other three differ onmainin the same way, and are not about--invalid:99999999999999999999999999999 --to=sigives100R, where GNU gives101R.--from=si 2Qprints the number, where GNU reports "value too large to be printed".cargo bench -p uu_numfmtshows no change against the merge base.I used an AI assistant to help draft parts of the code and tests; I reviewed the changes and ran the tests myself.