Skip to content

Commit 7bf3cf9

Browse files
committed
Allow scheme-only URLs
new URL('sveltekit-internal://') is valid. Used by amazon.
1 parent 878dbd8 commit 7bf3cf9

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/browser/url/url.zig

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,17 @@ pub const URL = struct {
8989
raw = if (url == .url) url_str else try arena.dupe(u8, url_str);
9090
}
9191

92-
const uri = std.Uri.parse(raw.?) catch return error.TypeError;
92+
const uri = std.Uri.parse(raw.?) catch blk: {
93+
if (!std.mem.endsWith(u8, raw.?, "://")) {
94+
return error.TypeError;
95+
}
96+
// schema only is valid!
97+
break :blk std.Uri{
98+
.scheme = raw.?[0..raw.?.len - 3],
99+
.host = .{.percent_encoded = ""},
100+
};
101+
};
102+
93103
return init(arena, uri);
94104
}
95105

@@ -558,6 +568,14 @@ test "Browser.URL" {
558568
.{ "var url = new URL('over?9000', 'https://lightpanda.io')", null },
559569
.{ "url.href", "https://lightpanda.io/over?9000" },
560570
}, .{});
571+
572+
try runner.testCases(&.{
573+
.{ "let sk = new URL('sveltekit-internal://')", null },
574+
.{ "sk.protocol", "sveltekit-internal:"},
575+
.{ "sk.host", ""},
576+
.{ "sk.hostname", ""},
577+
.{ "sk.href", "sveltekit-internal://"}
578+
}, .{});
561579
}
562580

563581
test "Browser.URLSearchParams" {

0 commit comments

Comments
 (0)