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

オープン
#16,777 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
62/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
rust
領域
cli

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Rust
スター
24.4k
フォーク
2.2k
平均マージ
2日 23時間
マージ済み PR(30日)
402

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

uutils/coreutils のほかの issue

uutils/coreutils の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。