Repository navigation
Text overrides restored file due to trailing newline #9077
Description
Activity
I can confirm this on a production instance, with a few additional observations that may help narrow it down.
Environment
- Nextcloud Hub 26 Spring (34.0.4), Text 8.0.0
- Files synced with the macOS desktop client; the Markdown files were written by a script on the client and compared byte by byte with a reference copy kept outside the synced folder
- Browser: Firefox 156.0.1 (64-Bit)
What we tested (two Markdown files with identical content, about 1.7 KB each, both ending with a single trailing newline; one named
README.md, one named differently)Server state Entering the folder in Files Clicking the other .mdfile, no typingdefaults README.mdrewrittenfile rewritten open_read_only_enabled = 1README.mdstill rewrittenfile still rewritten open_read_only_enabled = 1andworkspace_available = 0unchanged not tested in this state workspace_available = 0, Text app disabledunchanged unchanged (plain download) Additional observations
-
The rich workspace triggers it without any click. Just entering a folder in the Files app rewrote that folder's
README.mdon the server within about a minute. We did not click a file and did not click into the workspace area.workspace_available = 0stopped this. -
open_read_only_enabled = 1does not prevent the write. With the setting enabled, the file opened read-only as expected (typing was only possible after pressing "Edit"), but the file on the server was rewritten anyway, without "Edit" ever being pressed. The same was true for the rich workspace. So the setting protects against accidental typing, but not against the save described in this issue. -
It is not only the trailing newline that changes. Because the whole document is serialized again, the automatic save applies all normalizations at once. In our test file (1719 bytes before, 1747 bytes after):
_emphasis_became*emphasis*- an ordered list written as
1./1.became1./2. - adjacent lists using
-,*and+were separated by two blank lines each - table columns were re-padded, and a left-alignment marker
:---was reduced to--- - a pipe inside inline code in a table cell was escaped with a backslash
- a closed ATX heading
### Title ###became### Title - two consecutive blank lines were collapsed into one
- the trailing newline was removed
Front matter, backslash and two-space hard breaks, fenced code blocks, HTML and HTML comments were left untouched.
-
A file is only rewritten once. After the first automatic save the file no longer ends with a newline, and opening it again did not change it. This matches the trigger described above.
Why this matters to us
The rewritten file is synced to every client, so viewing a folder in the browser silently changes files on all devices. The modification time no longer says "last edited by a person", and any comparison by size or checksum reports a change that nobody made. For files that are tracked or checked elsewhere, this is hard to notice and hard to trace back.
We have disabled the Text app on this instance for now. I am happy to test a fix or to provide the test file.
Describe the bug
Text auto saves unchanged file upon opening, no editing, due to a normalizer behavior. See videos:
To Reproduce
From the video, you need to restore a file and needs to have one specific thing, a trailing newline::
Expected behavior
The serialiser should preserve a trailing newline, or
SaveServiceshould not write when the only difference is its own normalization. It's easy to demonstrate without Notes at all - put a markdown file ending in a newline in Files, open it in the Viewer, don't touch it, and a version appears within ~10 seconds.Screenshots
text_in_files_viewer.mp4
text_editor.mp4
Server details:
Client details:
Logs
Nextcloud log (data/nextcloud.log)
Browser log