dircolors: '=' is not escaped and '^'/'\\' do not toggle the backslash state, unlike GNU

Đang mở Phù hợp với người mới
#16,710 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.

  • #16711 của @saromanov — đã đóng, không merge

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
63/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

Bắt đầu với escape() trong src/uu/dircolors/src/dircolors.rs và so sánh hành vi của nó với các quy tắc GNU về need_backslash được mô tả trong issue. Kiểm tra cách xử lý parse_funky_string hiện có trong ls và thêm hoặc cập nhật các bài kiểm thử tập trung vào =, ^, dấu gạch chéo ngược và --print-ls-colors. Hoàn thành khi các đầu ra bị ảnh hưởng khớp với ví dụ GNU và đầu ra chỉ dùng để hiển thị không escape các ký tự.

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

Mô tả

U - dircolors
Description

escape() in src/uu/dircolors/src/dircolors.rs only escapes ' and :, and treats : as escaped unless the previous character is \. GNU coreutils uses a different quoting algorithm with a need_backslash state: \ and ^ toggle the state, and both : and = are escaped when the state says so. This produces different LS_COLORS output for several inputs.

Consequences:

  1. = is never escaped. The ls LS_COLORS parser treats \= as a literal = inside a glob item, so patterns containing = are mis-parsed when they are not escaped.
  2. ^ starts an escape sequence (^X control notation) in the ls parser, so it must toggle the backslash state; currently uutils escapes the : after ^, GNU does not.
  3. Because \ should toggle rather than disable escaping positionally, \\: must still escape the :.
  4. --print-ls-colors output escapes :, although GNU does not escape anything in that (display-only) mode.

Note: the missing csh escaping of ! is already tracked in #16496, this issue is only about the four points above.

Reproduction

Compared against GNU coreutils 9.11 (TERM=xterm, both reading a config from stdin via -):

$ printf 'exec x=y 01;33\n' | dircolors -b -
GNU:  LS_COLORS='ex=x\=y 01;33:';
uutils: LS_COLORS='ex=x=y 01;33:';

$ printf 'exec ^:x 01;33\n' | dircolors -b -
GNU:  LS_COLORS='ex=^:x 01;33:';
uutils: LS_COLORS='ex=^\:x 01;33:';

$ printf 'exec x\\:y 01;33\n' | dircolors -b -
GNU:  LS_COLORS='ex=x\\\:y 01;33:';
uutils: LS_COLORS='ex=x\\:y 01;33:';
Versions
  • uutils coreutils: master, commit a663b441b9b350ec54732974ae0cb7ae22e8f5b2 (also reproduces with the 0.10.0 binary shipped by the distro)
  • GNU coreutils: 9.11
  • Platform: Linux x86_64

The ls parser on both sides already understands \= / \: escapes (parse_funky_string), so fixing escape() does not break ls.

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.