os: fix off-by-one error in ShellEscapeWriter

I am truly not sure why the tests never caught this, but I just fell for
the oldest trick in the book
pull/9842/head
Leah Amelia Chen 2025-12-07 13:35:52 +08:00
parent 08c9661683
commit ed1d77d518
No known key found for this signature in database
1 changed files with 1 additions and 3 deletions

View File

@ -5,8 +5,6 @@ const Writer = std.Io.Writer;
/// Writer that escapes characters that shells treat specially to reduce the
/// risk of injection attacks or other such weirdness. Specifically excludes
/// linefeeds so that they can be used to delineate lists of file paths.
///
/// T should be a Zig type that follows the `std.Io.Writer` interface.
pub const ShellEscapeWriter = struct {
writer: Writer,
child: *Writer,
@ -33,7 +31,7 @@ pub const ShellEscapeWriter = struct {
var count: usize = 0;
for (data[0 .. data.len - 1]) |chunk| try self.writeEscaped(chunk, &count);
for (0..splat) |_| try self.writeEscaped(data[data.len], &count);
for (0..splat) |_| try self.writeEscaped(data[data.len - 1], &count);
return count;
}