Skip to content

Lua: polyglot segmentation splits a function when a [[ ]] long string contains embedded HTML/CSS/JS #2440

Closed

Description

@squid-protocol

Summary

detector.py's mid-file language-switching / segmentation runs on text where Lua long-bracket
string literals ([[ ... ]] / [=[ ... ]=]) are not shielded, so a Write([[<!doctype html> ... <style> body { ... } </style> ... ]]) call inside a Lua function gets carved into its own
embedded html/css segment. That segment boundary falls inside the enclosing Lua function,
so _slice_by_keywords receives a segment that starts mid-function and emits a
<name>_[Truncated] satellite plus a spurious second __global_context__.

Repro

language-crucible/data/lua/cosmopolitan/fetch.lua (and binarytrees.lua, events.lua,
maxmind.lua — all redbean demos that build an HTML page from a [[ ]] heredoc-style string):

local function WriteForm(url)
   Write([[<!doctype html>
     <style> body { padding: 1em; } ... </style>
     <form action="fetch.lua" method="post"> ... </form>
   ]] % {EscapeHtml(url)})
end

function_data for fetch.lua:

    3  WriteForm_[Truncated]      <- real span is 3..33
   16  __global_context__          <- spurious: this is line 16 of WriteForm's HTML string
   22  as
   35  main

At the _slice_by_keywords level the file is now clean (verified: after the 2026-08-29 literal-
shield fix the Lua keyword balance for fetch.lua is perfectly zero and WriteForm opens at 3 /
closes at 33). The truncation is introduced upstream, by segmentation seeing the unshielded
[[ ]] HTML.

Fix direction

Either (a) prism.py shields Lua long-bracket literals before the polyglot/segment detector
runs, or (b) the segment detector treats a [[ ... ]] span as opaque for Lua the same way it
already respects string boundaries for other languages. (a) is consistent with how string
shielding already protects the rest of the pipeline.

Impact

Accounts for the residual _[Truncated] satellites in
lua/function/existence/agree[gitgalaxy]_vs[ctags,tree_sitter] and part of the recall gap in
lua/function/existence/agree[ctags,tree_sitter]_vs[gitgalaxy] (binarytrees.lua:WriteForm).
Distinct mechanism from #2437 (that one is a true keyword-count desync; this one is segmentation).

Found by

tri-comparison-ledger-sweep (lua), 2026-08-29.

Activity

  1. added
    bug
    core-engine
    on Aug 29, 2026
  2. added this to the v2.4.9 milestone on Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcore-engine

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions