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

@@ -9036,7 +9036,12 @@
90369036 end
90379037 pi = pi + 1
90389038 end
9039- emit_raw(" sp_re_pat_" + i.to_s + " = re_compile(\"" + cpat + "\", " + pat.length.to_s + ", " + flags + ");")
9039+ # Byte count, not character count — `re_compile` reads `pat`
9040+ # as a byte buffer, and a UTF-8 char class (`[₀₁₂…]`) has
9041+ # `pat.length < pat.bytesize`. Truncating to char count cuts
9042+ # off a multi-byte char mid-sequence and the engine reports
9043+ # "unterminated character class". Issue #61.
9044+ emit_raw(" sp_re_pat_" + i.to_s + " = re_compile(\"" + cpat + "\", " + pat.bytesize.to_s + ", " + flags + ");")
90409045 i = i + 1
90419046 end
90429047 emit_raw("}")