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

Skip to content

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

Merged
kiran-brahma merged 2 commits into
v1.3from
v1.3-47
Sep 26, 2026
Merged

kiran-brahma merged 2 commits into
v1.3from
v1.3-47

Conversation

@kiran-brahma
@kiran-brahma kiran-brahma commented Sep 26, 2026 •
Copy link
Copy Markdown
Owner

Closes #47.

canonicalText now writes an href raw only when its parentheses balance and it contains no backslash. A left-to-right scan decides balance: the count must never go negative and must end at zero. Any other href gets a backslash before each \, ( and ). parseLink unescapes \\, \( and \), and a backslash before anything else stays literal. So [x](https://e.com/a\)) reads back as the href https://e.com/a), not as a shorter link followed by a stray ) text node.

  • An href with an unbalanced ) or (, or with a backslash, round-trips at the tree level: parseCanonical(canonicalText(tree)) equals tree. The test is in src/core/canonicalText.test.ts, and it failed before the fix.
  • A balanced href is written byte-for-byte as before. [x](https://en.wikipedia.org/wiki/Obelus_(sign)) comes out with no backslashes, and a test checks this.
  • The canonical string round-trip still holds: canonicalText(parseCanonical(t)) === canonicalText(t).
  • This closes the fuzz gap the issue names. A new 5,000-case fuzz builds links with hrefs made from \ ( ) [ ] * \ a / .` and checks both round-trips. It also failed before the fix.
  • pnpm test (1000 passed), pnpm typecheck, pnpm run gates and pnpm build all pass.
  • Not verifiable here: this is a core serialisation fix with nothing to see in the UI, so no browser check was run.

Judgement call: hrefs that balance and contain no backslash stay raw so that canonical strings for existing Documents do not move. Anchors store quotes and offsets over that string, so escaping every parenthesis would have Orphaned Findings whose quotes span links like Obelus_(sign). This follows the Writer's preference in #51. Only hrefs that were already broken, or that contain a backslash, change their canonical string.

🤖 Generated with Claude Code

canonicalText emitted an href unescaped, so an href with an unbalanced `)`
re-parsed as a shorter link plus a stray `)`. Backslash-escape `\`, `(` and
`)` in an emitted href and unescape them in parseLink. A new fuzz builds
links with adversarial hrefs and asserts the tree survives the round-trip.

Closes #47.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FjB3Gu8vhg5enkAneTdqga
@chatgpt-codex-connector
chatgpt-codex-connector Bot commented Sep 26, 2026 •
Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-09-26T09:34:26.332236Z a52dd43 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Escape `\`, `(` and `)` in an href only when its parentheses do not balance
or it holds a backslash, so a Document with a link such as `Obelus_(sign)`
keeps the same canonical string, and its Anchors, after upgrade. Move
isHrefEscapable off isEscapable's doc comment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FjB3Gu8vhg5enkAneTdqga
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.

2 participants

0