Skip to content

Commit dccb851

Browse files
authored
Replace CRLF with LF when loading file (#177)
* replace CRLF with LF when loading file * improve safety by not assuming file content is a string
1 parent 6adb667 commit dccb851

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

jupyter_server_documents/rooms/yroom_file_api.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,17 @@ async def _load_content(self, jupyter_ydoc: YBaseDoc) -> None:
319319
self.log.info(f"Processing outputs for loaded notebook: '{self.room_id}'.")
320320
file_data = self.outputs_manager.process_loaded_notebook(file_id=self.file_id, file_data=file_data)
321321

322+
# Replace CRLF line terminators with LF line terminators
323+
# Fixes #176, see issue description for more context.
324+
content = file_data.get('content')
325+
if isinstance(content, str) and '\r\n' in content:
326+
self.log.warning(f"Detected CRLF line terminators in '{path}'.")
327+
content = content.replace('\r\n', '\n')
328+
self.log.info("Replaced CRLF line terminators with LF line terminators.")
329+
322330
# Set JupyterYDoc content and set `dirty = False` to hide the "unsaved
323331
# changes" icon in the UI
324-
jupyter_ydoc.source = file_data['content']
332+
jupyter_ydoc.source = content
325333
jupyter_ydoc.dirty = False
326334

327335
# Set `_last_modified` timestamp

0 commit comments

Comments
 (0)