Skip to content

fix(shared): chunked Markdown links keep escaped angle brackets in reference destinations - #43830

Closed
saphid wants to merge 1 commit into
pingdotgg:mainfrom
saphid:hunter/c-410a387a73
Closed

saphid wants to merge 1 commit into
pingdotgg:mainfrom
saphid:hunter/c-410a387a73

Conversation

@saphid

@saphid saphid commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Problem

Large Markdown file previews leave valid reference links literal when their angle-wrapped destination contains an escaped angle bracket. The definition scanner rejects the escape even though the renderer accepts it.

Deterministic repro on origin/main (beb24ffed87bbb45e81dd27c7f253c30e83b2599)

Use this exact synthetic fixture with the default chunk size:

const text = "[guide][ref]\n\n# " + "x".repeat(4100) +
  "\n\n# Appendix\n\n" + String.raw`[ref]: <https://example.com/a\<b>`;
const { chunks, definitions } = splitMarkdown(text);
const first = withMarkdownDefinitions(chunks[0]!.text, definitions);

Render text and first through wordsHast using the existing wordsHtml helper in apps/web/src/markdown/wordsHast.test.ts. The runtime transcript includes the full temporary probe and its command:

vp test run apps/web/src/markdown/wordsHast.test.ts -t 'factory escaped-angle chunk transcript' --silent=false

Observed: two chunks, an empty definitions string, and literal [guide][ref] in the first chunk. Expected: guide links to https://example.com/a%3Cb, matching whole-document rendering. An unescaped inner < is the negative control and must remain unresolved.

Change

Make the angle-destination regex consume backslash escapes as pairs, accepting escaped < and > while rejecting unescaped inner brackets, escaped closing delimiters, and physical line endings. Web/desktop and mobile file previews use this shared scanner; no separate client fix or translation is needed.

Scope

Small fix for an obvious bug; no issue needed under CONTRIBUTING.md.

Verification

  • Added regression coverage in the existing shared test file before editing the implementation. On base, the escaped < and > cases fail because the first chunk has no expected link.
  • vp test run packages/shared/src/markdownChunks.test.ts: 28/28 passed in each of three consecutive runs. Controls cover paired backslashes, unescaped inner brackets, and CR/LF.
  • vp run check:changed: exit 0.
  • Before/after runtime evidence: the actual first chunk through wordsHast changes from literal text to the expected link; whole-document output and the invalid control stay consistent.
  • Not shown: browser screenshots or an integrated app session; desktop shell/IPC; native mobile rendering; provider turns; remote/relay/tunnel connections. This patch changes shared parsing only, with no layout, transport, or provider changes.

Authored by GPT-6.1 Sol (Codex); reviewed by Gemini 4 Neon (Antigravity).

@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Nov 26, 2026
@coderabbitai

coderabbitai Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The link definition pattern now accepts escaped characters in angle-bracket destinations and excludes carriage returns. Tests cover escaped characters, invalid destinations, and reference resolution across chunks.

Changes: Markdown definition parsing

Layer / File(s) Summary
Angle-bracket destination parsing
packages/shared/src/markdownChunks.ts, packages/shared/src/markdownChunks.test.ts
The link definition pattern accepts escaped characters other than line breaks and excludes carriage returns in angle-bracket destinations. Tests check valid escaped characters, invalid destinations, reference resolution, and reconstructed chunk text.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested labels: bugfix

Suggested reviewers: only21mil, macroscopeapp, marve10s

Merge Risk: Minimal · up to 92bea

This change fixes large Markdown previews leaving valid reference links as literal text when the destination contains an escaped angle bracket. The change is narrow and covered by targeted tests. No material merge risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the change: chunked Markdown links keep escaped angle brackets in reference destinations. The raw summary confirms that LINK_DEFINITION now accepts backslash-escaped characters in angl…
Description check Passed The description covers every template section: Problem, Change, Scope, and Verification. It gives a deterministic reproduction, names the changed behavior, explains why no issue is needed for a small …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the change: chunked Markdown links keep escaped angle brackets in reference destinations. The raw summary confirms that LINK_DEFINITION now accepts backslash-escaped characters in angle-bracket destinations and that tests cover escaped angle brackets across chunks. The title follows the conventional commit format and is specific to the primary fix.

Full details: Description check

Explanation

The description covers every template section: Problem, Change, Scope, and Verification. It gives a deterministic reproduction, names the changed behavior, explains why no issue is needed for a small obvious bug, and lists focused test results with counts and the commands run. It also states what was not checked, which the template requests. The template's optional agent-attribution line is present. The description links an external gist for runtime evidence, and the summary indicates no UI change, so screenshots are not required.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 59e80b7 and 92beaaa.

Files selected for processing: 2

  • packages/shared/src/markdownChunks.test.ts
  • packages/shared/src/markdownChunks.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

@juliusmarminge

Copy link
Copy Markdown
Member

Thanks for this. Main already has the change, as of 3ebc46f.

Main now recognizes reference definitions with Remark instead of the restrictive regex this PR changes. That replacement in 3ebc46f867 already accepts escaped angle brackets and preserves the definition for other chunks, while leaving invalid destinations unresolved.

The focused regression cases remain useful coverage for the replacement parser, but the implementation fix is already covered on main.

Closing as superseded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants