Sunflower icon indicating copy to clipboard operation
Sunflower copied to clipboard

Files with "#" in name fail

Open nbbn opened this issue 8 years ago • 22 comments

Hello, sunflower is great! There is issue with handling files with "#" in name. Only part of path before "#" is send to program, when file is double-clicked. For example, when I try to open file "test#test" file "test" is opened.

I use Sunflower 0.3(61) from deb package.

nbbn avatar Feb 19 '16 01:02 nbbn

Thanks for kind words and for reporting this issue. Can you please provide version of Sunflower you are using. Just to make sure we are both on the same page. I remember similar issue to this one being reported recently so I'd like to make sure that issue is properly described.

MeanEYE avatar Feb 19 '16 15:02 MeanEYE

I use Sunflower 0.3(61) from deb package. I updated the first post.

nbbn avatar Feb 19 '16 15:02 nbbn

I suppose it same problem https://github.com/MeanEYE/Sunflower/issues/66 By pressing F4 files with # open fine with gedit

ArseniyK avatar Feb 19 '16 15:02 ArseniyK

Next problems,

  1. right click on file -> Open with -> another application -> in new window select gedit. Then you get opened file: filename" (yes, quote at the end) The same issue with other editors.
  2. open text file test%test by double click in gedit. Opened file will be Untitled Document 1 with strange loading sign. F4 works fine. Other editors work fine.

I write it here, because I think there is one big issue with opening files. and #66 is about the same.

nbbn avatar Feb 19 '16 16:02 nbbn

Thanks for testing.

MeanEYE avatar Feb 19 '16 16:02 MeanEYE

Next quirk: I have file 36%160.pdf. When I try to move between panels using: ctrl+x, tab, ctrl+v I receive message: Application is unable to handle specified data. Check if source items still exist. When I use F6, it works fine.

nbbn avatar Feb 23 '16 09:02 nbbn

Oh, this sounds like a new issue as Ctrl+X puts the file path to clipboard. You should test by pressing Ctrl+X in Nautilus or something like that and then pressing Ctrl+V in Sunflower. Or the other way around.

MeanEYE avatar Feb 23 '16 10:02 MeanEYE

It works great between Nautilus, xfe and Sunflower. In both directions. Maybe it is a new issue. Please make new issue, if you wish.

nbbn avatar Feb 23 '16 14:02 nbbn

It is a second issue.

MeanEYE avatar Feb 24 '16 11:02 MeanEYE

Same problem here. In my case I open a video file via the Tothem player. When I try to open a file with # in name, then the Sunflower opens another file in current directory. I made a video of this behavior.

@MeanEYE , sorry for many issues in last days from me. I use the Sunflower only as a twin-panel file manager on my PC :+1:

nervgh avatar Feb 24 '16 19:02 nervgh

Thanks @nervgh.

MeanEYE avatar Feb 25 '16 10:02 MeanEYE

I looked into file names with a " in it: in order to execute e.g. the default editor, we take 'gedit %U' and replace %U with a double-quoted file name e.g. gedit "foo" But we don't escape a double-quote contained in the file name itself e.g. gedit "foo"bar" and then the launch process fails. gedit "foo\bar" works as expected. This should be a simple change to associations.__format_command_string(). Should I just submit a fix?

cmallwitz avatar Mar 08 '16 22:03 cmallwitz

Yes @cmallwitz. That would be great.

MeanEYE avatar Mar 08 '16 22:03 MeanEYE

PR #205 submitted. Christian

On Tue, Mar 8, 2016 at 10:23 PM, Mladen Mijatov [email protected] wrote:

Yes @cmallwitz https://github.com/cmallwitz. That would be great.

— Reply to this email directly or view it on GitHub https://github.com/MeanEYE/Sunflower/issues/195#issuecomment-193996353.

cmallwitz avatar Mar 08 '16 22:03 cmallwitz

Some further information for files containing # or % opened using (right mouse click) context menu - open: this hits associations.py open_file() line 212

For example file name /home/user/foo#bar.txt this is being turned into file:///home/user/foo#bar.txt - note: '#' and '%' have special meaning in a URI and therefore the file name is misinterpreted when gedit tries to use Gio to open the file (based on URI).

URL encoding special characters as in file:///home/user/foo%23bar.txt fixes the issue. Same with % being replaced with %25 first.

A more generic fix would be wrapping selections/paths using urllib.pathname2url() before prefixing it with file://

Any other suggestions? If not I can submit a fix.

cmallwitz avatar Mar 12 '16 23:03 cmallwitz

@cmallwitz sorry for delayed response. Basically paths should be URL encoded only if they are in form of URI complete with file://. We shouldn't blindly apply URL encode to all paths, instead we should see if while being executed application requires URI or path. As for using Ctrl+C/V (clipboard operations) as well with drag and drop we should universally use URIs.

MeanEYE avatar Mar 28 '16 23:03 MeanEYE

I completely agree with only encoding paths if the are URI complete with file:// - My fix is below and applicable in this situation:

diff --git a/application/associations.py b/application/associations.py index 75857b2..03a434b 100644 --- a/application/associations.py +++ b/application/associations.py @@ -209,7 +209,7 @@ class AssociationManager:

        if application is not None:
            if application.supports_uris():
  •               selection = map(lambda path: 'file://{0}'.format(path) if not path.startswith('file://') else path, selection)
    
  •               selection = map(lambda path: 'file://{0}'.format(urllib.pathname2url(path)) if not path.startswith('file://') else path, selection)
                application.launch_uris(selection)
            else:
                application.launch([Gio.File.new_for_path(path) for path in selection])
    

cmallwitz avatar Mar 30 '16 19:03 cmallwitz

This isn't pretty - I'm only suggesting changing one line - from:

selection = map(lambda path: 'file://{0}'.format(path) if not path.startswith('file://') else path, selection)

to:

selection = map(lambda path: 'file://{0}'.format(urllib.pathname2url(path)) if not path.startswith('file://') else path, selection)

cmallwitz avatar Mar 30 '16 19:03 cmallwitz

I think we should switch from manually formatting strings to using urllib and possible check if GTK application class has some sort of format parameters and get command line. Perhaps even execute with params.

MeanEYE avatar Apr 01 '16 08:04 MeanEYE

Submitted PR #216 to fix issue - fix is using urllib for formatting and only if required.

cmallwitz avatar Apr 01 '16 18:04 cmallwitz

This can be closed now.

cmallwitz avatar Sep 28 '16 18:09 cmallwitz

@MeanEYE This issue can be closed, as it is fixed in develop branch.

joshas avatar Jul 10 '19 18:07 joshas