Bug 45859

Summary: xdg-open fails to open a url in a "generic" environment
Product: Portland Reporter: Göran Uddeborg <goeran>
Component: xdg-utilsAssignee: Portland Bugs <portland-bugs>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: medium CC: freedesktop.zen.ssokolow, leho, mateusz
Version: 1.1.0Keywords: patch
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments: Complete log generated with bash -xv xdg-open URL
Solution by David Costa in form of patch

Description Göran Uddeborg 2012-02-09 14:25:56 UTC
When using xdg-open on a typical URL in an environment which is considered "generic", my browser comes up with to tabs.  One shows www.http.com and the other tries to open the real URL path as a file, which fails of course.

The reason for this seems to be an improper use of IFS in the script.  The different browsers to try are separated by colons, and to easily loop over them, IFS is set to colon.  But that will also affect the colon which is typically part of the URL, and split it into two separate arguments to the browser.  See the output from running xdg-open with "bash -xv" at the end.

This is with xdg-utils-1.1.0-0.10.20111207.fc16.noarch on a Fedora system.

This output comes from running open_generic, starting at line 612 in my copy of xdg-open.  Note that x-www-browser and firefox are called with two separate arguments, rather than a single URL.

+ IFS=:
+ for browser in '$BROWSER'
+ '[' xx-www-browser '!=' x ']'
printf "$browser" "$1" 2>/dev/null
++ printf x-www-browser http://portland.freedesktop.org/
+ browser_with_arg=x-www-browser
+ '[' 0 -ne 0 ']'
+ '[' xx-www-browser = xx-www-browser ']'
+ eval '$browser $1 > /dev/null 2> /dev/null'
$browser $1 > /dev/null 2> /dev/null
++ x-www-browser http //portland.freedesktop.org/
+ '[' 127 -eq 0 ']'
+ for browser in '$BROWSER'
+ '[' xfirefox '!=' x ']'
printf "$browser" "$1" 2>/dev/null
++ printf firefox http://portland.freedesktop.org/
+ browser_with_arg=firefox
+ '[' 0 -ne 0 ']'
+ '[' xfirefox = xfirefox ']'
+ eval '$browser $1 > /dev/null 2> /dev/null'
$browser $1 > /dev/null 2> /dev/null
++ firefox http //portland.freedesktop.org/
+ '[' 0 -eq 0 ']'
+ exit_success
+ '[' 0 -gt 0 ']'
+ exit 0
Comment 1 Mateusz Loskot 2012-06-16 05:23:22 UTC
Created attachment 63106 [details]
Complete log generated with bash -xv xdg-open URL

I can confirm this bug on Arch Linux (up-to-date).

Here is relevant part of my output generated for:
bash -xv xdg-open "http://www.gnu.org"

+ IFS=:
+ for browser in '$BROWSER'
+ '[' xx-www-browser '!=' x ']'
printf "$browser" "$1" 2>/dev/null
++ printf x-www-browser http://www.gnu.org
+ browser_with_arg=x-www-browser
+ '[' 0 -ne 0 ']'
+ '[' xx-www-browser = xx-www-browser ']'
+ eval '$browser $1 > /dev/null 2> /dev/null'
$browser $1 > /dev/null 2> /dev/null
++ x-www-browser http //www.gnu.org
+ '[' 127 -eq 0 ']'
+ for browser in '$BROWSER'
+ '[' xfirefox '!=' x ']'
printf "$browser" "$1" 2>/dev/null
++ printf firefox http://www.gnu.org
+ browser_with_arg=firefox
+ '[' 0 -ne 0 ']'
+ '[' xfirefox = xfirefox ']'
+ eval '$browser $1 > /dev/null 2> /dev/null'
$browser $1 > /dev/null 2> /dev/null
++ firefox http //www.gnu.org


Notice the URL split into "http" and "//www.gnu.org" parts.

Complete log attached.


My environment:
mloskot ~ $ uname -a
Linux dog 3.4.2-2-ARCH #1 SMP PREEMPT Mon Jun 11 22:27:17 CEST 2012 x86_64 GNU/Linux

mloskot ~ $ firefox -v
Mozilla Firefox 13.0.1

mloskot ~ $ xdg-open --version
xdg-open 1.1.0 rc1
Comment 2 David Costa 2012-06-22 13:53:04 UTC
The eval parameter on line 659 is not quoted. 

The original line is:
eval '$browser $1'$xdg_redirect_output;

while it should be:
eval '$browser "$1"'$xdg_redirect_output;

Tested and working on xdg-open 1.1.0 rc1 on Arch Linux (up to date) with Mozilla Firefox 13.0.1
Comment 3 Mateusz Loskot 2012-06-24 07:15:17 UTC
(In reply to comment #2)
> while it should be:
> eval '$browser "$1"'$xdg_redirect_output;

I also can confirm it fixes the problem.
Comment 4 Sergey Shepelev 2012-08-09 09:51:13 UTC
Created attachment 65338 [details] [review]
Solution by David Costa in form of patch

I also confirm that bug exists in xdg-open 1.1.0 rc1
and that quoting $1 on line 659 fixes it. Please, apply the patch.

Thanks David Costa.
Comment 6 Göran Uddeborg 2013-01-07 14:21:01 UTC
*** Bug 44164 has been marked as a duplicate of this bug. ***
Comment 7 Rex Dieter 2014-12-15 22:38:05 UTC
*** Bug 49970 has been marked as a duplicate of this bug. ***

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.