`-S/--smart-case` ignores `-e`/`-f` patterns and counts escapes like `\S` as uppercase
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ó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 57/100
Hướng nghiên cứu
Start with SearchOptions::effective_case_insensitive in tgrep-cli/src/search.rs, then trace how all_patterns() and parsed patterns feed the query plan and matcher. Read the existing search tests and add regression coverage for the four reproductions, including escaped uppercase characters and -e/-f; done when smart-case behavior matches the stated ripgrep expectations in indexed and no-index searches.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
-S/--smart-case decides case sensitivity in a way that differs from ripgrep in two cases:
- It only looks at the positional pattern. With
-eor-fthe positional pattern is empty, so the search is always case-insensitive, even when the given patterns contain uppercase letters. - It treats every uppercase character in the pattern text as uppercase, including those in escapes such as
\S,\Wor\D. ripgrep only counts uppercase literals: "of the literals in the pattern, none of them are considered to be uppercase according to Unicode. For example, foo\pL has no uppercase literals but Foo\pL does."
The first returns extra matches. The second misses matches. Both happen with and without the index.
Reproduce
mkdir repro && cd repro
mkdir d
printf 'abc\n' > d/lower.txt
printf 'ABC\n' > d/upper.txt
printf 'ABC\n' > pats.txt # outside d/ so the pattern file itself is not searched
tgrep --no-index -S -e ABC d
tgrep --no-index -S -f pats.txt d
tgrep --no-index -S -e abc -e XYZ d
tgrep --no-index -S 'a\Sc' d
| Query | Actual: tgrep | Expected: rg 15.1.0 |
|---|---|---|
-S -e ABC d |
upper.txt, lower.txt |
upper.txt |
-S -f pats.txt d (contains ABC) |
upper.txt, lower.txt |
upper.txt |
-S -e abc -e XYZ d |
upper.txt, lower.txt |
lower.txt |
-S 'a\Sc' d |
lower.txt |
upper.txt, lower.txt |
ripgrep applies smart case to the patterns as a whole: if any pattern has an uppercase literal, the search is case-sensitive, which is why -e abc -e XYZ does not match ABC.
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
- Same results with
--no-indexand with a local index;-S -e ABCalso reproduces throughtgrep serve
Cause
SearchOptions::effective_case_insensitive checks only self.pattern, using char::is_uppercase on the raw text:
When -e or -f is used, the positional argument moves to the path list and self.pattern is empty (search.rs#L432-L439), so the check is always true. The result feeds both the query plan and the matcher (search.rs#L817) and is sent to the server, so indexed searches get the same wrong case mode as scans.
Possible fix
Compute smart case from all_patterns() instead of self.pattern, with the search case-sensitive if any pattern has an uppercase literal:
- With
-F, every character is a literal, sois_uppercaseon the raw text is correct. - Otherwise, parse each pattern with
regex_syntax::astand look only at literal characters, as ripgrep'sgrep-regexdoes. A pattern with no literals at all (\w+) is not "all lowercase" under ripgrep's rule, so it stays case-sensitive.
A regression test could cover the four queries above.
- Ngôn ngữ chính
- Rust
- Star
- 3.5k
- Fork
- 140
- Merge trung bình
- 17 giờ 20 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
-
v1.2.6: Watcher notification on an idle Windows checkout clears `ready` during periodic content verification (unchanged-file filter gaps)Có thể đã có người làm @shengyfu đã nhận 1 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 22/100
microsoft/tgrep#221 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ 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ự
-
priority: low ☕️ type: bug 🐛
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
area:docs documentation good first issue priority:medium
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
rtk-ai/rtk#4958 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
calagopus/panel#285 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
agent-self
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
yologdev/yoyo-evolve#1117 · 1 bình luận ·
-
[Bug]: streamed Responses API flex_unavailable error maps to 500 InternalServerError instead of 429Đang mởllm translation
Độ khó 2/5 Dưới một giờ Mức phù hợp với người mới 85/100
BerriAI/litellm#49736 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày