Skip to content

fix(grep): UTF-8 codepoint Dot, GNU \b/\B, codepoint-aware -w - #1287

Merged
caomengxuan666 merged 1 commit into
unixwin:mainfrom
Catapult291:fix/grep-utf8-dot-and-word-boundary
Oct 23, 2026
Merged

caomengxuan666 merged 1 commit into
unixwin:mainfrom
Catapult291:fix/grep-utf8-dot-and-word-boundary

Conversation

@Catapult291

Copy link
Copy Markdown
Collaborator

Summary

Default BRE/ERE local engine matched per byte: . split CJK; \b parsed as literal b; -w used single-byte word chars.

Changes

  • UTF-8 helpers: char width, prev start, word-codepoint checks.
  • Dot advances one codepoint; find_first does not start mid-sequence.
  • WordBoundary / WordBoundaryNot for \b / \B; \< \> codepoint-aware.
  • -w word_boundary_ok codepoint-aware.

Unit tests: grep_gnu_backslash_b_word_boundary, \B, . whole codepoints, -o walk, -w CJK.

Test plan

Probe After
printf '中文\n' | grep -o '中.' e4b8ade69687 (完整「中文」)
grep '\balpha\b' rc=0
grep -o '.' on 中文测试 四个单字
-w 中文 only whole-word
CRLF alpha$, -F unchanged

Niubash defect log D7 (2026-10-23).

portable_regex matched bytewise so `grep -o 中.` split a multi-byte
character, and \\b parsed as a literal b. Dot now consumes a whole
UTF-8 sequence, find_first never restarts mid-codepoint, \\b/\\B are
GNU word boundaries, and grep -w word checks are codepoint-aware.
@caomengxuan666
caomengxuan666 merged commit 790b0f3 into unixwin:main Oct 23, 2026
8 checks passed
@caomengxuan666

Copy link
Copy Markdown
Member

Thanks — a per-byte . splitting 中文 in half is the kind of bug that matters to every CJK user of grep, and \\b parsing as a literal 'b' is genuinely miserable to debug. The codepoint-aware rewrite with the unit matrix (Dot, -o walk, -w, both boundary kinds) is the coverage this engine needed. Merged; this goes in the next release for sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants