Repository navigation
A link href with an unbalanced parenthesis breaks the Markdown round-trip - #71
Merged
Merged
Conversation
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
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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
This was referenced Sep 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #47.
canonicalTextnow 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).parseLinkunescapes\\,\(and\), and a backslash before anything else stays literal. So[x](https://e.com/a\))reads back as the hrefhttps://e.com/a), not as a shorter link followed by a stray)text node.)or(, or with a backslash, round-trips at the tree level:parseCanonical(canonicalText(tree))equalstree. The test is insrc/core/canonicalText.test.ts, and it failed before the fix.[x](https://en.wikipedia.org/wiki/Obelus_(sign))comes out with no backslashes, and a test checks this.canonicalText(parseCanonical(t)) === canonicalText(t).\ ( ) [ ] * \a / .` and checks both round-trips. It also failed before the fix.pnpm test(1000 passed),pnpm typecheck,pnpm run gatesandpnpm buildall pass.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