Skip to content

fix(core): drop NUL-byte separator from the when-clause regex tokenizer - #53

Merged
thorwhalen merged 1 commit into
mainfrom
fix/when-regex-structured-token
Jul 11, 2026
Merged

thorwhalen merged 1 commit into
mainfrom
fix/when-regex-structured-token

Conversation

@thorwhalen

Copy link
Copy Markdown
Member

Why

Surfaced during the v1.14–v1.18 pre-wiring review (#51) via a byte-level scan: packages/core/src/when.ts used a NUL byte (\x00) as the regex pattern | flags separator — the tokenizer joined pattern + <NUL> + flags (was line 180) and the parser split on the same NUL (was line 348).

It was self-consistent (all tests passed), but:

  • The file — and the built dist — were binary to git. No diff, blame, or PR-review rendering for when.ts.
  • It was fragile. The separator is invisible; a maintainer "tidying" it to a space would silently break any regex whose pattern contains a space (/foo bar/ → split(' ') mangles it). That exact case was never tested — it worked only because the separator was a NUL.

What

The regex token now carries pattern and flags as distinct Token fields — no separator at all. This is behavior-identical for every input (the NUL was correctly doing its job; this just removes the fragile packing) and removes the non-printable byte from source and dist.

  • Token gains an optional flags?: string (regex-only).
  • Tokenizer: value: pattern, flags instead of value: pattern + <NUL> + flags.
  • Parser: reads t.value / t.flags instead of t.value.split(<NUL>).
  • New regression test: a regex literal whose pattern contains a space (/foo bar/, /foo bar/i).

Verification

  • when.ts is now valid UTF-8 (0 NUL bytes); built dist verified NUL-free.
  • Core: typecheck clean, 96 tests pass (when.test +1).
  • Full monorepo typecheck + tests green (core is a widespread dependency; nothing downstream changed).

acture core patch bump (changeset included). No public API or runtime-behavior change.

https://claude.ai/code/session_01A1PykLHv2BjQRQhspjvPWy

…izer

The regex-literal token packed `pattern + <NUL> + flags` into one string and
split on that same NUL downstream. Self-consistent (tests passed), but it made
when.ts and the built dist binary to git (no diff/blame rendering) and was
fragile — a naive NUL->space "cleanup" would break any regex pattern containing
a space (e.g. /foo bar/).

Store `pattern` and `flags` as distinct Token fields (no separator at all).
Behavior-identical for every input; adds a regression test for a space-containing
pattern, previously only guarded by the invisible NUL and never tested.

Discovered during the v1.14-v1.18 pre-wiring review (#51). No public API or
runtime-behavior change.

Claude-Session: https://claude.ai/code/session_01A1PykLHv2BjQRQhspjvPWy
@thorwhalen
thorwhalen merged commit a82e071 into main Jul 11, 2026
1 check passed
@thorwhalen
thorwhalen deleted the fix/when-regex-structured-token branch July 11, 2026 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant