| ... | ... | @@ -276,9 +276,9 @@ pub const Ip6Address = struct { |
| 276 | 276 | if (text[text_i] != ':') return .{ .invalid_byte = text_i }; |
| 277 | 277 | assert(parts_i == 0); |
| 278 | 278 | } |
| 279 | | text_i += 1; |
| 280 | | if (text.len - text_i == 0) return .unexpected_end; |
| 281 | 279 | compress_start = parts_i; |
| 280 | text_i += 1; |
| 281 | if (text.len - text_i == 0) continue :state .end; |
| 282 | 282 | continue :c text[text_i]; |
| 283 | 283 | } else { |
| 284 | 284 | parts_i += 1; |
| ... | ... | @@ -744,19 +744,30 @@ pub const Server = struct { |
| 744 | 744 | test "parsing IPv6 addresses" { |
| 745 | 745 | try testIp6Parse("fe80::e0e:76ff:fed4:cf22%eno1"); |
| 746 | 746 | try testIp6Parse("2001:db8::1"); |
| 747 | try testIp6ParseTransform("2001:db8::1", "2001:0db8:0000:0000:0000:0000:0000:0001"); |
| 748 | try testIp6Parse("::1"); |
| 749 | try testIp6Parse("::"); |
| 750 | try testIp6Parse("fe80::1"); |
| 751 | try testIp6Parse("fe80::abcd:ef12%3"); |
| 752 | try testIp6Parse("ff02::"); |
| 753 | try testIp6Parse("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"); |
| 754 | } |
| 755 | |
| 756 | fn testIp6Parse(input: []const u8) !void { |
| 757 | return testIp6ParseTransform(input, input); |
| 747 | 758 | } |
| 748 | 759 | |
| 749 | | fn testIp6Parse(text: []const u8) !void { |
| 750 | | const ua = switch (Ip6Address.Unresolved.parse(text)) { |
| 760 | fn testIp6ParseTransform(expected: []const u8, input: []const u8) !void { |
| 761 | const ua = switch (Ip6Address.Unresolved.parse(input)) { |
| 751 | 762 | .success => |p| p, |
| 752 | 763 | else => |x| { |
| 753 | | std.debug.print("failed to parse \"{s}\": {any}\n", .{ text, x }); |
| 764 | std.debug.print("failed to parse \"{s}\": {any}\n", .{ input, x }); |
| 754 | 765 | return error.TestFailed; |
| 755 | 766 | }, |
| 756 | 767 | }; |
| 757 | 768 | var buffer: [100]u8 = undefined; |
| 758 | 769 | const result = try std.fmt.bufPrint(&buffer, "{f}", .{ua}); |
| 759 | | try std.testing.expectEqualStrings(text, result); |
| 770 | try std.testing.expectEqualStrings(expected, result); |
| 760 | 771 | } |
| 761 | 772 | |
| 762 | 773 | test { |