Inline flags such as `(?i)` in one `-e` pattern leak into the other patterns, and indexed and scanned results disagree
Maintainer thường phản hồi trong vòng 1 ngày
Một pull request liên quan đã được merge.
- #187 của @shengyfu — đã merge
Đá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
- 76/100
Hướng nghiên cứu
Start with combine_patterns in tgrep-cli/src/matching.rs and compare how it combines multiple patterns with the per-pattern parsing in build_multi_pattern_plan in tgrep-core/src/query.rs. Add a regression test for the two reported inline-flag queries, comparing scan and indexed results. Done means inline flags affect only their own pattern and indexed, scanned, and serve results agree.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
When several patterns are given with -e (or -f), an inline flag group such as (?i) or (?-i) at the start of one pattern also applies to the patterns after it. ripgrep scopes inline flags to the pattern they appear in.
The index planner parses each pattern on its own, so it and the matcher disagree: the same query can give different results with and without the index.
Reproduce
mkdir repro && cd repro
printf 'bar\n' > bar.txt
tgrep index .
tgrep -i -e '(?-i)foo' -e 'BAR' .
tgrep --no-index -i -e '(?-i)foo' -e 'BAR' .
tgrep -e '(?i)foo' -e 'BAR' .
tgrep --no-index -e '(?i)foo' -e 'BAR' .
| Query | Actual: tgrep (index, serve) |
Actual: tgrep --no-index |
Expected: rg 15.1.0 |
|---|---|---|---|
-i -e '(?-i)foo' -e 'BAR' |
no match (exit 1) | no match (exit 1) | bar.txt:bar |
-e '(?i)foo' -e 'BAR' |
no match (exit 1) | bar.txt:bar |
no match (exit 1) |
- In the first query,
(?-i)fromfooturns-ioff forBARtoo, sobaris missed everywhere. - In the second,
(?i)fromfoomakesBARmatchbarduring a scan. The index plannedBARcase-sensitively and drops the file, so the indexed result differs from the scan.
With -w or -x the queries behave like ripgrep, because each pattern is then wrapped in its own group.
Environment
- tgrep 1.1.0, built from 1120aca (current
main) with rustc 1.95.0 (59807616e 2026-04-14) - Windows 11 Pro (build 28000); the code involved is platform-independent
- The indexed result is the same with a local index and through
tgrep serve
Cause
combine_patterns only wraps a pattern in a group for -w/-x. Otherwise it joins the raw patterns as alternatives of one group:
-e '(?i)foo' -e 'BAR' becomes (?:(?i)foo|BAR). In regex syntax a bare flag group applies until the end of the enclosing group, so it reaches BAR too. build_multi_pattern_plan plans each pattern separately, where the flag does not leak.
Possible fix
Wrap every pattern in its own non-capturing group before joining, for example (?:(?i)foo)|(?:BAR), whether or not -w/-x is set. Flags then stay inside their pattern, which is also how the planner already reads them. The fancy-regex path is built from the same combined string, so it would be covered too.
A regression test could compare both queries above across --no-index, a local index and serve.
- Ngôn ngữ chính
- Rust
- Star
- 3.5k
- Fork
- 139
- Merge trung bình
- 16 giờ 31 phút
- Pull request đã merge (30 ngày)
- 27
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/tgrep
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của microsoft/tgrep
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
mozilla-services/syncstorage-rs#2715 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 70/100
-
documentation
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
physicsdolphin/nv-uefi-unlocker#53 · 4 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area/desktop-shell
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
yantrikos/yantrik-os#1012 ·
Maintainer thường phản hồi trong vòng 1 ngày