Skip to content

Text overrides restored file due to trailing newline #9077

Description

@AndyScherzinger

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::

  1. restored version : 150 bytes, tail "...old line :)\n\n🌴\n"
  2. what Text wrote : 149 bytes, tail "...old line :)\n\n🌴"
  3. first difference at byte 149: restored "\n" vs written ""

Expected behavior
The serialiser should preserve a trailing newline, or SaveService should 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:

  • Nextcloud version: master
  • PHP Version: -
  • Database: -
  • I use the docker dev setup

Client details:

  • OS: Win11pro
  • Browser: FF
  • Browser version: 153.0.4
  • Device: Desktop
Logs

Nextcloud log (data/nextcloud.log)

Insert your Nextcloud log here

Browser log

Insert your browser log here, this could for example include:

a) The javascript console log
b) The network log
c) ...

Activity

  1. micha-wb commented on Oct 5, 2026

    @micha-wb

    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 .md file, no typing
    defaults README.md rewritten file rewritten
    open_read_only_enabled = 1 README.md still rewritten file still rewritten
    open_read_only_enabled = 1 and workspace_available = 0 unchanged not tested in this state
    workspace_available = 0, Text app disabled unchanged unchanged (plain download)

    Additional observations

    1. The rich workspace triggers it without any click. Just entering a folder in the Files app rewrote that folder's README.md on the server within about a minute. We did not click a file and did not click into the workspace area. workspace_available = 0 stopped this.

    2. open_read_only_enabled = 1 does 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.

    3. 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. became 1. / 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.

    4. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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