8000 A link href with an unbalanced parenthesis breaks the Markdown round-trip · Issue #47 · kiran-brahma/writing-tool · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

A link href with an unbalanced parenthesis breaks the Markdown round-trip #47

Closed

Description

@kiran-brahma

What

A link whose href contains an unbalanced ) breaks the canonical round-trip contract.

  • src/core/canonicalText.ts — renderText emits [label](href) with the href unescaped.
  • src/core/parseCanonical.ts:338-371 — parseLink closes the href on the first ) that balances.

A Paragraph containing [x](https://e.com/a)) re-parses as link https://e.com/a plus a stray )
text node, and re-serialising produces [x](https://e.com/a)) again — so
canonicalText(parseCanonical(t)) !== canonicalText(t).

Impact

Narrow but real: a Document imported from Markdown that happens to contain such a URL is silently
changed on import, and a later export writes a different string than the Writer's source. The
canonical string is what model Passes and Anchors see, so it must be a faithful round-trip.

Fix

Percent-encode or backslash-escape ( and ) in an emitted href (and unescape in parseLink), or
use a delimiter that cannot appear in an href.

Why the fuzz test misses it

src/core/canonicalText.test.ts's adversarial fuzz only builds Paragraphs of plain text — it never
emits a link — so the round-trip invariant is only checked for the cases the renderer already
handles.

Origin

Found by the Thermos review (thermo-nuclear, core/wire).

Activity

  1. added a commit that references this issue on Sep 26, 2026
    bc3973f
  2. kiran-brahma commented on Sep 26, 2026

    @kiran-brahma
    OwnerAuthor

    Fixed in #71 (merged into v1.3). An href is written raw when its parentheses balance and it has no backslash, so existing canonical strings (and the Anchors over them) do not move; otherwise \, ( and ) are backslash-escaped and unescaped on parse. A link-building fuzz now covers the round-trip.

    Note: an href containing a backslash (e.g. C:\path) is now escaped, so such a Document's canonical string moves once.


    Generated by Claude Code

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

    bugSomething isn't workingready-for-agentSpec is ready for an agent to implement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0