A few questions about escaping in desktop files

meator meator.dev at gmail.com
Wed Aug 24 08:24:49 UTC 2022


On 8/23/22 16:30, Simon McVittie wrote:
> That wording seems strange when compared with how GLib implements it,
> but again, I didn't write this spec; all I can tell you is what one
> of the implementations that have been in daily use for many years is
> doing. Perhaps GLib is relying on the "as-if" rule, or perhaps the spec
> doesn't match reality, or perhaps the spec author meant something that
> is not how we're interpreting it.

Some of my questions still remain unanswered. But I'm not going to 
complain, passing the work to the shell significantly simplifies the 
code logic.

> Because GLib is substituting the field codes before doing shell-style
> parsing, it would be wrong for it not to quote the expansion of the field
> codes. If it didn't quote the expansion of the field codes, then the
> shell-style parsing would give it the wrong answer, because not every
> character in a shell-style string represents itself: some are metacharacters
> with a special meaning, like quotes and spaces.

Thanks, now I understand. My current plan is:
a) Expand the basic \s, \n, \t, \r, and \\ while parsing the desktop files.
b) Substitute the field codes with a quoted version of them (I 
personally put it in double quotes and then escape $, `, " and \ instead 
of using single quotes and then doing '"'"' for single quotes). This 
ensures that the shell won't do anything unexpected with it and that 
there will be the correct number of arguments as the spec requires:

 > Implementations must take care not to expand field codes into 
multiple arguments unless explicitly instructed by this specification. 
This means that name fields, filenames and other replacements that can 
contain spaces must be passed as a single argument to the executable 
program after expansion.

c) Pass it to the shell. This gets pretty interesting when 
Terminal=true. I have to do execlp(emulator, emulator, "-e", shell, 
"-c", exec, (char *) NULL). For example for Htop with xterm and /bin/sh: 
"xterm -e /bin/sh -c htop". That is the terminal emulator executing 
shell executing the program. Heh.

> For the GNOME side, all you'd really need is the GLib library, not
> any GUIs. GDesktopAppInfo objects are responsible for handling .desktop
> files.

Thanks! You helped me understand the standard better.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 659 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/xdg/attachments/20220824/19018efc/attachment.sig>


More information about the xdg mailing list