Skip to content

Commit fda6868

Browse files
committed
fix(agents): normalize read line endings
1 parent 13a092c commit fda6868

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

‎src/agents/sessions/tools/read.test.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,12 @@ describe("read tool", () => {
217217
expect(textContent(result)).toBe("File contains no readable text (3 bytes).");
218218
});
219219

220-
it("describes newline-only files instead of returning blank content", async () => {
220+
it.each([
221+
["LF", "\n"],
222+
["CRLF", "\r\n"],
223+
])("describes %s-only files instead of returning blank content", async (_label, contents) => {
221224
const tempDir = tempDirs.make("openclaw-read-blank-line-");
222-
await fs.writeFile(path.join(tempDir, "blank.txt"), "\n");
225+
await fs.writeFile(path.join(tempDir, "blank.txt"), contents);
223226
const tool = createReadToolDefinition(tempDir);
224227

225228
const result = await tool.execute(

‎src/agents/sessions/tools/read.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,9 @@ export function createReadToolDefinition(
534534
} else {
535535
const decodedText =
536536
ops.decodeText?.({ buffer, absolutePath }) ?? buffer.toString("utf8");
537-
const textContent = decodedText.startsWith("\uFEFF")
538-
? decodedText.slice(1)
539-
: decodedText;
537+
const textContent = (
538+
decodedText.startsWith("\uFEFF") ? decodedText.slice(1) : decodedText
539+
).replaceAll("\r\n", "\n");
540540
const allLines = textContent.split("\n");
541541
if (allLines.at(-1) === "") {
542542
allLines.pop();

0 commit comments

Comments
 (0)