summaryrefslogtreecommitdiff
path: root/src/cli
diff options
context:
space:
mode:
authorGregory Anders <greg@gpanders.com>2024-01-05 09:21:34 -0600
committerGregory Anders <greg@gpanders.com>2024-01-05 09:37:55 -0600
commit5fe2d03e96c94b031a4ae2a5bb315a21e9844117 (patch)
tree2a56dac567da3d60c7fb07b72356762ebaa925c2 /src/cli
parent20300f46dab2d8bd7a90d5f752c2bb5ad2f0fa9a (diff)
cli: strip CR in line iterator
Diffstat (limited to 'src/cli')
-rw-r--r--src/cli/args.zig15
1 files changed, 13 insertions, 2 deletions
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());
+}