`-f` drops blank lines and trims whitespace in pattern files; an empty pattern file matches every line
メンテナーはふだん 1 日以内に返信
関連するプルリクエストがすでにマージされています。
- #187 @shengyfu による — マージ済み
評価
調査の方向性
Start with SearchOptions::all_patterns in tgrep-cli/src/search.rs and trace how its pattern list reaches combine_patterns in tgrep-cli/src/matching.rs and build_multi_pattern_plan in tgrep-core/src/query.rs. Add regression coverage for blank lines, whitespace, and an empty pattern file, beginning with the --no-index examples in the issue. Done when pattern lines retain their contents, empty files match nothing, and the behavior is verified for the described search paths.
索引モデルが issue の本文から書いたものです。
説明
Summary
-f/--file reads pattern files differently from ripgrep. Every line is trimmed and blank lines are dropped, so:
- a blank line, which ripgrep treats as an empty pattern that matches every line, is ignored;
- leading and trailing whitespace is removed from each pattern (
testis searched astest); - an empty pattern file matches every line and exits 0, while ripgrep matches nothing and exits 1.
ripgrep documents the first case explicitly: "Empty pattern lines will match all input lines, and the newline is not counted as part of the pattern."
All three happen with --no-index, with the on-disk index, and through tgrep serve.
Reproduce
mkdir repro && cd repro
printf 'alpha\nbeta\n' > a.txt
printf 'alpha\n\n' > blank_line.txt # "alpha" plus one empty pattern
: > empty.txt # no patterns at all
printf ' test\n' > b.txt
printf ' test\n' > space.txt # one pattern with a leading space
tgrep --no-index -n -f blank_line.txt a.txt
tgrep --no-index -n -f empty.txt a.txt
tgrep --no-index -o -f space.txt b.txt
| Query | Actual: tgrep | Expected: rg 15.1.0 |
|---|---|---|
-n -f blank_line.txt a.txt |
1:alpha |
1:alpha, 2:beta |
-n -f empty.txt a.txt |
1:alpha, 2:beta (exit 0) |
no output (exit 1) |
-o -f space.txt b.txt |
test |
test |
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-index, with a local index (tgrep index .), and throughtgrep serve
Cause
SearchOptions::all_patterns trims each line of the pattern file and skips it if the result is empty:
For an empty file the pattern list ends up empty. combine_patterns then joins zero patterns into (?:), which matches everywhere, and build_multi_pattern_plan returns MatchAll for zero patterns. The client builds the server request from the same list (search.rs#L994), so serve behaves the same way.
Possible fix
- Keep each line as written.
str::linesalready strips both\nand\r\n, so dropping thetrim()and the empty-line filter is enough, and pattern files with CRLF line endings keep working (a file containingalpha\r\nfindsalphain both tools today). - Treat "no patterns" as "matches nothing" rather than as one empty pattern: skip the search and exit 1, as ripgrep does. An empty line in the file is one empty pattern and should still match every line.
A regression test could run the three cases above with --no-index, against a local index, and through serve.
- 主要言語
- Rust
- スター
- 3.5k
- フォーク
- 139
- 平均マージ
- 14時間 59分
- マージ済み PR(30日)
- 28
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/tgrep のほかの issue
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
メンテナーはふだん 1 日以内に返信
microsoft/tgrep の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
dsx-ai-factory/infra-controller#8341 ·
メンテナーはふだん 1 日以内に返信
-
enhancement triage:deciding
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
open-telemetry/otel-arrow#4540 ·
メンテナーはふだん 2 日以内に返信
-
benchmark: CSV report files contain blank records on Windows対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンcomponent:benchmark
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
agentic-os-org/ANOLISA#9177 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
oracle/rust-oracledb#61 ·
-
bug priority-medium to-agent
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信