fix(unplugin): keep hex character codes in param segments regexp by kwy404 · Pull Request #2811 · vuejs/router · GitHub
Skip to content

fix(unplugin): keep hex character codes in param segments regexp - #2811

Merged
posva merged 1 commit into
vuejs:mainfrom
kwy404:fix/unplugin-char-code-sub-segments
Oct 2, 2026
Merged

posva merged 1 commit into
vuejs:mainfrom
kwy404:fix/unplugin-char-code-sub-segments

Conversation

@kwy404

@kwy404 kwy404 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Root cause

In parseFileSegment(), a [x+HH] character code is appended to pathSegment but never pushed to subSegments. For static segments this does not matter, but param segments build their regexp (TreeNodeValueParam.re) and the experimental resolver path parts (matcherPatternPathDynamicParts) from subSegments, so the decoded character is silently dropped there.

For example [id][x+2E]json.vue gets the correct path :id.json, but its regexp is /^\/([^/]+?)json$/i and its path parts are [[1, 'json']]. With the experimental resolver, /foo.json resolves with id set to foo., /foojson also matches, and building the route with { id: 'foo' } gives /foojson.

Fix

Push the decoded character to subSegments as a static part, next to the existing pathSegment update.

Test

Added a case to the path regexp tests in tree.spec.ts for [id][x+2E]json. It fails before the fix (expected '/^\/([^/]+?)json$/i' to be '/^\/([^/]+?)\.json$/i') and passes after. The rest of the unplugin tests still pass.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed route matching for paths that contain a parameter followed by a hex-encoded character. The decoded character is now matched as part of the literal path, so routes with extensions such as .json are recognized correctly while the parameter remains captured as expected.

@netlify

netlify Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: vuejs/router/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 177305ae-6840-4fa1-9c51-83bf7b3b6a47

📥 Commits

Reviewing files that changed from the base of the PR and between 610644a and 34475ef.

📒 Files selected for processing (2)
  • packages/router/src/unplugin/core/tree.spec.ts
  • packages/router/src/unplugin/core/treeNodeValue.ts

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


📝 Walkthrough

Walkthrough

The parser now adds decoded character codes to subSegments as well as pathSegment. A new regexp test checks the .json suffix and matcher parts for [id][x+2E]json.

Changes

Path segment parsing

Layer / File(s) Summary
Decode character codes and verify regexp parts
packages/router/src/unplugin/core/treeNodeValue.ts, packages/router/src/unplugin/core/tree.spec.ts
Decoded character codes are now added to subSegments. The new test checks that [x+2E] produces a dot after the parameter capture and before json in the matcher parts.

Priority: ➖ Normal

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

Change: Bug fix

Suggested reviewers: posva

Merge Risk: ⚪ Minimal · up to 34475

Hex-encoded suffixes are retained in route matching, and source inspection confirms the parameter capture remains intact. No actionable merge risk was found.

Architecture Summary

Architecture risk: 🔵 Low · up to 34475

The change affects 1 system.

Changed systems: packages/router

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — packages/router (api) was modified; 2 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in packages/router/src/unplugin/core/tree.spec.ts: Added a regexp test for [id][x+2E]json, expecting the hex code to produce a literal .json suffix and matcher parts containing the parameter capture, dot, and json.
  • observed — Modified behavior in packages/router/src/unplugin/core/treeNodeValue.ts: Character codes decoded from [x+HH] now also become a subSegments entry, alongside being appended to pathSegment.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: preserving hex character codes in parameter-segment regular expressions.
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@posva posva left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@pkg-pr-new

pkg-pr-new Bot commented Oct 2, 2026

Copy link
Copy Markdown

Open in StackBlitz

pnpm add https://pkg.pr.new/vue-router@2811
npm i https://pkg.pr.new/vue-router@2811
yarn add https://pkg.pr.new/vue-router@2811.tgz

commit: 34475ef

@codecov

codecov Bot commented Oct 2, 2026

Copy link
Copy Markdown

@posva
posva merged commit 07663eb into vuejs:main Oct 2, 2026
10 checks passed
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