fix(util): resolvePath returns empty string when navigating above root#3957
Open
JSap0914 wants to merge 1 commit into
Open
fix(util): resolvePath returns empty string when navigating above root#3957JSap0914 wants to merge 1 commit into
JSap0914 wants to merge 1 commit into
Conversation
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 '/'
✅ Deploy Preview for vue-router-docs-v3 canceled.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
resolvePathinsrc/util/path.jsreturns an empty string''when a relative path resolves to or above the root.Reproduction:
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:This has no effect on any path that correctly resolves to a non-empty string.
Verification
Three new assertions added in
test/unit/specs/path.spec.js— all red before the fix, all green after.