prime-agent icon indicating copy to clipboard operation
prime-agent copied to clipboard

URIError: URI malformed in cellMarker when rendering markdown tables with special characters

Open vichaunter opened this issue 3 months ago • 1 comments

Description

prime-agent crashes with URIError: URI malformed when rendering a markdown table whose cell content contains lone surrogates or other characters that encodeURIComponent cannot handle.

Stack trace

``` URIError: URI malformed at encodeURIComponent () at cellMarker (chunk-MMG2DX73.js:26349:56) at markTableCell (chunk-MMG2DX73.js:26376:10) at Markdown.renderTable (chunk-MMG2DX73.js:27155:35) at Markdown.renderToken (chunk-MMG2DX73.js:26790:33) at Markdown.renderBlock (chunk-MMG2DX73.js:26647:29) at Markdown.render (chunk-MMG2DX73.js:26616:27) at Container.render (chunk-MMG2DX73.js:18807:32) ```

Root cause

In cellMarker:

```js function cellMarker(kind, row, column, segment2, content) { const encodedContent = content === void 0 ? "" : `:${encodeURIComponent(content)}`; // ... } ```

encodeURIComponent throws on strings with lone surrogates (e.g. U+D800–U+DFFF). Agent output can contain such characters (e.g. binary data snippets, malformed unicode from tool output, certain emoji sequences).

Suggested fix

Wrap in try/catch and sanitize lone surrogates:

```js function cellMarker(kind, row, column, segment2, content) { let encodedContent; if (content === void 0) { encodedContent = ""; } else { try { encodedContent = `:${encodeURIComponent(content)}`; } catch { encodedContent = `:${encodeURIComponent(String(content).replace(/[\uD800-\uDFFF]/g, "\uFFFD"))}`; } } return `${TABLE_MARKER_PREFIX}${kind}:${row}:${column}:${segment2}${encodedContent}\x07`; } ```

Reproduction

  1. Have an agent produce a markdown table with content containing lone surrogates or malformed unicode
  2. The TUI crashes immediately when trying to render it

Version

prime-agent 0.9.1, Node.js v24.11.1

Workaround

Patching the dist bundle directly with the suggested fix above.

vichaunter avatar Sep 02 '26 17:09 vichaunter

Hi @vichaunter, thanks for your interest!

This project requires that issue reporters are vouched, and you are not in the list of vouched users.

This issue will be closed automatically. See https://github.com/PrimeIntellect-ai/prime-agent/blob/main/CONTRIBUTING.md for more details.

github-actions[bot] avatar Sep 02 '26 17:09 github-actions[bot]