authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-02-02 20:01:26 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-02-02 20:01:26 -08:00
log7a92d878ee9739b7c67be09904f332fad1f1fdaa
treed20ae5e58cec3989118fafbd2e1d704cc2ba4bc2
parenta16a1a608262e9881e127922c8f27921c4af8407

free href in fail cases that wronly pass

prevents leak logs in test results

2 files changed, 8 insertions(+), 4 deletions(-)

generate.ts+4-2
...@@ -61,10 +61,11 @@ const E = stringEscape;...@@ -61,10 +61,11 @@ const E = stringEscape;
61w.write(`61w.write(`
62pub fn parseFail(input: []const u8, base: ?[]const u8) !void {62pub fn parseFail(input: []const u8, base: ?[]const u8) !void {
63 const allocator = std.testing.allocator;63 const allocator = std.testing.allocator;
64 _ = url.URL.parse(allocator, input, base) catch |err| switch (err) {64 const u = url.URL.parse(allocator, input, base) catch |err| switch (err) {
65 error.InvalidURL => return,65 error.InvalidURL => return,
66 error.OutOfMemory => return error.OutOfMemory,66 error.OutOfMemory => return error.OutOfMemory,
67 };67 };
68 defer allocator.free(u.href);
68 return error.FailZigTest;69 return error.FailZigTest;
69}70}
7071
...@@ -87,10 +88,11 @@ pub fn parsePass(input: []const u8, base: ?[]const u8, href: []const u8, origin:...@@ -87,10 +88,11 @@ pub fn parsePass(input: []const u8, base: ?[]const u8, href: []const u8, origin:
8788
88pub fn parseIDNAFail(comptime input: []const u8) !void {89pub fn parseIDNAFail(comptime input: []const u8) !void {
89 const allocator = std.testing.allocator;90 const allocator = std.testing.allocator;
90 _ = url.URL.parse(allocator, "https://" ++ input ++ "/x", null) catch |err| switch (err) {91 const u = url.URL.parse(allocator, "https://" ++ input ++ "/x", null) catch |err| switch (err) {
91 error.InvalidURL => return,92 error.InvalidURL => return,
92 error.OutOfMemory => return error.OutOfMemory,93 error.OutOfMemory => return error.OutOfMemory,
93 };94 };
95 defer allocator.free(u.href);
94 return error.FailZigTest;96 return error.FailZigTest;
95}97}
9698
zig-out/test.zig+4-2
...@@ -6,10 +6,11 @@ const expect = @import("expect").expect;...@@ -6,10 +6,11 @@ const expect = @import("expect").expect;
66
7pub fn parseFail(input: []const u8, base: ?[]const u8) !void {7pub fn parseFail(input: []const u8, base: ?[]const u8) !void {
8 const allocator = std.testing.allocator;8 const allocator = std.testing.allocator;
9 _ = url.URL.parse(allocator, input, base) catch |err| switch (err) {9 const u = url.URL.parse(allocator, input, base) catch |err| switch (err) {
10 error.InvalidURL => return,10 error.InvalidURL => return,
11 error.OutOfMemory => return error.OutOfMemory,11 error.OutOfMemory => return error.OutOfMemory,
12 };12 };
13 defer allocator.free(u.href);
13 return error.FailZigTest;14 return error.FailZigTest;
14}15}
1516
...@@ -32,10 +33,11 @@ pub fn parsePass(input: []const u8, base: ?[]const u8, href: []const u8, origin:...@@ -32,10 +33,11 @@ pub fn parsePass(input: []const u8, base: ?[]const u8, href: []const u8, origin:
3233
33pub fn parseIDNAFail(comptime input: []const u8) !void {34pub fn parseIDNAFail(comptime input: []const u8) !void {
34 const allocator = std.testing.allocator;35 const allocator = std.testing.allocator;
35 _ = url.URL.parse(allocator, "https://" ++ input ++ "/x", null) catch |err| switch (err) {36 const u = url.URL.parse(allocator, "https://" ++ input ++ "/x", null) catch |err| switch (err) {
36 error.InvalidURL => return,37 error.InvalidURL => return,
37 error.OutOfMemory => return error.OutOfMemory,38 error.OutOfMemory => return error.OutOfMemory,
38 };39 };
40 defer allocator.free(u.href);
39 return error.FailZigTest;41 return error.FailZigTest;
40}42}
4143