Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[correctness][confirmed-defect][builtins/grep] grep -w reverses matches for punctuation-only patterns

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

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

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

调研方向

整词匹配逻辑位于 builtins/grep/grep.go 第 462 行附近,在模式两侧应用了 \b。先阅读该匹配检查,然后运行复现命令 printf '@\nx@y\n' | grep -w @,它目前输出的是 x@y 而不是 @。完成标准是:单独的 @ 行被选中,x@y 不被选中,并且 tests/scenarios/cmd/grep/flags/ 中的场景测试覆盖仅由标点组成的模式。

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

描述

Generated by the rshell behavior correctness scanner.

  • Contract: BEH-002
  • Classification: confirmed-defect
  • Impact: medium
  • Target: builtins/grep
  • Scanned commit: 514d1cb8188fda6b1accca5955dfab3b0e8aa34a

Wrapping a pattern in word boundaries is not equivalent to requiring non-word neighbors. For @, rshell rejects the standalone line and accepts x@y, exactly reversing the expected selection.

Contract sources
  • [SHELL_FEATURES.md:23](https://github.com/datadog/rshell/blob/514d1cb8188fda6b1accca5955dfab3b0e8aa34a/SHELL_FEATURES.md#L23): Supported surface; Bash/GNU behavior applies where no intentional divergence is documented.
Implementation references
  • [builtins/grep/grep.go:462](https://github.com/datadog/rshell/blob/514d1cb8188fda6b1accca5955dfab3b0e8aa34a/builtins/grep/grep.go#L462): Implements whole-word matching with \b on both sides, which incorrectly requires word/non-word transitions for non-word endpoints.

Fixture setup

Use a fresh empty working directory for each run. Build from /workspace/repo first. No fixture files are needed. Run the CLI and reference commands with that directory as cwd.

Reproducer

printf '@\nx@y\n' | grep -w @

Commands used:

  • GOENV_VERSION=1.26.3 timeout 300s go build -o /tmp/zz_correctness_scan_rshell ./cmd/rshell
  • /tmp/zz_correctness_scan_rshell --allow-all-commands --allowed-paths "$PWD" -c 'printf '"'"'@\nx@y\n'"'"' | grep -w @ '
  • LC_ALL=C.UTF-8 /usr/bin/bash --noprofile --norc -c 'printf '"'"'@\nx@y\n'"'"' | grep -w @ '
  • GOENV_VERSION=1.26.3 timeout 300s go test ./tests -run '^TestShellScenarios$/^.$/zz_correctness_scan_' -count=2 -v -timeout 300s
Expected

Exit code: 0

stdout:

@

stderr:


Actual

Exit code: 0

stdout:

x@y

stderr:


Verification

  • Reproduction runs: 4
  • Reference: Two fresh CLI fixtures and two fresh scenario fixtures; exploratory runs excluded. Native Bash 5.2.21, GNU coreutils 9.4, grep 3.11, sed 4.9, LC_ALL=C.UTF-8. Docker comparison attempted but image pull returned HTTP 502.
  • Temporary test: tests/scenarios/zz_correctness_scan_grep_word_punctuation.yaml (removed after evidence capture)
  • Suggested regression-test location: tests/scenarios/cmd/grep/flags/

Fingerprint: 3a2d49617cf7c2be540db56be523d757cafe1f0e39c7c47a34e2c38f35f62a8a

主要语言
Go
星标
31
派生
3
平均合并
2 天 9 小时
30 天内合并 PR
14

环境准备

从这里开始

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

DataDog/rshell 的其他 Issue

查看 DataDog/rshell 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

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