Skip to content

sort: don't accept leading '+' in numeric (-n) sort#12336

Open
c-tonneslan wants to merge 1 commit into
uutils:mainfrom
c-tonneslan:fix/sort-numeric-plus-sign
Open

sort: don't accept leading '+' in numeric (-n) sort#12336
c-tonneslan wants to merge 1 commit into
uutils:mainfrom
c-tonneslan:fix/sort-numeric-plus-sign

Conversation

@c-tonneslan
Copy link
Copy Markdown

Rust's f64 parser happily accepts +1 as 1.0, so the whole-line numeric fast path in sort -n was treating +1, +10, +2 as numbers and sorting them numerically. GNU sort -n doesn't accept a leading + (only -g does), so those lines should compare lexicographically and stay in their original order.

Reproduces on main:

$ printf '+1\n+10\n+2\n' | target/debug/sort -n
+1
+2
+10
$ printf '+1\n+10\n+2\n' | /usr/bin/sort -n
+1
+10
+2

Fix: exclude inputs containing + from the fast path so they fall through to the regular comparator, which already rejects + as a sign.

Closes #10315.

Rust's f64 parser happily accepts "+1" as 1.0, so the whole-line
numeric fast path was treating "+1", "+10", "+2" as numbers and
sorting them numerically. GNU sort -n explicitly rejects a leading
'+' (that's reserved for -g), so the lines should compare
lexicographically and end up in their original order.

Reject inputs containing '+' from the fast path so they fall through
to the regular comparator, which already does the right thing.

Closes uutils#10315.

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
@github-actions
Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/date/resolution (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/retry (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/tee/tee is no longer failing!
Congrats! The gnu test tests/printf/printf-surprise is now passing!
Congrats! The gnu test tests/seq/seq-epipe is now passing!

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.

sort: numeric sort (-n) incorrectly parses '+' as a number sign

1 participant