Skip to content

fix: URL-encode rule doc link targets - #997

Open
bmish wants to merge 1 commit into
mainfrom
fix/url-encode-links
Open

fix: URL-encode rule doc link targets#997
bmish wants to merge 1 commit into
mainfrom
fix/url-encode-links

Conversation

@bmish

@bmish bmish commented Jul 19, 2026

Copy link
Copy Markdown
Member

Summary

  • URL-encode each path segment in generated relative rule-doc links (pathToUrl), including characters encodeURIComponent leaves alone that break CommonMark destinations ((, ), !)
  • Encode only the substituted {name} portion of string --url-rule-doc templates; leave the template itself untouched
  • Encode relative urlRuleDoc function return values; leave absolute URLs (://) as-is so callers own encoding

Test plan

  • npm run lint
  • npm test
  • New fixtures with rule name/path no foo (bar) assert exact %20 / %28 / %29 in snapshots for relative links, string templates, and relative function returns
  • Absolute function return with pre-encoded URL is not double-encoded

Made with Cursor

Context

From the post-#987 standards audit: pathToUrl handled Windows separator conversion but never URL-encoded, so a rule doc path containing a space or parenthesis produced a broken link — CommonMark terminates a plain link destination at whitespace or an unbalanced ). (, ), and ! also pass through encodeURIComponent untouched, hence the explicit replacements.

Scope guard: only tool-generated relative paths and the substituted {name} portion are encoded; user-supplied absolute URLs and template text are left to the caller, so nothing pre-encoded gets double-encoded.

Encode path segments and urlRuleDoc name substitutions so spaces,
parentheses, and similar characters do not break CommonMark links.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

1 participant