From 4e69a7b9fffa1e4c3fa6d978efd72ca599d68617 Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Thu, 29 Oct 2026 16:43:59 -0500 Subject: [PATCH] Print no trailing space after an NSEC or CSYNC with no types Both formatted the type bitmap after a space whether or not it held anything, so one with no types ended "host.example.com. " and "42 3 ". NSEC3 already left the types off entirely when there were none, and NSEC and CSYNC now do the same. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01P9FTtVnMcnFRXFB7z9TZRE --- src/rdata/dnssec.zig | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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}); } }; -- knotmirror 0.0.1