From d0691844d567a88d8673ab5ba0b54ffba6498e18 Mon Sep 17 00:00:00 2001 From: "David L. Qiu" Date: Fri, 14 Nov 2025 08:21:08 -0800 Subject: [PATCH 1/2] replace CRLF with LF when loading file --- jupyter_server_documents/rooms/yroom_file_api.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/jupyter_server_documents/rooms/yroom_file_api.py b/jupyter_server_documents/rooms/yroom_file_api.py index 6bd7c2d..ce720f7 100644 --- a/jupyter_server_documents/rooms/yroom_file_api.py +++ b/jupyter_server_documents/rooms/yroom_file_api.py @@ -319,9 +319,17 @@ async def _load_content(self, jupyter_ydoc: YBaseDoc) -> None: self.log.info(f"Processing outputs for loaded notebook: '{self.room_id}'.") file_data = self.outputs_manager.process_loaded_notebook(file_id=self.file_id, file_data=file_data) + # Replace CRLF line terminators with LF line terminators + # Fixes #176, see issue description for more context. + content: str = file_data['content'] + if '\r\n' in content: + self.log.warning(f"Detected CRLF line terminators in '{path}'.") + content = content.replace('\r\n', '\n') + self.log.info("Replaced CRLF line terminators with LF line terminators.") + # Set JupyterYDoc content and set `dirty = False` to hide the "unsaved # changes" icon in the UI - jupyter_ydoc.source = file_data['content'] + jupyter_ydoc.source = content jupyter_ydoc.dirty = False # Set `_last_modified` timestamp From f256ff8b3e0d0e33104d2b463276395ef3c70889 Mon Sep 17 00:00:00 2001 From: "David L. Qiu" Date: Mon, 17 Nov 2025 11:32:25 -0800 Subject: [PATCH 2/2] improve safety by not assuming file content is a string --- jupyter_server_documents/rooms/yroom_file_api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jupyter_server_documents/rooms/yroom_file_api.py b/jupyter_server_documents/rooms/yroom_file_api.py index ce720f7..7963995 100644 --- a/jupyter_server_documents/rooms/yroom_file_api.py +++ b/jupyter_server_documents/rooms/yroom_file_api.py @@ -321,8 +321,8 @@ async def _load_content(self, jupyter_ydoc: YBaseDoc) -> None: # Replace CRLF line terminators with LF line terminators # Fixes #176, see issue description for more context. - content: str = file_data['content'] - if '\r\n' in content: + content = file_data.get('content') + if isinstance(content, str) and '\r\n' in content: self.log.warning(f"Detected CRLF line terminators in '{path}'.") content = content.replace('\r\n', '\n') self.log.info("Replaced CRLF line terminators with LF line terminators.")