config: refill after ignored line boundaries

Refill the line iterator when an ignored comment or blank line
consumes the remaining buffered data.

Configuration parsing previously stopped silently at these boundaries
and left every subsequent setting unapplied.

Request more data before continuing the loop and cover both comment
and blank line boundaries with buffered-reader regression tests.
This commit is contained in:
Mitchell Hashimoto
2026-08-05 11:29:23 -07:00
parent 54fe8e1885
commit c247e455c2

View File

@@ -1454,8 +1454,15 @@ pub const LineIterator = struct {
entry = entry[0..trim.len];
}
// Ignore blank lines and comments
if (entry.len == 0 or entry[0] == '#') continue;
// Ignore blank lines and comments. If this line consumed the
// remaining buffer, refill before the loop condition checks for
// more data.
if (entry.len == 0 or entry[0] == '#') {
if (self.r.seek == self.r.end) {
self.r.fillMore() catch {};
}
continue;
}
break entry;
} else return null;
@@ -1623,3 +1630,27 @@ test "LineIterator with buffered and primed reader" {
try testing.expectEqual(@as(?[]const u8, null), iter.next());
try testing.expectEqual(@as(?[]const u8, null), iter.next());
}
test "LineIterator refills after ignored line at buffer boundary" {
const testing = std.testing;
{
var f: std.Io.Reader = .fixed("#\nA\n");
var buf: [2]u8 = undefined;
var r = f.limited(.unlimited, &buf);
var iter: LineIterator = .init(&r.interface);
try testing.expectEqualStrings("--A", iter.next().?);
try testing.expectEqual(@as(?[]const u8, null), iter.next());
}
{
var f: std.Io.Reader = .fixed("\nA\n");
var buf: [1]u8 = undefined;
var r = f.limited(.unlimited, &buf);
var iter: LineIterator = .init(&r.interface);
try testing.expectEqualStrings("--A", iter.next().?);
try testing.expectEqual(@as(?[]const u8, null), iter.next());
}
}