Bug 474758 - Executable with space in path mis-quoted when writing Exec line in .desktop file
Summary: Executable with space in path mis-quoted when writing Exec line in .desktop file
Status: RESOLVED FIXED
Alias: None
Product: kmenuedit
Classification: Applications
Component: general (show other bugs)
Version: 5.27.8
Platform: Other Linux
: VHI major
Target Milestone: ---
Assignee: Plasma Bugs List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-09-21 08:08 UTC by Igor Mironchik
Modified: 2023-09-28 22:08 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.27.9
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Igor Mironchik 2023-09-21 08:08:17 UTC
SUMMARY

Added by hands application in system menu with space in path cannot be invoked to open a file with that application.


STEPS TO REPRODUCE
1. Add a new application by hands in system menu with space in a path to a executable.
2. Assign this new application to open some file type with its.
3. Double click on that file type in Dolphin or Krusader.

OBSERVED RESULT

You will see a message that application cannot be found.

EXPECTED RESULT

Application should being launched and open selected file.

SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: KDE neon 5.27
(available in About System)
KDE Plasma Version: 5.27.8
KDE Frameworks Version: 5.110.0
Qt Version: 5.15.10

ADDITIONAL INFORMATION
Comment 1 Nate Graham 2023-09-21 15:59:26 UTC
When you write out a file path by hand, it's up to you to ensure that spaces and other historically special characters are escaped properly, or that the path is quoted.
Comment 2 Igor Mironchik 2023-09-21 16:10:44 UTC
You are wrong! I didn't write path by hands, I did it with "Menu Editor", I added new menu entry by hands, but I set path to executable with file dialog!!!
Comment 3 Igor Mironchik 2023-09-21 16:13:41 UTC
I will record a GIF, give me some time.
Comment 4 Igor Mironchik 2023-09-21 16:42:47 UTC
GIF poof - https://i.ibb.co/TMpR2B9/bug.gif
Comment 5 Igor Mironchik 2023-09-21 16:43:05 UTC
*proof :)
Comment 6 Nate Graham 2023-09-21 22:15:44 UTC
Ok, my mistake. It looks like it is quoting the path properly when you select it that file using the file dialog. Or at least it looks like it!

Can you select the entire contents of the text that was added to the "Program" text field, copy it, paste it into a terminal window, and hit Return? Does it run? If not, what's the error message?
Comment 7 Igor Mironchik 2023-09-22 04:28:50 UTC
Text in the "Program" filed is '/home/igor/Markdown Tools/bin/md-editor'

It launches from terminal without any problem.
Comment 8 Nate Graham 2023-09-25 21:35:17 UTC
Thank you, that's very helpful. I can reproduce the bug now with git master of KF6 too. The exact error message I see in the journal log is:

> kf.kio.gui: "Could not find the program ''/home/nate/Markdown Tools/foo.sh''"

Looks like some bad quoting, maybe? When I open the .desktop file that I constructed, I see the following:

> Exec=''\\''/home/nate/Markdown Tools/foo.sh'\\'''

If I remove the excess quotes and backslashes and change it to this:

> Exec='/home/nate/Markdown Tools/foo.sh'

Then it works. Méven, would you be able to take a look here?
Comment 9 Nate Graham 2023-09-25 21:36:43 UTC
Also Igor, note that you'll want to change your exec line in KMenuEdit to `/home/igor/Markdown Tools/bin/md-editor %F` to make it pass the file path of the file to `md-editor`. See https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s07.html.
Comment 11 Bug Janitor Service 2023-09-26 09:40:17 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kmenuedit/-/merge_requests/27
Comment 12 Méven 2023-09-27 14:01:27 UTC
Git commit 90ddeb9f2fd05529c4cda97502faa094adf7f9cc by Méven Car.
Committed on 27/09/2023 at 12:02.
Pushed by meven into branch 'master'.

Better construct command line

After 87c38a30fff27e3e9c0375f5c17d53ab0644ea0f the executable was KShell::joinArgs but it wasn't need.

M  +12   -5    basictab.cpp

https://invent.kde.org/plasma/kmenuedit/-/commit/90ddeb9f2fd05529c4cda97502faa094adf7f9cc
Comment 13 Méven 2023-09-28 12:56:12 UTC
Git commit 91133087ae39f05ac837f93cb4fcfcd32d3b8308 by Méven Car.
Committed on 28/09/2023 at 14:55.
Pushed by meven into branch 'Plasma/5.27'.

Better construct command line

After 87c38a30fff27e3e9c0375f5c17d53ab0644ea0f the executable was KShell::joinArgs but it wasn't need.

(cherry picked from commit 90ddeb9f2fd05529c4cda97502faa094adf7f9cc)

M  +12   -5    basictab.cpp

https://invent.kde.org/plasma/kmenuedit/-/commit/91133087ae39f05ac837f93cb4fcfcd32d3b8308