mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 07:03:29 +00:00
url: add origin getter
This commit is contained in:
@@ -71,6 +71,21 @@ pub const URL = struct {
|
|||||||
alloc.free(self.rawuri);
|
alloc.free(self.rawuri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_origin(self: *URL, alloc: std.mem.Allocator) ![]const u8 {
|
||||||
|
var buf = std.ArrayList(u8).init(alloc);
|
||||||
|
defer buf.deinit();
|
||||||
|
|
||||||
|
try self.uri.writeToStream(.{
|
||||||
|
.scheme = true,
|
||||||
|
.authentication = false,
|
||||||
|
.authority = true,
|
||||||
|
.path = false,
|
||||||
|
.query = false,
|
||||||
|
.fragment = false,
|
||||||
|
}, buf.writer());
|
||||||
|
return try buf.toOwnedSlice();
|
||||||
|
}
|
||||||
|
|
||||||
// the caller must free the returned string.
|
// the caller must free the returned string.
|
||||||
// TODO return a disposable string
|
// TODO return a disposable string
|
||||||
// https://github.com/lightpanda-io/jsruntime-lib/issues/195
|
// https://github.com/lightpanda-io/jsruntime-lib/issues/195
|
||||||
@@ -223,6 +238,7 @@ pub fn testExecFn(
|
|||||||
) anyerror!void {
|
) anyerror!void {
|
||||||
var url = [_]Case{
|
var url = [_]Case{
|
||||||
.{ .src = "var url = new URL('https://foo.bar/path?query#fragment')", .ex = "undefined" },
|
.{ .src = "var url = new URL('https://foo.bar/path?query#fragment')", .ex = "undefined" },
|
||||||
|
.{ .src = "url.origin", .ex = "https://foo.bar" },
|
||||||
.{ .src = "url.href", .ex = "https://foo.bar/path?query#fragment" },
|
.{ .src = "url.href", .ex = "https://foo.bar/path?query#fragment" },
|
||||||
.{ .src = "url.protocol", .ex = "https:" },
|
.{ .src = "url.protocol", .ex = "https:" },
|
||||||
.{ .src = "url.username", .ex = "" },
|
.{ .src = "url.username", .ex = "" },
|
||||||
|
|||||||
Reference in New Issue
Block a user