Bug 15661

Summary: xdg-open breaks on spaces in paths when using generic open method
Product: Portland Reporter: John Carlyle-Clarke <jpcc>
Component: xdg-utilsAssignee: Portland Bugs <portland-bugs>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: low CC: greg.grossmeier, jw+debian
Version: unspecified   
Hardware: All   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:

Description John Carlyle-Clarke 2008-04-22 15:39:32 UTC
xdg-utils 1.0.1-2 on Ubuntu Gutsy 7.10

xdg-open tries to detect the desktop environment and falls back to a generic method using run-mailcap.  There is a bug in this function open_generic() that means if the path contains a space, the method fails.

e.g.

johncc@liberator:~$ xdg-open Fire\ stockists.txt 
local: 438: stockists.txt: bad variable name
Warning: unknown mime-type for "Fire" -- using "application/*"
Error: no such file "Fire"

To provoke this bug you need to not be running GNOME, KDE or XFCE.  In GNOME you can fake this by doing:-

unset GNOME_DESKTOP_SESSION_ID
touch file\ with\ spaces.txt
xdg-open file\ with\ spaces.txt 

The problem is just missing quotes.  A simple patch fixes it for me.

373c373
< 	local file="$(echo "$1" | sed 's%^file://%%')"
---
> 	local file=$(echo "$1" | sed 's%^file://%%')
Comment 1 Greg Grossmeier 2008-04-22 16:29:23 UTC
Confirmed this behavior in Hardy (xdg-utils 1.0.2-2) with the following:

greg@alexandria:~$echo $GNOME_DESKTOP_SESSION_ID
Default
greg@alexandria:~$unset GNOME_DESKTOP_SESSION_ID
greg@alexandria:~$echo $GNOME_DESKTOP_SESSION_ID

greg@alexandria:~$touch file\ with\ spaces.txt
greg@alexandria:~$xdg-open file\ with\ spaces.txt
local: 438: spaces.txt: bad variable name
Warning: unknown mime-type for "file" -- using "application/*"
Error: no such file "file"
greg@alexandria:~$touch file%20with%20a\ space.txt
greg@alexandria:~$ls | grep file
file%20with%20a space.txt
file with spaces.txt
greg@alexandria:~$xdg-open file%20with%20a\ space.txt
local: 438: space.txt: bad variable name
Warning: unknown mime-type for "file%20with%20a" -- using "application/*"
Error: no such file "file%20with%20a"

After an "export GNOME_DESKTOP_SESSION_ID=Default" the above xdg-open commands work as expected.
Comment 2 James Westby 2009-02-21 15:48:00 UTC
Hi,

I have tested this and it is fixed in 1.0.2

Thanks,

James

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.