mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-30 07:31:47 +00:00
anchor: implement set_host
This commit is contained in:
@@ -231,11 +231,32 @@ pub const HTMLAnchorElement = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_host(self: *parser.Anchor, alloc: std.mem.Allocator, v: []const u8) !void {
|
pub fn set_host(self: *parser.Anchor, alloc: std.mem.Allocator, v: []const u8) !void {
|
||||||
_ = self;
|
// search : separator
|
||||||
_ = alloc;
|
var p: ?u16 = null;
|
||||||
_ = v;
|
var h: []const u8 = undefined;
|
||||||
// TODO
|
for (v, 0..) |c, i| {
|
||||||
return error.NotImplemented;
|
if (c == ':') {
|
||||||
|
h = v[0..i];
|
||||||
|
p = try std.fmt.parseInt(u16, v[i + 1 ..], 10);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var u = try url(self, alloc);
|
||||||
|
defer u.deinit(alloc);
|
||||||
|
|
||||||
|
if (p) |pp| {
|
||||||
|
u.uri.host = h;
|
||||||
|
u.uri.port = pp;
|
||||||
|
} else {
|
||||||
|
u.uri.host = v;
|
||||||
|
u.uri.port = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const href = try u.format(alloc);
|
||||||
|
defer alloc.free(href);
|
||||||
|
|
||||||
|
try parser.anchorSetHref(self, href);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO return a disposable string
|
// TODO return a disposable string
|
||||||
@@ -855,6 +876,16 @@ pub fn testExecFn(
|
|||||||
|
|
||||||
.{ .src = "a.origin", .ex = "https://lightpanda.io" },
|
.{ .src = "a.origin", .ex = "https://lightpanda.io" },
|
||||||
|
|
||||||
|
.{ .src = "a.host = 'lightpanda.io:443'", .ex = "lightpanda.io:443" },
|
||||||
|
.{ .src = "a.host", .ex = "lightpanda.io:443" },
|
||||||
|
.{ .src = "a.port", .ex = "443" },
|
||||||
|
.{ .src = "a.hostname", .ex = "lightpanda.io" },
|
||||||
|
|
||||||
|
.{ .src = "a.host = 'lightpanda.io'", .ex = "lightpanda.io" },
|
||||||
|
.{ .src = "a.host", .ex = "lightpanda.io" },
|
||||||
|
.{ .src = "a.port", .ex = "" },
|
||||||
|
.{ .src = "a.hostname", .ex = "lightpanda.io" },
|
||||||
|
|
||||||
.{ .src = "a.host", .ex = "lightpanda.io" },
|
.{ .src = "a.host", .ex = "lightpanda.io" },
|
||||||
.{ .src = "a.hostname", .ex = "lightpanda.io" },
|
.{ .src = "a.hostname", .ex = "lightpanda.io" },
|
||||||
.{ .src = "a.hostname = 'foo.bar'", .ex = "foo.bar" },
|
.{ .src = "a.hostname = 'foo.bar'", .ex = "foo.bar" },
|
||||||
|
|||||||
Reference in New Issue
Block a user