authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-01-23 03:32:49 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-01-23 03:32:49 -08:00
log7bd9b75b2cc7ca58cfcd543ad912790c6c8678eb
treef68932f4058a5868873e9a3ac45313ec64b55163
parent8dbaebfd79b25b8f59072dae69122bb9d05e2550

populate host field


3 files changed, 10 insertions(+), 7 deletions(-)

generate.ts+2-2
......@@ -52,7 +52,7 @@ pub fn parsePass(input: []const u8, base: ?[]const u8, href: []const u8, origin:
5252 try expect(u.password).toEqualString(password);
5353 try expect(u.hostname).toEqualString(hostname);
5454 try expect(u.port).toEqualString(port);
55 _ = host;
55 try expect(u.host).toEqualString(host);
5656 _ = origin;
5757 _ = pathname;
5858 try expect(u.search).toEqualString(search);
......@@ -75,7 +75,7 @@ pub fn parseIDNAPass(comptime input: []const u8, comptime output: []const u8) !v
7575 const u = try url.URL.parse(allocator, "https://" ++ input ++ "/x", null);
7676 defer allocator.free(u.href);
7777 try expect(u.hostname).toEqualString(output);
78 // assert_equals(url.host, idnaTest.output);
78 try expect(u.host).toEqualString(output);
7979 // assert_equals(url.pathname, "/x");
8080 // assert_equals(url.href, 'https://{idnaTest.output}/x');
8181}
url.zig+6-3
......@@ -13,6 +13,7 @@ pub const URL = struct {
1313 hostname: []const u8,
1414 hostname_kind: HostKind = .name,
1515 port: []const u8,
16 host: []const u8,
1617 search: []const u8,
1718 hash: []const u8,
1819
......@@ -399,6 +400,7 @@ pub const URL = struct {
399400 hostname_kind = h;
400401 buffer.clearRetainingCapacity();
401402 state = .port;
403 try href.set(8, ":");
402404 }
403405 // 3. Otherwise, if one of the following is true:
404406 // - c is the EOF code point, U+002F (/), U+003F (?), or U+0023 (#)
......@@ -800,11 +802,12 @@ pub const URL = struct {
800802 const url: URL = .{
801803 .href = _href,
802804 .protocol = _href[0..extras.sum(usize, href.lengths[0..2])],
803 .username = _href[extras.sum(usize, href.lengths[0..2])..][0..href.lengths[3]],
804 .password = _href[extras.sum(usize, href.lengths[0..4])..][0..href.lengths[5]],
805 .username = _href[extras.sum(usize, href.lengths[0..3])..][0..href.lengths[3]],
806 .password = _href[extras.sum(usize, href.lengths[0..5])..][0..href.lengths[5]],
805807 .hostname = _href[extras.sum(usize, href.lengths[0..7])..][0..href.lengths[7]],
806808 .hostname_kind = hostname_kind,
807 .port = _href[extras.sum(usize, href.lengths[0..8])..][0..href.lengths[9]],
809 .port = _href[extras.sum(usize, href.lengths[0..9])..][0..href.lengths[9]],
810 .host = _href[extras.sum(usize, href.lengths[0..7])..][0..extras.sum(usize, href.lengths[7..][0..if (href.lengths[9] == 0) 1 else 3])],
808811 .search = if (href.lengths[12] == 0) "" else _href[extras.sum(usize, href.lengths[0..11])..][0..extras.sum(usize, href.lengths[11..][0..2])],
809812 .hash = if (href.lengths[14] == 0) "" else _href[extras.sum(usize, href.lengths[0..13])..][0..extras.sum(usize, href.lengths[13..][0..2])],
810813 };
zig-out/test.zig+2-2
......@@ -22,7 +22,7 @@ pub fn parsePass(input: []const u8, base: ?[]const u8, href: []const u8, origin:
2222 try expect(u.password).toEqualString(password);
2323 try expect(u.hostname).toEqualString(hostname);
2424 try expect(u.port).toEqualString(port);
25 _ = host;
25 try expect(u.host).toEqualString(host);
2626 _ = origin;
2727 _ = pathname;
2828 try expect(u.search).toEqualString(search);
......@@ -45,7 +45,7 @@ pub fn parseIDNAPass(comptime input: []const u8, comptime output: []const u8) !v
4545 const u = try url.URL.parse(allocator, "https://" ++ input ++ "/x", null);
4646 defer allocator.free(u.href);
4747 try expect(u.hostname).toEqualString(output);
48 // assert_equals(url.host, idnaTest.output);
48 try expect(u.host).toEqualString(output);
4949 // assert_equals(url.pathname, "/x");
5050 // assert_equals(url.href, 'https://{idnaTest.output}/x');
5151}