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