fix(core): normalize CRLF line endings in step scripts (#1)

Bash treats a trailing carriage return as part of the command, so notebooks saved with CRLF endings produced broken scripts.
This commit is contained in:
Florian Schmidt
2026-11-16 00:06:28 +01:00
parent eee6c0d4fb
commit c993089f37
2 changed files with 4 additions and 2 deletions
+2 -1
View File
@@ -177,7 +177,8 @@ export function parseNotebook(source: string): Notebook {
artifacts: kind === "run" ? artifacts : [],
uploads: kind === "run" ? uploads : [], timeoutSec,
},
script: rawLines.slice(begin + 1, end).join("\n")
// LF-normalized: bash must never see a trailing \r from CRLF notebooks.
script: lines.slice(begin + 1, end).join("\n")
+ (end > begin + 1 && (end < lines.length || /\n$/.test(source)) ? "\n" : ""),
range: { startLine: begin + 1, endLine: end < lines.length ? end + 1 : end },
};
+2 -1
View File
@@ -83,7 +83,8 @@ describe("parser", () => {
it("uses title fallback, numeric step ids, CRLF ranges and exact script whitespace", () => {
expect(parseNotebook("").title).toBe("Untitled");
const n = parseNotebook("---\r\ntitle: Front\r\n---\r\n# Heading\r\n```sh {run}\r\n echo x \r\n\r\n```\r\n");
expect(n.title).toBe("Front"); expect(steps(n.blocks)[0]).toMatchObject({ script: " echo x \r\n\r\n", attrs: { id: "step-1" }, range: { startLine: 5, endLine: 8 } });
// Scripts are executed by bash: CRLF line endings must not leak a trailing \r into commands.
expect(n.title).toBe("Front"); expect(steps(n.blocks)[0]).toMatchObject({ script: " echo x \n\n", attrs: { id: "step-1" }, range: { startLine: 5, endLine: 8 } });
});
});