grep - `--exclude-dir=./dir` does not exclude the operand `./dir`
维护者通常 2 天内回复
评估
调研方向
首先追踪递归遍历期间如何匹配 --exclude-dir 模式,然后将 ./box 和 ./b* 的处理方式与 issue 中描述的最后一个路径组件匹配进行比较。运行 GNU include-exclude 测试,或添加提供的回归用例;完成标准是两个模式都排除 ./box,且命令以代码 1 退出并且没有输出。
由索引模型根据 Issue 内容生成。
描述
GNU grep applies --exclude-dir to a directory named on the command line, and a pattern
that contains a / is compared with the operand as written. So
grep -r --exclude-dir=./logs needle ./logs searches nothing. uu_grep only compares the
pattern with the last path component (logs), so a pattern with a slash never matches and
the whole tree is searched. (--exclude-dir=logs with the operand ./logs already agrees.)
Related but different: #165 (implicit .), #166/PR #190 (trailing slash), PR #153
(--include/--exclude on command-line files; it does not change --exclude-dir).
Exposed by the GNU test include-exclude (grep -rl --exclude-dir=./x . ./x and
--exclude-dir='./x*' must print nothing).
Reproduction
$ mkdir -p logs/old; echo needle > logs/now.txt; echo needle > logs/old/then.txt
Rust (incorrect)
$ ./target/release/grep -r --exclude-dir=./logs needle ./logs
./logs/now.txt:needle
./logs/old/then.txt:needle
# Exit code: 0
GNU (correct)
$ LC_ALL=C /usr/bin/grep -r --exclude-dir=./logs needle ./logs
# Output: (none)
# Exit code: 1
Test
#[test]
fn exclude_dir_matches_operand_as_written() {
let (scene, _) = ucmd();
scene.fixtures.mkdir_all("box/inner");
scene.fixtures.write("box/inner/f.txt", "hay\n");
for pattern in ["./box", "./b*"] {
let mut c = scene.cmd(env!("CARGO_BIN_EXE_grep"));
c.args(&["-r", &format!("--exclude-dir={pattern}"), "hay", "./box"])
.fails_with_code(1)
.no_output();
}
}
Exposed by the GNU grep test suite: include-exclude.
- 主要语言
- Rust
- 星标
- 147
- 派生
- 34
- 平均合并
- 3 天 18 小时
- 30 天内合并 PR
- 21
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
uutils/grep 的其他 Issue
-
grep - `-L` with `-m 0` or `-v ''` prints nothing; GNU still lists every file可能已有人在做 @yunusarda-sudo 于 5 天前认领。 未关闭bug gnu-compat good first issue
难度 2/5 1-3 小时 新手友好度 83/100
维护者通常 2 天内回复
-
grep - `-v -o` with `-A`/`-B`/`-C` prints nothing; GNU prints the matches found in the context lines未关闭bug gnu-compat good first issue
难度 2/5 1-3 小时 新手友好度 83/100
维护者通常 2 天内回复
-
grep - interval counts above 32767 are accepted; GNU rejects them with `Regular expression too big`可能已有人在做 @yunusarda-sudo 于 5 天前认领。 未关闭bug gnu-compat good first issue
难度 2/5 1-3 小时 新手友好度 79/100
维护者通常 2 天内回复
-
bug gnu-compat good first issue
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 2 天内回复
-
gnu-compat good first issue oss-scanner
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 2 天内回复
相似的 Issue
-
marketing
难度 2/5 半天 新手友好度 62/100
维护者通常 1 天内回复
-
S: Untriaged T: Bug
难度 2/5 1-3 小时 新手友好度 72/100
libnyanpasu/clash-nyanpasu#6537 ·
维护者通常 1 天内回复
-
难度 2/5 1 小时以内 新手友好度 62/100
tauri-apps/tao#1445 ·
维护者通常 1 天内回复
-
bug P3
难度 1/5 1-3 小时 新手友好度 88/100
-
go good first issue test
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 2 天内回复