mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-28 22:53:28 +00:00
Allow scheme-only URLs
new URL('sveltekit-internal://') is valid. Used by amazon.
This commit is contained in:
@@ -89,7 +89,17 @@ pub const URL = struct {
|
||||
raw = if (url == .url) url_str else try arena.dupe(u8, url_str);
|
||||
}
|
||||
|
||||
const uri = std.Uri.parse(raw.?) catch return error.TypeError;
|
||||
const uri = std.Uri.parse(raw.?) catch blk: {
|
||||
if (!std.mem.endsWith(u8, raw.?, "://")) {
|
||||
return error.TypeError;
|
||||
}
|
||||
// schema only is valid!
|
||||
break :blk std.Uri{
|
||||
.scheme = raw.?[0..raw.?.len - 3],
|
||||
.host = .{.percent_encoded = ""},
|
||||
};
|
||||
};
|
||||
|
||||
return init(arena, uri);
|
||||
}
|
||||
|
||||
@@ -558,6 +568,14 @@ test "Browser.URL" {
|
||||
.{ "var url = new URL('over?9000', 'https://lightpanda.io')", null },
|
||||
.{ "url.href", "https://lightpanda.io/over?9000" },
|
||||
}, .{});
|
||||
|
||||
try runner.testCases(&.{
|
||||
.{ "let sk = new URL('sveltekit-internal://')", null },
|
||||
.{ "sk.protocol", "sveltekit-internal:"},
|
||||
.{ "sk.host", ""},
|
||||
.{ "sk.hostname", ""},
|
||||
.{ "sk.href", "sveltekit-internal://"}
|
||||
}, .{});
|
||||
}
|
||||
|
||||
test "Browser.URLSearchParams" {
|
||||
|
||||
Reference in New Issue
Block a user