diff --git a/src/rdata/dnssec.zig b/src/rdata/dnssec.zig index e3e2c36..2a040b4 100644 --- a/src/rdata/dnssec.zig +++ b/src/rdata/dnssec.zig @@ -669,9 +669,11 @@ pub const Nsec = struct { ); } - /// The next name, absolute, and then the types it lists. + /// The next name, absolute, and then the types it lists, which are left + /// off entirely when there are none. pub fn format(self: Nsec, w: *Writer) Writer.Error!void { - try w.print("{f} {f}", .{ self.next, self.types }); + try w.print("{f}", .{self.next}); + if (self.types.bytes.len > 0) try w.print(" {f}", .{self.types}); } test format { @@ -680,6 +682,9 @@ pub const Nsec = struct { .types = .{ .bytes = "\x00\x02\x40\x01" }, }; try std.testing.expectFmt("host.example.com. A MX", "{f}", .{nsec}); + // With no types, nothing follows the name -- not even a space. + const bare: Nsec = .{ .next = Name.literal("host.example.com"), .types = .empty }; + try std.testing.expectFmt("host.example.com.", "{f}", .{bare}); } }; @@ -958,14 +963,18 @@ pub const Csync = struct { try std.testing.expectEqualSlices(u8, "\x00\x00\x00\x2a\x00\x01\x00\x01\x20", b.buffer[12..b.pos]); } - /// The serial and the flags in decimal, then the types. + /// The serial and the flags in decimal, then the types, which are left + /// off entirely when there are none. pub fn format(self: Csync, w: *Writer) Writer.Error!void { - try w.print("{d} {d} {f}", .{ self.serial, self.flags, self.types }); + try w.print("{d} {d}", .{ self.serial, self.flags }); + if (self.types.bytes.len > 0) try w.print(" {f}", .{self.types}); } test format { const csync: Csync = .{ .serial = 42, .flags = 3, .types = .{ .bytes = "\x00\x01\x20" } }; try std.testing.expectFmt("42 3 NS", "{f}", .{csync}); + const bare: Csync = .{ .serial = 42, .flags = 3, .types = .empty }; + try std.testing.expectFmt("42 3", "{f}", .{bare}); } };