Skip to content

Commit fc2e62b

Browse files
Prevent accidental discard of line content during file.readLines
file.readLines reads chunks of 1024 bytes, looking for newline characters. If we have content at the end of a chunk that isn't a newline, we store that content in a variable called `partialLine`. However, if an entire chunk goes by without a newline (say, there's a line with >1024 characters), then ideally, we should append the chunk to the stored `partialLine`. However, we were instead *replacing* `partialLine` with the new chunk, accidentally discarding whatever was in `partialLine` before. It's an easy bug to miss, and simply swapping `partialLine =` with `partialLine +=` fixes the issue perfectly. Fixes #190.
1 parent d1f2fcb commit fc2e62b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

MiniScript-cpp/src/ShellIntrinsics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ static IntrinsicResult intrinsic_readLines(Context *context, IntrinsicResult par
749749
}
750750
}
751751
if (lineStart < bytesRead) {
752-
partialLine = String(&buf[lineStart], bytesRead - lineStart);
752+
partialLine += String(&buf[lineStart], bytesRead - lineStart);
753753
}
754754
}
755755
if (!partialLine.empty()) list.Add(partialLine);

0 commit comments

Comments
 (0)