-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
breaking: fix path resolution #11276
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sveltejs/kit': major | ||
--- | ||
|
||
breaking: fix path resolution |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"hrefs": ["/#encöded"], | ||
"hrefs": ["/#enc%C3%B6ded"], | ||
"ids": ["before", "after", "encöded"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"hrefs": ["/styles.css", "/favicon.png", "https://external.com"], | ||
"hrefs": ["/styles.css", "/favicon.png", "https://external.com/"], | ||
"ids": [] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
{ | ||
"hrefs": ["https://external.com", "/og-image.jpg", "https://example.com/audio.mp3", "/video.mp4"], | ||
"hrefs": [ | ||
"https://external.com/", | ||
"/og-image.jpg", | ||
"https://example.com/audio.mp3", | ||
"/video.mp4" | ||
], | ||
"ids": [] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"hrefs": ["/styles.css", "/favicon.png", "https://external.com", "/wheee"], | ||
"hrefs": ["/styles.css", "/favicon.png", "https://external.com/", "/wheee"], | ||
"ids": [] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,39 +6,20 @@ import { BROWSER } from 'esm-env'; | |
*/ | ||
export const SCHEME = /^[a-z][a-z\d+\-.]+:/i; | ||
|
||
const absolute = /^([a-z]+:)?\/?\//; | ||
const internal = new URL('sveltekit-internal://'); | ||
|
||
/** | ||
* @param {string} base | ||
* @param {string} path | ||
*/ | ||
export function resolve(base, path) { | ||
if (SCHEME.test(path)) return path; | ||
if (path[0] === '#') return base + path; | ||
if (path === '') return base; | ||
// special case | ||
if (path[0] === '/' && path[1] === '/') return path; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's this special case about? Is this some extra thing we need to mention in the docs? What does this mean for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. protocol-relative URLs should remain protocol-relative, but the |
||
|
||
const base_match = absolute.exec(base); | ||
const path_match = absolute.exec(path); | ||
let url = new URL(base, internal); | ||
url = new URL(path, url); | ||
|
||
if (!base_match) { | ||
throw new Error(`bad base path: "${base}"`); | ||
} | ||
|
||
const baseparts = path_match ? [] : base.slice(base_match[0].length).split('/'); | ||
const pathparts = path_match ? path.slice(path_match[0].length).split('/') : path.split('/'); | ||
|
||
baseparts.pop(); | ||
|
||
for (let i = 0; i < pathparts.length; i += 1) { | ||
const part = pathparts[i]; | ||
if (part === '.') continue; | ||
else if (part === '..') baseparts.pop(); | ||
else baseparts.push(part); | ||
} | ||
|
||
const prefix = (path_match && path_match[0]) || (base_match && base_match[0]) || ''; | ||
|
||
return `${prefix}${baseparts.join('/')}`; | ||
return url.protocol === internal.protocol ? url.pathname + url.search + url.hash : url.href; | ||
} | ||
|
||
/** @param {string} path */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous results had the character references persisted - will this somehow affect other stuff negatively / in a breaking way now that they no longer are?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured if it did, tests would start failing. Seems fine. Though we're probably now double-decoding at prerender time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oof. Double-decoding is bad and would result in breakages. Maybe we don't have a test for prerendering an encoded URL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do:
If there's a bug, it's very well-hidden, and we can fix it when it reveals itself. It shouldn't block merging