Commit fdceb0c5
fdceb0c5ecd8Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
fix(codegen): pass byte length, not char count, to re_compile
Stage 1 of issue #61. emit_regexp_runtime called re_compile with pat.length (character count, UTF-8 aware) but the engine reads pat as a byte buffer; for a UTF-8 source like [₀₁₂…], char count = 18 but byte count = 48, so the engine truncated 30 bytes mid-multibyte and the program crashed at startup with "unterminated character class".
This commit only fixes the truncation. Full end-to-end UTF-8 support in [...] character classes (engine-side) and dispatching .match? on a regex held in a local or constant (codegen-side) are separate stages and remain open against issue #61.
Refs #61
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- fdceb0c5ecd8
- Parent
- e7bbaf3efdd4
spinel_codegen.rbmodifiedView file
end pi = pi + 1 end emit_raw(" sp_re_pat_" + i.to_s + " = re_compile(\"" + cpat + "\", " + pat.length.to_s + ", " + flags + ");") # Byte count, not character count — `re_compile` reads `pat` # as a byte buffer, and a UTF-8 char class (`[₀₁₂…]`) has # `pat.length < pat.bytesize`. Truncating to char count cuts # off a multi-byte char mid-sequence and the engine reports # "unterminated character class". Issue #61. emit_raw(" sp_re_pat_" + i.to_s + " = re_compile(\"" + cpat + "\", " + pat.bytesize.to_s + ", " + flags + ");") i = i + 1 end emit_raw("}")test/regex_utf8_pattern_compiles.rbaddedView file
Loading diff…