From b10e5ab46dcb145722cc08522c824a5aa06e4948 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Mon, 12 Jan 2026 02:01:34 -0800 Subject: [PATCH] =?UTF-8?q?=E2=94=94=E2=94=80=20run=20test=20499/543=20pas?= =?UTF-8?q?sed,=2017=20failed,=2027=20skipped?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- url.zig | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/url.zig b/url.zig index ea4bb28a44aa913ff0210774b730c3591fcffcb5..d2fc19ebaca618a78c3072f6248502ec71a9a013 100644 --- a/url.zig +++ b/url.zig @@ -1059,8 +1059,16 @@ fn percentDecode(allocator: std.mem.Allocator, input: []const u8) ![]u8 { /// https://url.spec.whatwg.org/#concept-domain-to-ascii // TODO: fn domainToAscii(allocator: std.mem.Allocator, domain: []const u8, beStrict: bool) ![]u8 { - _ = beStrict; - return allocator.dupe(u8, domain); + const result = try allocator.dupe(u8, domain); + errdefer allocator.free(result); + if (!beStrict) { + if (result.len == 0) return error.InvalidURL; + if (extras.matchesAny(u8, result, is_forbidden_domain_codepoint)) return error.InvalidURL; + return result; + } + std.debug.assert(result.len > 0); + std.debug.assert(!extras.matchesAny(u8, result, is_forbidden_domain_codepoint)); + return result; } // https://url.spec.whatwg.org/#ends-in-a-number-checker @@ -1227,6 +1235,14 @@ fn is_forbidden_host_codepoint(c: u8) bool { if (c == '|') return true; return false; } +/// https://url.spec.whatwg.org/#forbidden-domain-code-point +fn is_forbidden_domain_codepoint(c: u8) bool { + if (is_forbidden_host_codepoint(c)) return true; + if (is_c0control(c)) return true; + if (c == '%') return true; + if (c == 0x7f) return true; + return false; +} /// https://url.spec.whatwg.org/#url-code-points fn is_url_codepoint(c: u21) bool { if (c < 128 and std.ascii.isAlphanumeric(@intCast(c))) return true; -- 2.54.0