Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fair-scissors-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: better handling of data: and about: protocols
5 changes: 5 additions & 0 deletions packages/kit/src/runtime/client/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ export function create_updated_store() {
* @param {boolean} hash_routing
*/
export function is_external_url(url, base, hash_routing) {
//about: and data: protocols are always internal urls
if (url.protocol === 'about:' || url.protocol === 'data:') {
return false;
}

if (url.origin !== origin || !url.pathname.startsWith(base)) {
return true;
}
Expand Down
5 changes: 3 additions & 2 deletions packages/kit/src/runtime/server/page/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,15 @@ export async function render_response({
base = segments.map(() => '..').join('/') || '.';

// resolve e.g. '../..' against current location, then remove trailing slash
base_expression = `new URL(${s(base)}, location).pathname.slice(0, -1)`;
base_expression = `location.protocol === 'about:' || location.protocol === 'data:' ? new URL('#', location) : new URL(${s(base)}, location).pathname.slice(0, -1)`;

if (!paths.assets || (paths.assets[0] === '/' && paths.assets !== SVELTE_KIT_ASSETS)) {
assets = base;
}
} else if (options.hash_routing) {
// we have to assume that we're in the right place
base_expression = "new URL('.', location).pathname.slice(0, -1)";
base_expression =
"location.protocol === 'about:' || location.protocol === 'data:' ? new URL('#', location) : new URL('.', location).pathname.slice(0, -1)";
}
}

Expand Down
Loading