From 15d279e6f5ad1a22dfc0cb2d9c3209fcae5f9c21 Mon Sep 17 00:00:00 2001 From: Baobhan Sith <80159437+Heavrnl@users.noreply.github.com> Date: Wed, 14 May 2025 09:11:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BB=9F=E4=B8=80=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E4=B8=BA=20Unix=20LF=20=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/websocket/handlers/sftp.handler.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/websocket/handlers/sftp.handler.ts b/packages/backend/src/websocket/handlers/sftp.handler.ts index cfd8bb7..6025d0a 100644 --- a/packages/backend/src/websocket/handlers/sftp.handler.ts +++ b/packages/backend/src/websocket/handlers/sftp.handler.ts @@ -46,7 +46,9 @@ export async function handleSftpOperation( const fileContent = payload?.content ?? payload?.data ?? ''; const encoding = payload?.encoding; if (payload?.path) { - const dataToSend = (typeof fileContent === 'string') ? fileContent : ''; + let dataToSend = (typeof fileContent === 'string') ? fileContent : ''; + // Convert only true line endings (CRLF and standalone CR not followed by LF) to LF to ensure Unix-compatible line endings + dataToSend = dataToSend.replace(/\r\n/g, '\n').replace(/\r(?!\n)/g, '\n'); sftpService.writefile(sessionId, payload.path, dataToSend, requestId, encoding); } else throw new Error("Missing 'path' in payload for writefile"); break;