grep - `--exclude-dir=./dir` does not exclude the operand `./dir`

未关闭 适合新手
#207 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

@yunusarda-sudo 已经在做这个了。

开始于 2026年11月17日。

  • #220 来自 @yunusarda-sudo —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
84/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust
领域
cli, testing

调研方向

首先追踪递归遍历期间如何匹配 --exclude-dir 模式,然后将 ./box 和 ./b* 的处理方式与 issue 中描述的最后一个路径组件匹配进行比较。运行 GNU include-exclude 测试,或添加提供的回归用例;完成标准是两个模式都排除 ./box,且命令以代码 1 退出并且没有输出。

由索引模型根据 Issue 内容生成。

描述

bug gnu-compat good first 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 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

uutils/grep 的其他 Issue

查看 uutils/grep 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。