| ... | ... | @@ -1059,8 +1059,16 @@ fn percentDecode(allocator: std.mem.Allocator, input: []const u8) ![]u8 { |
| 1059 | 1059 | /// https://url.spec.whatwg.org/#concept-domain-to-ascii |
| 1060 | 1060 | // TODO: |
| 1061 | 1061 | fn domainToAscii(allocator: std.mem.Allocator, domain: []const u8, beStrict: bool) ![]u8 { |
| 1062 | | _ = beStrict; |
| 1063 | | return allocator.dupe(u8, domain); |
| 1062 | const result = try allocator.dupe(u8, domain); |
| 1063 | errdefer allocator.free(result); |
| 1064 | if (!beStrict) { |
| 1065 | if (result.len == 0) return error.InvalidURL; |
| 1066 | if (extras.matchesAny(u8, result, is_forbidden_domain_codepoint)) return error.InvalidURL; |
| 1067 | return result; |
| 1068 | } |
| 1069 | std.debug.assert(result.len > 0); |
| 1070 | std.debug.assert(!extras.matchesAny(u8, result, is_forbidden_domain_codepoint)); |
| 1071 | return result; |
| 1064 | 1072 | } |
| 1065 | 1073 | |
| 1066 | 1074 | // https://url.spec.whatwg.org/#ends-in-a-number-checker |
| ... | ... | @@ -1227,6 +1235,14 @@ fn is_forbidden_host_codepoint(c: u8) bool { |
| 1227 | 1235 | if (c == '|') return true; |
| 1228 | 1236 | return false; |
| 1229 | 1237 | } |
| 1238 | /// https://url.spec.whatwg.org/#forbidden-domain-code-point |
| 1239 | fn is_forbidden_domain_codepoint(c: u8) bool { |
| 1240 | if (is_forbidden_host_codepoint(c)) return true; |
| 1241 | if (is_c0control(c)) return true; |
| 1242 | if (c == '%') return true; |
| 1243 | if (c == 0x7f) return true; |
| 1244 | return false; |
| 1245 | } |
| 1230 | 1246 | /// https://url.spec.whatwg.org/#url-code-points |
| 1231 | 1247 | fn is_url_codepoint(c: u21) bool { |
| 1232 | 1248 | if (c < 128 and std.ascii.isAlphanumeric(@intCast(c))) return true; |