[Portland-bugs] [Bug 86340] New: xdg-open does not handle x-schemes with no URL correctly (suggested PATCH)
bugzilla-daemon at freedesktop.org
bugzilla-daemon at freedesktop.org
Sun Nov 16 03:20:55 PST 2014
https://bugs.freedesktop.org/show_bug.cgi?id=86340
Bug ID: 86340
Summary: xdg-open does not handle x-schemes with no URL
correctly (suggested PATCH)
Product: Portland
Version: 1.1.0 rc2
Hardware: All
OS: Linux (All)
Status: NEW
Severity: normal
Priority: medium
Component: xdg-utils
Assignee: portland-bugs at lists.freedesktop.org
Reporter: infinite.craziness at gmail.com
I want tp use xdg-open to open my default browser or email-client by doing e.g.
xdg-open http: or xdg-open mailto:
If I do that, (in the former case) it opens the browser an empty page with the
http:// URL and the error 'Page not found' (of course)
Here follows the fix, it needed some fixing on argument quoting (since of the
arg is empty, it must not be quoted at all). I took the opportunity to fix bug
66670 and change the quoting around the user's argument to single rather than
double (it also takes care of single quotes present in it).
Also, first_word was defined twice (once in the beginning and once later one
along with last_word) - moved definition of both to the beginning
And lastly, binary_to_desktop_file handled the deprecated applnk location, but
nowhere else in the script was this supported - added it to all the other
functions
--- xdg-open 2014-11-16 12:14:06.587351388 +0200
+++ xdg-open.fix 2014-11-16 13:08:47.224959973 +0200
@@ -132,6 +132,12 @@
echo "$first"
}
+last_word()
+{
+ read first rest
+ echo "$rest"
+}
+
#-------------------------------------------------------------
# map a binary to a .desktop file
binary_to_desktop_file()
@@ -172,14 +178,16 @@
IFS=:
for dir in $search; do
unset IFS
- [ "$dir" ] && [ -d "$dir/applications" ] || continue
- file="$dir/applications/$desktop"
- [ -r "$file" ] || continue
- # Remove any arguments (%F, %f, %U, %u, etc.).
- command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- |
first_word`"
- command="`which "$command"`"
- readlink -f "$command"
- return
+ [ "$dir" ] || continue
+ [ -d "$dir/applications" ] || [ -d "$dir/applnk" ] || continue
+ for file in "$dir"/applications/*.desktop
"$dir"/applications/*/*.desktop "$dir"/applnk/*.desktop
"$dir"/applnk/*/*.desktop; do
+ [ -r "$file" ] || continue
+ # Remove any arguments (%F, %f, %U, %u, etc.).
+ command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- |
first_word`"
+ command="`which "$command"`"
+ readlink -f "$command"
+ return
+ done
done
}
@@ -454,19 +462,6 @@
return 0
}
-# This handles backslashes but not quote marks.
-first_word()
-{
- read first rest
- echo "$first"
-}
-
-last_word()
-{
- read first rest
- echo "$rest"
-}
-
open_darwin()
{
open "$1"
@@ -572,10 +567,12 @@
command_exec=`which $command 2>/dev/null`
arguments="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- |
last_word`"
arg_one="`echo "$arg" | sed 's/[&*\\]/\\\\&/g'`"
- arguments_exec="`echo "$arguments" | sed -e
's*%[fFuU]*"'"$arg_one"'"*g'`"
+ arg_one="`echo "$arg" | sed \"s/'/'\\\"'\\\"'/g\"`"
+ [ -n "$arg_one" ] && arg_one="'$arg_one'"
+ arguments_exec="`echo "$arguments" | sed -e 's*%[fFuU]*'"$arg_one"'*g'`"
if [ -x "$command_exec" ] ; then
- if echo "$arguments" | grep -iq '%[fFuU]' ; then
+ if echo "$arguments" | grep -iq '%[fu]' ; then
echo START "$command_exec" "$arguments_exec"
eval "$command_exec" "$arguments_exec"
else
@@ -600,15 +597,13 @@
filetype="$2"
default=`xdg-mime query default "$filetype"`
if [ -n "$default" ] ; then
- xdg_user_dir="$XDG_DATA_HOME"
- [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share"
-
- xdg_system_dirs="$XDG_DATA_DIRS"
- [ -n "$xdg_system_dirs" ] ||
xdg_system_dirs=/usr/local/share/:/usr/share/
+ [ -n "$XDG_DATA_HOME" ] && xdg_user_dir="$XDG_DATA_HOME" ||
xdg_user_dir="$HOME/.local/share"
+ [ -n "$XDG_DATA_DIRS" ] && xdg_system_dirs="$XDG_DATA_DIRS" ||
xdg_system_dirs=/usr/local/share/:/usr/share/
DEBUG 3 "$xdg_user_dir:$xdg_system_dirs"
for x in `echo "$xdg_user_dir:$xdg_system_dirs" | sed 's/:/ /g'`; do
- search_desktop_file "$default" "$x/applications/" "$1"
+ [ -d "$x/applications/" ] && search_desktop_file "$default"
"$x/applications/" "$1"
+ [ -d "$x/applnk/" ] && search_desktop_file "$default" "$x/applnk/"
"$1"
done
fi
}
@@ -622,9 +617,11 @@
open_generic_xdg_x_scheme_handler()
{
scheme="`echo $1 | sed -n 's/\(^[[:alnum:]+\.-]*\):.*$/\1/p'`"
+ uri="`echo $1 | sed -n 's/^[[:alnum:]+\.-]*:\/\{1,\}//p'`"
if [ -n $scheme ]; then
filetype="x-scheme-handler/$scheme"
- open_generic_xdg_mime "$1" "$filetype"
+ [ -n "$uri" ] && open_generic_xdg_mime "$1" "$filetype"
+ open_generic_xdg_mime "" "$filetype"
fi
}
--
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/portland-bugs/attachments/20141116/1e726d97/attachment.html>
More information about the Portland-bugs
mailing list