Skip to content

fix(lua): shield \z string continuation across newlines (#2437) - #2447

Merged
squid-protocol merged 1 commit into
mainfrom
lua-zescape-shield
Aug 29, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
lua-zescape-shield

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Hardens the last remaining lua repro of #2437.

Root cause

Lua's \z escape skips the following run of whitespace including line breaks, so

(Message or print)('\n >>> testC not active: skipping tests for \z
userdata <<<\n')

is one single-quoted string spanning two physical lines. The lua branch of
_apply_literal_shield bounds its quote patterns by newline (so an unterminated single-line
quote can't swallow the file), so this string never matched — leaking the word for as live
code, which _slice_by_keywords counted as a \bfor\b Mode-D opener with no end. The
if not T then above it then ran to EOF as one Anonymous_Block_[Truncated] satellite
(events.lua).

Fix

Add \z[ \t\r\n]* as an explicit cross-newline alternative to lua's standard_double /
standard_single shield patterns. Plain \<newline> continuation was already covered by \\.
under re.DOTALL; only \z + trailing whitespace needed handling. \z appears in 6 corpus
files (main.lua even has function () \z inside a string) — only events.lua currently
desynced, the rest were latent.

Measured

tree_sitter_accuracy_audit.py --lang lua: extra_functions 1 → 0, function precision
99.8% → 100.0%. found_functions unchanged at 618 (the truncated satellite was never a real
function).

Differential Scan

  • Both golden masters re-blessed — events.lua + main.lua metric shifts (the \z strings are
    now correctly shielded) + topological ripple. crucible_check.py --mode both PASS.
  • Lua baseline regenerated, summary table updated. --all --ci (both audits) OK.
  • Ledger verdicts, chart, points-of-interest regenerated (--all --write).
    docs/language_status/lua.md §9 updated.
  • audit_check.py clean; lua extraction + strict + detector + prism tests pass.

Scope

The issue's other half — a mid-file blast-radius containment heuristic — is deliberately not
built. After this fix there is no remaining corpus repro to validate it against, and fixing
desync sources (6/6 defects across this sweep) has consistently beaten adding containment
backstops. I'd recommend closing #2437.

Two low-value recall misses remain in the ledger (constructs.lua:f occurrence-alignment fuzz on
a 4×-redefined name; literals.lua:lexerror in the Lua suite's lexer-torture fixture) —
documented in §5, not chased.

🤖 Generated with Claude Code

https://claude.ai/code/session_019Zm1uVBpVEZJ9SB7bWFR8S

Lua's `\z` escape skips the following run of whitespace INCLUDING line
breaks, so

  (Message or print)('\n >>> testC not active: skipping tests for \z
  userdata <<<\n')

is one single-quoted string spanning two physical lines. The lua branch
of `_apply_literal_shield` bounds its quote patterns by newline (so an
unterminated single-line quote can't swallow the file), so this string
never matched -- leaking the word `for` as live code, which
`_slice_by_keywords` counted as a `\bfor\b` Mode-D opener with no `end`.
The `if not T then` above it then ran to EOF as one
`Anonymous_Block_[Truncated]` satellite (events.lua).

Fixed by adding `\z[ \t\r\n]*` as an explicit cross-newline alternative
to lua's `standard_double` / `standard_single` shield patterns. Plain
`\<newline>` continuation was already covered by `\\.` under re.DOTALL;
only `\z` + trailing whitespace needed handling. `\z` appears in 6 corpus
files (`main.lua` even has `function () \z` inside a string); only
events.lua currently desynced, the rest were latent.

Measured (`tree_sitter_accuracy_audit.py --lang lua`): extra_functions
1 -> 0, function precision 99.8% -> 100.0%. Both golden masters re-blessed
(events.lua + main.lua metric shifts + topological ripple), lua baseline +
summary table regenerated, ledger verdicts + chart + points-of-interest
regenerated (`--all`), `docs/language_status/lua.md` §9 updated.

This is #2437's last lua repro. The issue's other half -- a mid-file
blast-radius containment heuristic -- is deliberately not built: no
remaining repro to validate it against, and fixing desync sources (6/6
this sweep) has consistently beaten adding containment backstops. Two
low-value recall misses remain in the ledger (`constructs.lua:f`
occurrence-alignment fuzz, `literals.lua:lexerror` in the Lua suite's
lexer-torture fixture), documented not chased.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019Zm1uVBpVEZJ9SB7bWFR8S
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit b46b2dd into main Aug 29, 2026
30 checks passed
@squid-protocol
squid-protocol deleted the lua-zescape-shield branch August 29, 2026 20:32
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