From ca8288e4d4de7ccc388ddcfe8305c05614cf63bf Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Thu, 22 Jan 2026 01:59:53 -0800 Subject: [PATCH] =?UTF-8?q?=E2=94=94=E2=94=80=20run=20test=20511/542=20pas?= =?UTF-8?q?sed,=204=20failed,=2027=20skipped?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- generate.ts | 1 - licenses.txt | 2 ++ url.zig | 8 ++++++-- zigmod.yml | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/generate.ts b/generate.ts index 7c6cfa76f3f28da81730d9fb4c88853ab8af269f..a1d43719b56c976ae10281a4fe44369ddfe616a7 100644 --- a/generate.ts +++ b/generate.ts @@ -1,4 +1,3 @@ -import { closeSync, openSync } from "node:fs"; import casesraw from "./urltestdata.json"; import casesidna from "./IdnaTestV2.json"; diff --git a/licenses.txt b/licenses.txt index 8491ea7d0ea491fdce748d375a5913766588da31..e77a3aad5d54b43c939a4906934f98b746595242 100644 --- a/licenses.txt +++ b/licenses.txt @@ -3,12 +3,14 @@ MPL-2.0: - This - git https://github.com/nektro/zig-net - git https://github.com/nektro/zig-nio +- git https://github.com/nektro/zig-unicode-idna MIT: = https://spdx.org/licenses/MIT - git https://github.com/nektro/zig-expect - git https://github.com/nektro/zig-extras - git https://github.com/nektro/zig-sys-linux +- git https://github.com/nektro/zig-unicode-ucd Unspecified: - system_lib c diff --git a/url.zig b/url.zig index d2fc19ebaca618a78c3072f6248502ec71a9a013..692cccce952f25966c7a0bf146ac8d9e4d4033cd 100644 --- a/url.zig +++ b/url.zig @@ -2,6 +2,7 @@ const std = @import("std"); const builtin = @import("builtin"); const net = @import("net"); const extras = @import("extras"); +const unicode_idna = @import("unicode-idna"); pub const URL = struct { href: []const u8, @@ -448,6 +449,7 @@ pub const URL = struct { }, .file => { // 1. Set url’s scheme to "file". + scheme.clearRetainingCapacity(); try scheme.appendSlice("file"); // 2. Set url’s host to the empty string. host = .{ .name = "" }; @@ -1057,9 +1059,11 @@ 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 { - const result = try allocator.dupe(u8, domain); + const result = unicode_idna.ToASCII(allocator, domain, beStrict, true, true, beStrict, false, beStrict, false) catch |err| switch (err) { + error.IDNAFailure => return error.InvalidURL, + error.OutOfMemory => return error.OutOfMemory, + }; errdefer allocator.free(result); if (!beStrict) { if (result.len == 0) return error.InvalidURL; diff --git a/zigmod.yml b/zigmod.yml index a0af50bbec67400de41bc51f93adeb53dd50455c..1800017b0d80e80e9623718f8d5b2eb8c701ae67 100644 --- a/zigmod.yml +++ b/zigmod.yml @@ -6,5 +6,6 @@ description: A WHATWG URL-compatible parser for Zig dependencies: - src: git https://github.com/nektro/zig-net - src: git https://github.com/nektro/zig-extras + - src: git https://github.com/nektro/zig-unicode-idna root_dependencies: - src: git https://github.com/nektro/zig-expect -- 2.54.0