numfmt: reject a leading + and scientific notation to match GNU - #13899
Open
AlejandroCoronadoN wants to merge 1 commit into
Open
numfmt: reject a leading + and scientific notation to match GNU#13899AlejandroCoronadoN wants to merge 1 commit into
AlejandroCoronadoN wants to merge 1 commit into
Conversation
sylvestre
force-pushed
the
fix-numfmt-scientific-plus
branch
from
August 13, 2026 07:16
17bd101 to
b1e7b46
Compare
Merging this PR will not alter performance
Performance Changes
Comparing Footnotes
|
GNU numfmt rejects a number with a leading '+' sign ("+5") as an invalid
number, and rejects scientific notation ("1e-3") as an invalid suffix in
input. Rust's i128 and f64 parsers accept both, so numfmt silently accepted
them and printed a wrong value with exit 0. Reject them in parse_number_part,
mirroring GNU's two distinct diagnostics.
sylvestre
force-pushed
the
fix-numfmt-scientific-plus
branch
from
August 13, 2026 08:13
b1e7b46 to
721a00a
Compare
|
GNU testsuite comparison: |
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.
Problem
numfmtsilently accepts inputs that GNU rejects, and prints a wrong value:Rust's
i128/f64parsers accept a leading+and scientific notation, sothese slip through
parse_number_part. TheE(Exa) suffix is not affected,because the suffix is stripped before the number is parsed.
Fix
In
parse_number_part, reject a leading+and anye/Ein the number part,using GNU's two distinct messages (
invalid numberfor the sign,invalid suffix in inputfor the exponent).Verification
Compared against GNU coreutils (
gnumfmt) over a matrix of 20 inputs: everypreviously-wrong case now matches GNU's exit code (2) and message, and valid
inputs (
1K,2.5M,100Ki,1P,3.5G,-42, ...) are unchanged.Added a regression test; the full
test_numfmtsuite passes andcargo fmt/cargo clippyare clean.