Skip to content

Incorrect saving of files with DOS line endings #448

Open
@BaukJ

Description

@BaukJ

Description

The collab plugin changes the autosave functionality to save files in a different route to normal jupyterlab file saves. This is not an issue without the collab plugin if manually saving or saving with the default autosave functionality.
When files have DOS line endings, any text entered is saved shifted to the left.
This is apparent if the file is closed and re-opened, as it appears fine in the editor but is saved incorrectly to disk.

The longer the file, the more shifted to the left, which makes it appear that the information sent through the websocket is ignoring the extra carriage return char, so when applying the changes to the file it does not take that into account, hence everything is shifted to the left.

Example of the same change being applied to 2 files, one with dos line endings and one with normal linux line endings:

==> example-dos.py <==

import os
import sys

nameKuba = ""
print(f"Hello {name}")

==> example-unix.py <==

import os
import sys

name = "Kuba"
print(f"Hello {name}")

Reproduce

See this PR with a failing test for DOS line endings with a carriage return and passing for Linux line endings without the carriage return: #449

Also see this notebook: https://github.com/BaukJ/work-snippets/blob/main/2025/03/sagemaker-dos-bug/DosBugNotebook.ipynb

And this video of the failing test, taken directly from the UI tests:
https://github.com/user-attachments/assets/49b539de-e857-451d-8816-58e00223c263

Expected behavior

Edits to files with DOS line endings should be correctly saved.

Context

Reproduced on multiple systems, first found in AWS sagemaker, but reproduced on vanilla jupyter and then got a failing test in the ui tests of this repo.
This does not happen when using jupyterlab's default save or autosave functionality.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions