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

@@ -205,6 +205,12 @@
205205 case 'v': return '\v';
206206 case 'a': return '\a';
207207 case 'e': return 0x1b;
208+ /* `\b` is a word boundary outside a character class, but inside
209+ `[...]` it means backspace (U+0008). The outer compile loop
210+ consumes `\b` as RE_WBOUND before reaching parse_escape, so
211+ this arm only fires from read_class_atom -- i.e. always the
212+ character-class meaning. Issue #632. */
213+ case 'b': return 0x08;
208214 default: return ch; /* literal: \., \\, \/, \(, etc. */
209215 }
210216 }