From 2d1d8f7da877c6d71a30820361d38949164de1fc Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Thu, 22 Jan 2026 18:56:08 -0800 Subject: [PATCH] populate search field --- generate.ts | 2 +- url.zig | 7 +++++++ zig-out/test.zig | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/generate.ts b/generate.ts index 7447f877bcbda19614f284aeb16225c36519b5bd..b1d4b7dc2da23806e46be3aff31a71419740aa7f 100644 --- a/generate.ts +++ b/generate.ts @@ -56,7 +56,7 @@ pub fn parsePass(input: []const u8, base: ?[]const u8, href: []const u8, origin: _ = hostname; try expect(u.port).toEqualString(port); _ = pathname; - _ = search; + try expect(u.search).toEqualString(search); _ = hash; } diff --git a/url.zig b/url.zig index f483a6e9b2e9cc56d40b3c70873ca4f98f6f63cb..f79b485ef80025526eda2adedb2b210f80e9ef61 100644 --- a/url.zig +++ b/url.zig @@ -11,6 +11,7 @@ pub const URL = struct { username: []const u8, password: []const u8, port: []const u8, + search: []const u8, pub const HostKind = enum { name, @@ -248,6 +249,7 @@ pub const URL = struct { if (c == '?') { href.clear(12); state = .query; + try href.appendSlice(11, &.{c}); } // 3. Otherwise, if c is U+0023 (#), set url’s fragment to the empty string and state to fragment state. else if (c == '#') { @@ -484,6 +486,7 @@ pub const URL = struct { if (c == '?') { href.clear(12); state = .query; + try href.appendSlice(11, &.{c}); } // 3. Otherwise, if c is U+0023 (#), set url’s fragment to the empty string and state to fragment state. else if (c == '#') { @@ -603,6 +606,7 @@ pub const URL = struct { else if (state_override == null and c == '?') { href.clear(12); state = .query; + try href.appendSlice(11, &.{c}); } // 3. Otherwise, if state override is not given and c is U+0023 (#), set url’s fragment to the empty string and state to fragment state. else if (state_override == null and c == '#') { @@ -661,6 +665,7 @@ pub const URL = struct { if (c == '?') { href.clear(12); state = .query; + try href.appendSlice(11, &.{c}); } // 7. If c is U+0023 (#), then set url’s fragment to the empty string and state to fragment state. if (c == '#') { @@ -689,6 +694,7 @@ pub const URL = struct { if (c == '?') { href.clear(12); state = .query; + try href.appendSlice(11, &.{c}); } // 2. Otherwise, if c is U+0023 (#), then set url’s fragment to the empty string and state to fragment state. else if (c == '#') { @@ -785,6 +791,7 @@ pub const URL = struct { .username = _href[extras.sum(usize, href.lengths[0..2])..][0..href.lengths[3]], .password = _href[extras.sum(usize, href.lengths[0..4])..][0..href.lengths[5]], .port = _href[extras.sum(usize, href.lengths[0..8])..][0..href.lengths[9]], + .search = if (href.lengths[12] == 0) "" else _href[extras.sum(usize, href.lengths[0..11])..][0..extras.sum(usize, href.lengths[11..][0..2])], }; return url; } diff --git a/zig-out/test.zig b/zig-out/test.zig index 5494cb956ef8efd3b9f25e27e930dc5bd38e5690..57c5bb85091d2d441517ce6b6dcc938850e33c20 100644 --- a/zig-out/test.zig +++ b/zig-out/test.zig @@ -26,7 +26,7 @@ pub fn parsePass(input: []const u8, base: ?[]const u8, href: []const u8, origin: _ = hostname; try expect(u.port).toEqualString(port); _ = pathname; - _ = search; + try expect(u.search).toEqualString(search); _ = hash; } -- 2.54.0