Skip to content

Conversation

@okaestne
Copy link
Contributor

Automatically add quotes if selected filepath contains spaces.

fixes linuxmint/cinnamon-settings-daemon#363

Automatically add quotes if selected filepath contains spaces.

fixes linuxmint/cinnamon-settings-daemon#363
if response == Gtk.ResponseType.ACCEPT:
name = chooser.get_filename()
if " " in name:
name = '"' + name + '"'
Copy link
Member

Choose a reason for hiding this comment

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

Can we just use GLib.shell_quote() here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I understand the fd.o specs, we need to use double quotes. I didn't use GLib.shell_quote or shlex.quote because they both returned single quoted strings in my testing.

Copy link
Member

Choose a reason for hiding this comment

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

Both work, but single quotes are safer, as their contents are taken literally.

Copy link
Contributor Author

@okaestne okaestne Dec 5, 2025

Choose a reason for hiding this comment

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

I spent quite some time to read the fd.o spec [1], which is pretty clear:

Arguments may be quoted in whole. If an argument contains a reserved character the argument must be quoted. The rules for quoting of arguments is also applicable to the executable name or path of the executable program as provided.

Quoting must be done by enclosing the argument between double quotes and escaping the double quote character, backtick character ("`"), dollar sign ("$") and backslash character ("") by preceding it with an additional backslash character. Implementations must undo quoting before expanding field codes and before passing the argument to the executable program. Reserved characters are space (" "), tab, newline, double quote, single quote ("'"), backslash character (""), greater-than sign (">"), less-than sign ("<"), tilde ("~"), vertical bar ("|"), ampersand ("&"), semicolon (";"), dollar sign ("$"), asterisk ("*"), question mark ("?"), hash mark ("#"), parenthesis ("(") and (")") and backtick character ("`").

This is why I explicitly tried to avoid single quotes. All .desktop files I found used double quotes if they used quotes.

[1] https://specifications.freedesktop.org/desktop-entry/latest/exec-variables.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Startup Applications - Custom Command Browse leaves spaces in file paths

2 participants