Commit 0c21b9c7
0c21b9c76a0aMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · +2 added · ~1 modified
Description
Fix top-level \D / \W / \S double-negation in the regex engine
class_add_shorthand already builds the directly-matching set for every
shorthand -- positive for \d \w \s, the explicit complement (plus
utf8_any) for \D \W \S -- but the top-level dispatcher routed the
uppercase forms through RE_NCLASS, negating the complement a second
time. So "5" =~ /\D/ matched (CRuby: nil) and "x" =~ /\D/ failed
(CRuby: 0). The [...] path has no NCLASS wrapper and was already
correct.
Emit RE_CLASS for all six shorthands at top level (mirroring the \h/\H arm). The compiler sources use no top-level negated shorthand, so this is self-host safe.
Closes #1370
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 0c21b9c76a0a
- Parent
- da8e9147f743
lib/regexp/re_compile.cmodifiedView file
next_char(c); uint16_t id = add_class(c); class_add_shorthand(&c->classes[id], ch); emit(c, (ch >= 'A' && ch <= 'Z') ? RE_NCLASS : RE_CLASS, (uint8_t)id, 0); /* class_add_shorthand already builds the directly-matching set for every shorthand -- positive for d/w/s, the explicit complement (plus utf8_any) for D/W/S -- so emit RE_CLASS for all of them. The old `uppercase -> RE_NCLASS` route negated the complement a second time, so top-level \D/\W/\S matched exactly the set they should reject. The `[...]` path was unaffected (no NCLASS wrapper) and stays correct. Mirrors the \h/\H arm below. */ emit(c, RE_CLASS, (uint8_t)id, 0); } else if (ch == 'h' || ch == 'H') { /* \h / \H both carry their full positive set (hex digits /test/regex_negated_shorthand_toplevel.rbaddedView file
Loading diff…
test/regex_negated_shorthand_toplevel.rb.expectedaddedView file
Loading diff…