sort -nu: a comma after the decimal point can make distinct numbers compare equal

Aperta
#16,777 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
62/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
cli

Direzione di ricerca

The bug is in NumInfo::parse in src/uucore/src/lib/features/numeric_str_cmp.rs (around lines 131-137), which skips the thousands separator without checking whether a decimal point was already consumed. Reproduce with the two printf | LC_ALL=en_US.UTF-8 sort -nu examples in the issue and compare against GNU sort. Done when 1.2,9 and 1.29,0 both survive -nu, 1.2,9 sorts before 1.21,0 under -n, and 1,200.5 still equals 1200.50.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

In en_US.UTF-8, sort -nu silently drops the second of two records with distinct decimal prefixes. Both implementations exit 0.

printf '%s\n' '1.2,9' '1.29,0' | LC_ALL=en_US.UTF-8 sort -nu

GNU prints both rows. uutils prints only 1.2,9. GNU stops the numeric prefix at the comma after the decimal point. uutils skips it and compares 1.29 with 1.290.

Plain sorting is also affected.

printf '%s\n' '1.2,9' '1.21,0' | LC_ALL=en_US.UTF-8 sort -n

GNU keeps the input order. uutils puts 1.21,0 first. With -t, -k1,1n -u, both retain both rows in the first example. Both correctly treat 1,200.5 and 1200.50 as equal with -nu.

Verified on x86_64 Linux with uutils 0.12.0, 0.13.0 and main at 8b16a3dca86ae91df73db3d375205eb7718c4c03 against GNU 9.7 and 9.12. Unlike #16735, this also reproduces with -k1,1n -u using the default field delimiter. NumInfo::parse skips the thousands separator without checking whether a decimal point has already been consumed. https://github.com/uutils/coreutils/blob/8b16a3dca86ae91df73db3d375205eb7718c4c03/src/uucore/src/lib/features/numeric_str_cmp.rs#L131-L137

Lingua principale
Rust
Stelle
24.4k
Fork
2.2k
Merge medio
2g 23h
PR unite (30g)
402

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di uutils/coreutils

Tutte le issue di uutils/coreutils

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.