Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jeremypw
Copy link
Collaborator

@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
@jeremypw jeremypw mentioned this pull request Jul 14, 2025
1 task
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
Collaborator 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
Collaborator Author

Cut and paste works correctly.

@jeremypw
Copy link
Collaborator Author

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

@jeremypw
Copy link
Collaborator 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
Collaborator 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
Collaborator 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
Collaborator 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
Collaborator 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
Collaborator 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.

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