mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 23:23:28 +00:00
Merge pull request #905 from lightpanda-io/scheme_only_url
Allow scheme-only URLs
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);
|
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);
|
return init(arena, uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -558,6 +568,14 @@ test "Browser.URL" {
|
|||||||
.{ "var url = new URL('over?9000', 'https://lightpanda.io')", null },
|
.{ "var url = new URL('over?9000', 'https://lightpanda.io')", null },
|
||||||
.{ "url.href", "https://lightpanda.io/over?9000" },
|
.{ "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" {
|
test "Browser.URLSearchParams" {
|
||||||
|
|||||||
Reference in New Issue
Block a user