Skip to content

fix(router): keep raw query values that are not valid percent-encoding - #2864

Closed
goranai wants to merge 1 commit into
docsifyjs:developfrom
goranai:fix/parsequery-malformed-percent
Closed

goranai wants to merge 1 commit into
docsifyjs:developfrom
goranai:fix/parsequery-malformed-percent

Conversation

@goranai

@goranai goranai commented Nov 16, 2026

Copy link
Copy Markdown

Summary

Fixes #2863.

parseQuery() calls decodeURIComponent() on each query value. A value with a stray %, such as ?ref=100%, makes it throw URIError: URI malformed. This runs from the router's parse(), so the error happens on route change and inside toURL(). A markdown link like [Sale](guide?ref=100%) then breaks the render of the whole page.

This adds a small safeDecode() helper in src/core/router/util.js. It returns the decoded value, or the raw text when decoding throws. The search plugin already uses the same pattern (#2767).

Behavior changes

  • A value that used to throw is now returned as raw text. ?x=100% gives { x: '100%' }.
  • Values that decoded before are unchanged. In a 50,016-case differential fuzz against the current code, no valid value changed and no new error was added.
  • Fallback is per value and all-or-nothing. If a value mixes a valid escape with a bad one, such as a%20b%, the whole value is kept raw (a%20b%), not partly decoded.
  • Keys are not decoded today, and this PR does not change that.
  • For a markdown link, [Sale](guide?ref=100%) now renders as #/guide?ref=100%25, because stringifyQuery() re-encodes the raw value.

Tests

  • Added two unit tests for parseQuery() in test/unit/router-util.test.js. The malformed test fails on develop with URIError: URI malformed and passes with the fix.
  • Local run on Windows, Node 24.19.0:
    • npm run lint: passed.
    • npx tsc --noEmit: passed.
    • npm run test:unit -- --ci --runInBand: 7 suites, 56 tests passed.
    • npm run test:integration -- --ci --runInBand: 9 suites, 79 tests passed.
    • e2e (Playwright) was not run here.

Note

#2811 changes the line just above (split('=')) in parseQuery() and adds a parseQuery() test block in the same spot. The two changes do not clash in behavior, but one of them will need a small rebase after the other is merged. I'm happy to rebase this one.

Validated with Claude Opus 5.5.

@vercel

vercel Bot commented Nov 16, 2026

Copy link
Copy Markdown

@goranai is attempting to deploy a commit to the Docsify Team on Vercel.

A member of the Team first needs to authorize it.

@sy-records sy-records closed this Nov 17, 2026
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.

A literal % in a route query or a markdown link query throws URIError and the page does not render

2 participants