Skip to content

FileOperations: Re-escape uris from Clipboard or DNDHandler before use in fileoperations#2616

Merged
lenemter merged 14 commits intomainfrom
jeremypw/fileoperations/hash-in-name
Aug 16, 2025
Merged

FileOperations: Re-escape uris from Clipboard or DNDHandler before use in fileoperations#2616
lenemter merged 14 commits intomainfrom
jeremypw/fileoperations/hash-in-name

Conversation

@jeremypw
Copy link
Contributor

@jeremypw jeremypw commented Jul 10, 2025

Fixes #2615

After #2268 files being copied or dragged have their name sanitized before being given to the recipient so that they appear correctly when pasted/dropped as text. However, they were not being re-escaped when used in a file operation and this caused the operation to fail for some files. This PR fixes that.

After this PR, copy/dragging a file should work both to a text document or terminal and to another folder in Files (or Dolphin or Nautilus at least).

Note that Dolphin does not unescape filenames when transferred as text but Nautilus does.

@jeremypw jeremypw marked this pull request as ready for review July 10, 2025 10:38
@jeremypw jeremypw requested a review from a team July 10, 2025 10:38
@jeremypw jeremypw added the Priority: High Significantly affecting majority of users' normal work label Jul 12, 2025
vjr
vjr previously approved these changes Jul 15, 2025
Copy link
Member

@vjr vjr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code LGTM but I can't confirm (repro) the fix works...

@lenemter
Copy link
Member

When dragging a file with '#' in its name into the Terminal, the pasted path gets cut off after '#'

@jeremypw jeremypw dismissed vjr’s stale review July 16, 2025 16:36

A bug has now been identified so dismissing approval in case of accidental merging.

@jeremypw
Copy link
Contributor Author

When dragging a file with '#' in its name into the Terminal, the pasted path gets cut off after '#'

Nautilus seems to have the same problem (with Pantheon Terminal).

@jeremypw
Copy link
Contributor Author

Cut and paste works correctly.

@jeremypw
Copy link
Contributor Author

This appears to be a bug in Terminal not Files - the "sanitization" of dropped uris is causing this truncation.

@jeremypw
Copy link
Contributor Author

See #877 for Terminal fix.

@jeremypw jeremypw requested a review from lenemter July 16, 2025 18:04
@zeebok
Copy link
Contributor

zeebok commented Aug 2, 2025

Hmmm just tested in a VM. It does fix D&Ding the ##test##.txt to a subfolder, but dragging into Terminal or Code (or an mp3 into Music) still doesn't seem to work. Terminal only shows the folder of the file, Code crashes, and Music sees the mp3 as invalid.

@jeremypw
Copy link
Contributor Author

jeremypw commented Aug 3, 2025

@zeebok Thanks for the review - it is hard to fix this problem without introducing problems elsewhere hence the need for multiple testers. There is a Terminal PR to fix handling # there (elementary/terminal#877). I'll look into the other instances you mentioned to see where the problem lies.

@jeremypw
Copy link
Contributor Author

jeremypw commented Aug 3, 2025

@zeebok I cannot reproduce the problem with pasting into Code I am afraid (using current master version of Code on OS8).

I notice that pasting from other file managers into Terminal also truncates confirming that it is a Terminal bug.

@jeremypw
Copy link
Contributor Author

jeremypw commented Aug 3, 2025

I can conform that pasting into Music is problematic. I suspect it is because Files is including the files:// protocol for local files.

@jeremypw
Copy link
Contributor Author

jeremypw commented Aug 3, 2025

Hmm, I now cannot reproduce the Music issue after recompiling Music from source, neither on version 8.0.0 or version 7.0.0 of Music, at least with files not containing # so I am not sure what version of Music I was running before. However, I cannot drop files onto a similar third-party music app (Amberol) but Nautilus e.g. can. I cannot see any difference in the URI of a file dropped by Files and Nautilus so that is puzzling.

There is a problem similar to Terminal in Music where the URI of files is truncated at the first occurrence of # but in that case it does not occur with other file managers.

@jeremypw
Copy link
Contributor Author

jeremypw commented Aug 6, 2025

@zeebok I'd be grateful for your review after the latest commits. I noticed that Files was only providing the TargetType TEXT_URI_LIST to other apps - I've fixed that although I don't think it is related to this issue necessarily. I've also tried to clarify the code a little with better names and comments.
Also, I've reverted the stringbuilder function to work as it did in version 6.x i.e. it only sanitizes the path when providing a TargetType.STRING.

I suggest you test using Music compiled from source as the current release has issues with dropped files. I also suggest testing with Terminal compiled from elementary/terminal#877.

I could not get dropping onto Amberol to work - maybe because it is a Gtk4 app and DnD is done differently? I think any issues with 3rd party apps will have to be left for another PR.

@jeremypw
Copy link
Contributor Author

jeremypw commented Aug 14, 2025

@lenemter I've incorporated your suggested changes and it works correctly with Terminal. I am still getting issue elementary/music#816 with Music though whereas Dolphin and Nautilus work correctly. This is using a file with# and spaces in the file name.

May be because the main branch is now Gtk4 I guess.

@jeremypw
Copy link
Contributor Author

@lenemter Its started working with Music now! Not sure what's going on. Must have been running a different version to the one I thought 🤷

@jeremypw jeremypw requested a review from lenemter August 14, 2025 14:51
@jeremypw
Copy link
Contributor Author

@lenemter I've made the requested change - sorry I missed that. It seems to work OK but I would be grateful for more testing.

@jeremypw
Copy link
Contributor Author

jeremypw commented Aug 15, 2025

Hmm, dropping onto the pathbar seems broken.

Update: This seems to be an issue in main

@jeremypw
Copy link
Contributor Author

jeremypw commented Aug 15, 2025

Also dropping some files (containing hash in name) onto Dolphin is broken but works on Nautilus 🤷

Update: Dropping the same file from Nautilus doesn't work either so maybe a Dolphin issue.

Copy link
Member

@lenemter lenemter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lenemter lenemter merged commit 0ae1157 into main Aug 16, 2025
4 checks passed
@lenemter lenemter deleted the jeremypw/fileoperations/hash-in-name branch August 16, 2025 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: High Significantly affecting majority of users' normal work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Files with names containing # characters are not transferred correctly.

4 participants