grep - `-E` rejects a repeat operator right after `^` or `$` (`^*`, `$*`, `^+x`)

Đang mở Phù hợp với người mới
#206 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 2 ngày

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

Đá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
82/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, testing

Hướng nghiên cứu

Bắt đầu bằng cách đọc phần xử lý các toán tử lặp và neo, sau đó so sánh các bản sửa lỗi liên quan trong #164 và #48. Bổ sung kiểm thử cho các toán tử sau ^ và $, bao gồm các trường hợp GNU spencer1 và ví dụ tái hiện được cung cấp; công việc được xem là hoàn tất khi grep chấp nhận các mẫu này và trả về những kết quả khớp cùng hành vi cảnh báo như mong đợi.

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

Mô tả

bug gnu-compat good first issue

In an extended regexp GNU grep accepts a repetition operator that follows an anchor. After
^ it warns * at start of expression (or +, ?) and searches; after $ it accepts it
silently. uu_grep exits 2 with Oniguruma's target of repeat operator is invalid.

Related: #164 covers an operator after ( or |, and #48 strips one at the very start of
the pattern; neither handles an operator after an anchor (Oniguruma reports a different error
code there).

Exposed by the GNU tests spencer1 (tests #53 ^* and #54 $*) and spencer1-locale
(the same two tests in each locale, #209-#216).

Reproduction

Rust (incorrect)

$ printf 'q\n' | ./target/release/grep -E '^*q'
grep: invalid pattern "^*q": target of repeat operator is invalid
# Exit code: 2

$ printf 'q\n' | ./target/release/grep -E 'q$*'
grep: invalid pattern "q$*": target of repeat operator is invalid
# Exit code: 2

$ printf 'q\n' | ./target/release/grep -E '(^+q)'
grep: invalid pattern "(^+q)": target of repeat operator is invalid
# Exit code: 2

GNU (correct)

$ printf 'q\n' | LC_ALL=C /usr/bin/grep -E '^*q'
/usr/bin/grep: warning: * at start of expression
q
# Exit code: 0

$ printf 'q\n' | LC_ALL=C /usr/bin/grep -E 'q$*'
q
# Exit code: 0

$ printf 'q\n' | LC_ALL=C /usr/bin/grep -E '(^+q)'
/usr/bin/grep: warning: + at start of expression
q
# Exit code: 0

Test

#[test]
fn ere_repeat_after_anchor() {
    let (_s, mut c) = ucmd();
    c.args(&["-E", "^*jo"])
        .pipe_in("jo\nx\n")
        .succeeds()
        .stdout_is("jo\n")
        .stderr_contains("* at start of expression");

    let (_s, mut c) = ucmd();
    c.args(&["-E", "jo$+"])
        .pipe_in("jo\nx\n")
        .succeeds()
        .stdout_only("jo\n");
}

Exposed by the GNU grep test suite: spencer1, spencer1-locale.

Ngôn ngữ chính
Rust
Star
147
Fork
34
Merge trung bình
3 ngày 18 giờ
Pull request đã merge (30 ngày)
21

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

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/grep

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

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.