lxqt / libqtxdg

Qt implementation of freedesktop.org xdg specs
https://lxqt.github.io
GNU Lesser General Public License v2.1
72 stars 35 forks source link

Unneeded URL encoding for %U/%u in .desktop? #229

Closed yan12125 closed 3 years ago

yan12125 commented 3 years ago
Expected Behavior

Running the following commands from the terminal (QTerminal in my case) should open the directory foo bar in pcmanfm-qt (my default file manager)

$ mkdir "foo bar"
$ qtxdg-mat open "foo bar"
Current Behavior

A dialog with error message

Error when getting information for file “/home/yen/tmp/foo%20bar”: No such file or directory
Possible Solution

This is how everything goes:

  1. pcmanfm-qt.desktop has Exec=pcmanfm-qt %U
  2. XdgDesktopFile::expandExecString() create a QUrl from /home/yen/tmp/foo bar for %U [1]
  3. In the next line, url.toEncoded() is called and the result is a non-existent path. This happens as toLocalFile() returns an empty string for URLs without file: scheme. [2]

I'm not sure what should be the fix. Adding file: when needed? Just don't call .toEncoded() and hope applications always encode URLs?

[1] https://github.com/lxqt/libqtxdg/blob/0133926cfed4f2f1c1e407b3592786db6cf85ed1/src/qtxdg/xdgdesktopfile.cpp#L1133-L1134 [2] https://doc.qt.io/qt-5/qurl.html

Steps to Reproduce (for bugs)

(See above)

Context

Noticed this bug when I tried to switch from alias open=xdg-open to alias open="qtxdg-mat open"

System Information
tsujan commented 3 years ago

Confirming. pcmanfm-qt "foo bar" works but qtxdg-mat open "foo bar" gives the above-mentioned error, here too.

tsujan commented 3 years ago

xdg-open "foo bar" works fine too. So, libqtxdg needs a fix.

luis-pereira commented 3 years ago

Probably I'm doing something wrong

[lpereira@manjaro ~]$ xdg-open "Desktop Documents"
xdg-open: file 'Desktop Documents' does not exist

and

pcmanfm-qt "Desktop Documents"

get me this: screen2

tsujan commented 3 years ago

@luis-pereira

In @yan12125's example, the folder "foo bar" exists but qtxdg-mat can't open it.

luis-pereira commented 3 years ago

@tsujan Thanks!. I didn't read the mkdir ...... I was right.... I was doing something wrong. ;)

luis-pereira commented 3 years ago

I'm not sure what should be the fix. Adding file: when needed? Just don't call .toEncoded() and hope applications always encode URLs?

We can't rely on others good behavior. Some tweak in checking if the file is local and some minor changes should do it. Implementing it tomorrow.

luis-pereira commented 3 years ago

@yan12125 Can you pls take a look at the draft PR at https://github.com/lxqt/libqtxdg/pull/232 ?