Commit 85f78053
85f780538ecdMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(regexp): \b inside [...] character class is backspace, not 'b'
\b is a context-sensitive escape: outside a character class it's a
word-boundary anchor (handled by the outer compile loop and emitted as
RE_WBOUND before reaching parse_escape); inside [...] it's the
backspace codepoint U+0008. parse_escape's default arm returned the
raw byte 'b', so [\b] matched the letter b. Roundhouse's
JsonBuilder used /[\\\"\n\r\t\b\f]/ as its JSON escape pattern and
stripped every literal b from output ("browsers" -> "rowsers", etc).
Add the explicit case 'b': return 0x08 to parse_escape. Reachable
only via read_class_atom, so the outside-class word-boundary path
stays untouched.
Fixes #632.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 85f780538ecd
- Parent
- bf614c6e046d
lib/regexp/re_compile.cmodifiedView file
case 'v': return '\v'; case 'a': return '\a'; case 'e': return 0x1b; /* `\b` is a word boundary outside a character class, but inside `[...]` it means backspace (U+0008). The outer compile loop consumes `\b` as RE_WBOUND before reaching parse_escape, so this arm only fires from read_class_atom -- i.e. always the character-class meaning. Issue #632. */ case 'b': return 0x08; default: return ch; /* literal: \., \\, \/, \(, etc. */ }}test/regexp_backspace_in_class.expectedaddedView file
Loading diff…
test/regexp_backspace_in_class.rbaddedView file
Loading diff…