diff --git a/src/cli/args.zig b/src/cli/args.zig index 6444400a7..c226493f9 100644 --- a/src/cli/args.zig +++ b/src/cli/args.zig @@ -712,8 +712,8 @@ pub fn LineIterator(comptime ReaderType: type) type { unreachable; } orelse return null; - // Trim any whitespace around it - const trim = std.mem.trim(u8, entry, whitespace); + // Trim any whitespace (including CR) around it + const trim = std.mem.trim(u8, entry, whitespace ++ "\r"); if (trim.len != entry.len) { std.mem.copyForwards(u8, entry, trim); entry = entry[0..trim.len]; @@ -833,3 +833,14 @@ test "LineIterator spaces around '='" { try testing.expectEqual(@as(?[]const u8, null), iter.next()); try testing.expectEqual(@as(?[]const u8, null), iter.next()); } + +test "LineIterator with CRLF line endings" { + const testing = std.testing; + var fbs = std.io.fixedBufferStream("A\r\nB = C\r\n"); + + var iter = lineIterator(fbs.reader()); + try testing.expectEqualStrings("--A", iter.next().?); + try testing.expectEqualStrings("--B=C", iter.next().?); + try testing.expectEqual(@as(?[]const u8, null), iter.next()); + try testing.expectEqual(@as(?[]const u8, null), iter.next()); +}