[Bug] TUI crashes with URIError in cellMarker when rendering markdown tables #2001
Replies: 2 comments
|
I reproduced this against upstream The public table-selection path still reaches the unconditional I prepared a focused candidate change that replaces only unpaired surrogates with U+FFFD before encoding while preserving valid surrogate pairs. The regression test exercises the public Red/green evidence:
Candidate branch: Candidate commit: I have not opened an upstream PR. If maintainers want this fix, I can add the required TUI changelog fragment and open a focused PR after an explicit invitation, per |
|
Follow-up: I expanded the candidate into a complete fork-local Draft PR for review: The candidate now:
Both regressions were verified red against upstream Fresh validation on the final commit:
The Draft PR targets only the fork's |
Uh oh!
There was an error while loading. Please reload this page.
The TUI crashes with
URIError: URI malformedwhen rendering a markdown table whose cell content contains lone surrogates or characters thatencodeURIComponentcannot handle. The crash kills the entire session with no recovery.Root cause:
cellMarker()callsencodeURIComponent(content)unconditionally on table cell text:(Called from
markTableCell().)Per ECMA-262 §19.2.6.5,
encodeURIComponentmust throwURIErroron lone surrogates (U+D800–U+DFFF). This is not Node.js-specific or platform-specific — it's mandated by the JS spec and applies to every conformant engine (V8, SpiderMonkey, JSC), every Node version, and every OS.Lone surrogates can reach agent-produced strings through several paths:
JSON.parseof strings with escaped lone surrogates (\uD800)TextDecoderwith invalid UTF-8 sequences (non-fatal mode, the default)Steps to reproduce
Minimal reproduction:
Expected behavior
The TUI should gracefully handle any string content in markdown table cells without crashing. A try/catch around
encodeURIComponentwith a fallback that replaces lone surrogates (e.g. with U+FFFD) would prevent the crash without affecting normal table rendering.Environment
Additional context
This crash has occurred multiple times across different sessions. It's not deterministic — it depends on the agent's output containing specific characters in a table cell. A local workaround is to patch
cellMarkerin the dist bundle to wrapencodeURIComponentin try/catch and replace lone surrogates with U+FFFD, but this gets overwritten on everyprime-agent update.All reactions