Skip to content

Improved newline handling#2633

Open
valoq wants to merge 11 commits into
gokcehan:masterfrom
valoq:newline
Open

Improved newline handling#2633
valoq wants to merge 11 commits into
gokcehan:masterfrom
valoq:newline

Conversation

@valoq

@valoq valoq commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Picking up the discussion from #2630

This PR cleans up and refactors the handling of newlines in filenames and implements the recommendations from POSIX.1-2024

  • newlines are refused to be operated on: no copy, no move etc.
  • existing filenames with newlines are displayed as before with substitude characters
  • rename will refuse to save a filename with newlines but can be used to edit a filename to remove the newline.

One thing to discuss and decide for this PR is how to display newlines, which was already mentioned in #2505

Here are some obvious options:

The current PR behavior:

lf-current

The proposal from #2505

lf-symbol

With ASCII names:

lf-token

How coreutils "ls" displays it

ls

How "lsd" displays it:

lsd

Displaying the different escape sequences seems better then replacing them all with the same "illegal character" symbol, at least for these four that actually matter. The symbols proposed in #2505 seem really small, but maybe thats just me? (can anyone confirm this is how it shows up too?)
The display from "lsd" is what I would prefer but we would need to escape that and this adds its own problems, which leaves the ASCII name display as my personal preferred solution since its the most readable.

@valoq

valoq commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

The replacement character is still unchanged but the PR feels ready for review now. (though intended for after r42)
@CatsDeservePets What do you think? I tried to make the entire newline handling solid while still keeping it as simple as possible. There are a few issues that can lead to accidents like data loss when custom commands are used in lfrc and they are run on files with newlines (e.g the wiki example trash-cli would delete the wrong files) which is the most relevant of the reasons for this PR.

(I will squash the commits before merge but we need to wait for the release and a decision on #2633 first anyway)

@valoq
valoq marked this pull request as ready for review July 8, 2026 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant