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;
6161w.write(`
6262pub fn parseFail(input: []const u8, base: ?[]const u8) !void {
6363 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) {
6565 error.InvalidURL => return,
6666 error.OutOfMemory => return error.OutOfMemory,
6767 };
68 defer allocator.free(u.href);
6869 return error.FailZigTest;
6970}
7071
......@@ -87,10 +88,11 @@ pub fn parsePass(input: []const u8, base: ?[]const u8, href: []const u8, origin:
8788
8889pub fn parseIDNAFail(comptime input: []const u8) !void {
8990 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) {
9192 error.InvalidURL => return,
9293 error.OutOfMemory => return error.OutOfMemory,
9394 };
95 defer allocator.free(u.href);
9496 return error.FailZigTest;
9597}
9698
zig-out/test.zig+4-2
......@@ -6,10 +6,11 @@ const expect = @import("expect").expect;
66
77pub fn parseFail(input: []const u8, base: ?[]const u8) !void {
88 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) {
1010 error.InvalidURL => return,
1111 error.OutOfMemory => return error.OutOfMemory,
1212 };
13 defer allocator.free(u.href);
1314 return error.FailZigTest;
1415}
1516
......@@ -32,10 +33,11 @@ pub fn parsePass(input: []const u8, base: ?[]const u8, href: []const u8, origin:
3233
3334pub fn parseIDNAFail(comptime input: []const u8) !void {
3435 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) {
3637 error.InvalidURL => return,
3738 error.OutOfMemory => return error.OutOfMemory,
3839 };
40 defer allocator.free(u.href);
3941 return error.FailZigTest;
4042}
4143