| ... | ... | @@ -2,6 +2,7 @@ const std = @import("std"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | const net = @import("net"); |
| 4 | 4 | const extras = @import("extras"); |
| 5 | const unicode_idna = @import("unicode-idna"); |
| 5 | 6 | |
| 6 | 7 | pub const URL = struct { |
| 7 | 8 | href: []const u8, |
| ... | ... | @@ -448,6 +449,7 @@ pub const URL = struct { |
| 448 | 449 | }, |
| 449 | 450 | .file => { |
| 450 | 451 | // 1. Set url’s scheme to "file". |
| 452 | scheme.clearRetainingCapacity(); |
| 451 | 453 | try scheme.appendSlice("file"); |
| 452 | 454 | // 2. Set url’s host to the empty string. |
| 453 | 455 | host = .{ .name = "" }; |
| ... | ... | @@ -1057,9 +1059,11 @@ fn percentDecode(allocator: std.mem.Allocator, input: []const u8) ![]u8 { |
| 1057 | 1059 | } |
| 1058 | 1060 | |
| 1059 | 1061 | /// https://url.spec.whatwg.org/#concept-domain-to-ascii |
| 1060 | | // TODO: |
| 1061 | 1062 | fn domainToAscii(allocator: std.mem.Allocator, domain: []const u8, beStrict: bool) ![]u8 { |
| 1062 | | const result = try allocator.dupe(u8, domain); |
| 1063 | const result = unicode_idna.ToASCII(allocator, domain, beStrict, true, true, beStrict, false, beStrict, false) catch |err| switch (err) { |
| 1064 | error.IDNAFailure => return error.InvalidURL, |
| 1065 | error.OutOfMemory => return error.OutOfMemory, |
| 1066 | }; |
| 1063 | 1067 | errdefer allocator.free(result); |
| 1064 | 1068 | if (!beStrict) { |
| 1065 | 1069 | if (result.len == 0) return error.InvalidURL; |