Skip to content

fix(util): resolvePath returns empty string when navigating above root#3957

Open
JSap0914 wants to merge 1 commit into
vuejs:devfrom
JSap0914:fix/resolve-path-never-returns-empty-string
Open

fix(util): resolvePath returns empty string when navigating above root#3957
JSap0914 wants to merge 1 commit into
vuejs:devfrom
JSap0914:fix/resolve-path-never-returns-empty-string

Conversation

@JSap0914

Copy link
Copy Markdown

Bug

resolvePath in src/util/path.js returns an empty string '' when a relative path resolves to or above the root.

Reproduction:

resolvePath('..', '/')   // returns '' instead of '/'
resolvePath('..', '/a')  // returns '' instead of '/'

Root cause: When .. segments pop all entries off the internal stack, stack.join('/') on a single-element ['']\ array produces ''. The correct result per POSIX semantics (and common sense) is '/'` — navigating above root should clamp to root.

Fix

One-character change in src/util/path.js:

-  return stack.join('/')
+  return stack.join('/') || '/'

This has no effect on any path that correctly resolves to a non-empty string.

Verification

npm run test:unit
# 116 specs, 0 failures

Three new assertions added in test/unit/specs/path.spec.js — all red before the fix, all green after.

AI-assisted: this PR was prepared with the help of an AI coding assistant.

When a relative path resolves to above the root (e.g. resolvePath('..', '/')),
the stack becomes empty and stack.join('/') produces an empty string ''.
An empty path is invalid for URL routing and differs from POSIX behavior
where navigating above root stays at '/'.

Fix by falling back to '/' when the joined result is empty.

Fixes: resolvePath('..', '/') returning '' instead of '/'
Copilot AI review requested due to automatic review settings June 17, 2026 19:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@netlify

netlify Bot commented Jun 17, 2026

Copy link
Copy Markdown

Deploy Preview for vue-router-docs-v3 canceled.

Name Link
🔨 Latest commit 413eb3b
🔍 Latest deploy log https://app.netlify.com/projects/vue-router-docs-v3/deploys/6a32f0332ce9030008e4153b

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