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

Đang mở
#16,777 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
62/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
cli

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Rust
Star
24.4k
Fork
2.2k
Merge trung bình
2 ngày 23 giờ
Pull request đã merge (30 ngày)
402

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của uutils/coreutils

Tất cả issue của uutils/coreutils

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.