awk: an invalid (or unsupported) regex panics

Đang mở
#174 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
78/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ệ
awk, rust
Lĩnh vực
backend, cli

Hướng nghiên cứu

Start at interpreter/src/vm/types.rs:368, where the panic occurs, and trace how regex compilation errors reach the awk interpreter. Check the regex handling and existing CLI tests for the two cases in the issue. Done means malformed regexes report an error without panicking, while [!---] matches - and the reported tests pass.

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

Mô tả

bug crash gnu-compat good first issue

When a regex literal does not compile, uutils awk panics instead of reporting
an error. This also happens for a bracket expression GNU accepts, [a---z]
(a range ending at -).

Reproduction

Rust (incorrect)

$ ./target/release/awk 'BEGIN { print ("x" ~ /[x/) }'
thread 'main' panicked at interpreter/src/vm/types.rs:368:80:
called `Result::unwrap()` on an `Err` value: UnbalancedBracket("unbalanced [")
# Exit code: 2

$ ./target/release/awk 'BEGIN { print ("-" ~ /[a---z]/) }'
thread 'main' panicked at interpreter/src/vm/types.rs:368:80:
called `Result::unwrap()` on an `Err` value: InvalidEndpoint("invalid range endpoint")

GNU (correct)

$ gawk 'BEGIN { print ("x" ~ /[x/) }'
gawk: cmd. line:1: BEGIN { print ("x" ~ /[x/) }
gawk: cmd. line:1:                       ^ unterminated regexp
# Exit code: 1

$ gawk 'BEGIN { print ("-" ~ /[a---z]/) }'
1

Test

#[test]
fn unbalanced_bracket_regex_is_an_error() {
    ucmd()
        .arg("BEGIN { if (\"q\" ~ /[q/) print 1 }")
        .fails_with_code(1)
        .stderr_does_not_contain("panicked");
}

#[test]
fn bracket_range_ending_in_dash() {
    ucmd()
        .arg("BEGIN { print (\"-\" ~ /[!---]/) }")
        .succeeds()
        .stdout_only("1\n");
}

Exposed by the GNU awk test suite: regexpbad, regex3minus.

Ngôn ngữ chính
Rust
Star
31
Fork
13
Merge trung bình
23 giờ 42 phút
Pull request đã merge (30 ngày)
29

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

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

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

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

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.