G
YouTube TikTok Games
Skip to content

fix(statechart): keep CDATA comments out of the XML markup - #1222

Open
denis-trofimov wants to merge 1 commit into
cursor:mainfrom
denis-trofimov:fix/statechart-cdata-comments
Open

denis-trofimov wants to merge 1 commit into
cursor:mainfrom
denis-trofimov:fix/statechart-cdata-comments

Conversation

@denis-trofimov

Copy link
Copy Markdown

Problem

statechart crashes on any spec whose SANY XML export contains a comment with TLA+ sequence syntax:

Cannot read properties of undefined (reading 'tag')

SANY's XMLExporter wraps comments in <![CDATA[...]]>. parseXml scans the raw XML with a tag regex, so the << / >> inside a CDATA comment (for example <<1, 2>>, as in Sequences.tla) are read as markup. The scanner pops the tag stack on a > it should not have seen, and the next element is attached to an undefined parent.

Reproduced with a spec that extends Sequences and has any comment containing <<...>>.

Fix

parseXml escapes CDATA bodies — and only them — before scanning, so their contents stay text. Comments keep their text; markup outside CDATA is untouched.

Test

test/spec.test.ts feeds readSany an export whose pre-comments contain (* x > y, then <<1, 2>> and a < b. *) and asserts the variable is still read.

npm test in pstack/skills/statechart/scripts: the new test passes. test/render.test.ts fails both on this branch and on main without the change — pre-existing, unrelated.

SANY's XMLExporter wraps TLA+ comments in <![CDATA[...]]>. parseXml scanned the
raw XML, so a comment containing TLA+ sequence syntax (<<1, 2>>, as in
Sequences.tla) desynced the tag stack and the statechart crashed with
"Cannot read properties of undefined (reading 'tag')".

Escape the CDATA bodies before scanning, and cover it with a test.
@denis-trofimov

denis-trofimov commented Nov 13, 2026 •

Copy link
Copy Markdown
Author

Hey thanks for skill! @poteto
I watched your podcast with Matt and decided to give a try to your verification approach.
This code I generateded with my deepseek/deepseek-v4.1-flash-1017 • ● high cause I do mostly go/py/php/c++ and know JS very little.

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