xdg-mime does not handle whitespace in .desktop file names correctly
Submitted by Vladimir Panteleev
Assigned to Portland Bugs
Link to original bug (#101039)
Description
On my system, running:
$ xdg-open http://google.com
Prints this to stderr:
/usr/sbin/xdg-mime: line 323: [: too many arguments /usr/sbin/xdg-mime: line 325: [: too many arguments
xdg-mime at line 323 looks like this:
if [ -r $dir/applications/$vendor/$app ]; then
file_path=$dir/applications/$vendor/$app
elif [ -r $dir/applnk/$vendor/$app ]; then
file_path=$dir/applnk/$vendor/$app
fi
It looks like xdg-mime does not properly quote variables before expansion, which makes them subject to globbing and word splitting.
The particular file that causes xdg-mime to misbehave is:
/home/vladimir/.local/share/applications/userapp-Firefox Developer Edition-ZN8AEY.desktop
I'm not sure what created it, but it does have spaces in the file name.
Regardless of whether spaces are allowed in such file names, not quoting variables that are not intended to be expanded is a bug.
I strongly recommend linting shell scripts with ShellCheck (http://www.shellcheck.net/) to prevent bugs like this one.