Package: xdg-utils
Version: 1.1.1-1
Severity: normal
Tags: patch

I have a file ~/.local/share/applications/ssh.desktop :

--snip--------------------------------------------
[Desktop Entry]                                           
Type=Application
Encoding=UTF-8
Name=SSH
TryExec=rxvt
Exec=/home/paul/bin/ssh-launcher
NoDisplay=false
Comment=SSH launcher
--snip--------------------------------------------


~/bin/ssh-launcher contains:

--snip--------------------------------------------
#!/bin/bash

host=${1/ssh:\/\/}

exec rxvt -ls -n $1 -T $1 -e ssh $host
--snip--------------------------------------------


This is so that I can click on an ssh://ipaddress link on a webpage and
have an rxvt opened to that host. That worked fine prior to upgrading to
this version; 1.1.0~rc1+git20111210-7.3 worked fine; if I use the
xdg-open from that version then it works.

When I run bash -x xdg-open ssh://ipaddress I see:

--snip--------------------------------------------
+ for x in '`echo "$xdg_user_dir:$xdg_system_dirs" | sed '\''s/:/ /g'\''`'
+ search_desktop_file ssh.desktop /home/paul/.local/share/applications/ 
ssh://172.101.0.52
+ local default=ssh.desktop
+ local dir=/home/paul/.local/share/applications/
+ local target=ssh://172.101.0.52
+ local file=
+ '[' -r /home/paul/.local/share/applications//ssh.desktop ']'
+ file=/home/paul/.local/share/applications//ssh.desktop
+ '[' -r /home/paul/.local/share/applications//ssh.desktop ']'
++ first_word
++ get_key /home/paul/.local/share/applications//ssh.desktop Exec
++ read first rest
++ local file=/home/paul/.local/share/applications//ssh.desktop
++ local key=Exec
++ local desktop_entry=
++ IFS_='
'
++ IFS=
++ read line
++ case "$line" in
++ desktop_entry=
++ read line
++ case "$line" in
++ read line
++ case "$line" in
++ read line
++ case "$line" in
++ read line
++ case "$line" in
++ read line
++ case "$line" in
++ '[' -n '' ']'
++ read line
++ case "$line" in
++ read line
++ case "$line" in
++ read line
++ IFS='
'
++ echo ''
+ command=
++ which
+ command_exec=
++ get_key /home/paul/.local/share/applications//ssh.desktop Icon
++ local file=/home/paul/.local/share/applications//ssh.desktop
++ local key=Icon
++ local desktop_entry=
++ IFS_='
'
++ IFS=
++ read line
++ case "$line" in
++ desktop_entry=
++ read line
++ case "$line" in
++ read line
++ case "$line" in
++ read line
++ case "$line" in
++ read line
++ case "$line" in
++ read line
++ case "$line" in
++ read line
++ case "$line" in
++ read line
++ case "$line" in
++ read line
++ IFS='
'
+ icon=
++ get_key /home/paul/.local/share/applications//ssh.desktop Name
++ local file=/home/paul/.local/share/applications//ssh.desktop
++ local key=Name
++ local desktop_entry=
++ IFS_='
'
++ IFS=
++ read line
++ case "$line" in
++ desktop_entry=
++ read line
++ case "$line" in
++ read line
++ case "$line" in
++ read line
++ case "$line" in
++ '[' -n '' ']'
++ read line
++ case "$line" in
++ read line
++ case "$line" in
++ read line
++ case "$line" in
++ read line
++ case "$line" in
++ read line
++ IFS='
'
+ localised_name=
++ get_key /home/paul/.local/share/applications//ssh.desktop Exec
++ local file=/home/paul/.local/share/applications//ssh.desktop
++ local key=Exec
++ local desktop_entry=
++ IFS_='
'
++ IFS=
++ read line
++ case "$line" in
++ desktop_entry=
++ read line
++ case "$line" in
++ read line
++ case "$line" in
++ read line
++ case "$line" in
++ read line
++ case "$line" in
++ read line
++ case "$line" in
++ '[' -n '' ']'
++ read line
++ case "$line" in
++ read line
++ case "$line" in
++ read line
++ IFS='
'
++ last_word
++ read first rest
++ echo ''
+ set --
+ local args=0
+ local replaced=0
+ '[' 0 -gt 0 ']'
+ '[' 0 -eq 1 ']'
+ set -- ssh://172.101.0.52
+ '' ssh://172.101.0.52
/usr/bin/xdg-open: line 709: : command not found
+ '[' 127 -eq 0 ']'
+ for d in '$dir/*/'
+ '[' -d '/home/paul/.local/share/applications//*/' ']'
+ for x in '`echo "$xdg_user_dir:$xdg_system_dirs" | sed '\''s/:/ /g'\''`'
+ search_desktop_file ssh.desktop /usr/local/share//applications/ 
ssh://172.101.0.52
+ local default=ssh.desktop
+ local dir=/usr/local/share//applications/
+ local target=ssh://172.101.0.52
+ local file=
+ '[' -r /usr/local/share//applications//ssh.desktop ']'
++ echo ssh.desktop
++ sed -e 's|-|/|'
+ '[' -r /usr/local/share//applications//ssh.desktop ']'
+ '[' -r '' ']'
+ for d in '$dir/*/'
+ '[' -d '/usr/local/share//applications//*/' ']'
+ for x in '`echo "$xdg_user_dir:$xdg_system_dirs" | sed '\''s/:/ /g'\''`'
+ search_desktop_file ssh.desktop /usr/share//applications/ ssh://172.101.0.52
+ local default=ssh.desktop
+ local dir=/usr/share//applications/
+ local target=ssh://172.101.0.52
+ local file=
+ '[' -r /usr/share//applications//ssh.desktop ']'
++ echo ssh.desktop
++ sed -e 's|-|/|'
+ '[' -r /usr/share//applications//ssh.desktop ']'
+ '[' -r '' ']'
+ for d in '$dir/*/'
+ '[' -d /usr/share//applications//screensavers/ ']'
+ search_desktop_file ssh.desktop /usr/share//applications//screensavers/ 
ssh://172.101.0.52
+ local default=ssh.desktop
+ local dir=/usr/share//applications//screensavers/
+ local target=ssh://172.101.0.52
+ local file=
+ '[' -r /usr/share//applications//screensavers//ssh.desktop ']'
++ echo ssh.desktop
++ sed -e 's|-|/|'
+ '[' -r /usr/share//applications//screensavers//ssh.desktop ']'
+ '[' -r '' ']'
+ for d in '$dir/*/'
+ '[' -d '/usr/share//applications//screensavers//*/' ']'
+ '[' x = x ']'
+ BROWSER=www-browser:links2:elinks:links:lynx:w3m
+ '[' -n :0 ']'
+ 
BROWSER=x-www-browser:firefox:iceweasel:seamonkey:mozilla:epiphany:konqueror:chromium-browser:google-chrome:www-browser:links2:elinks:links:lynx:w3m
+ open_envvar ssh://172.101.0.52
+ local 'oldifs=
'
+ local browser browser_with_arg
+ IFS=:
+ for browser in '$BROWSER'
+ IFS='
'
+ '[' -z x-www-browser ']'
+ echo x-www-browser
+ grep -q %s
+ x-www-browser ssh://172.101.0.52
+ '[' 0 -eq 0 ']'
+ exit_success
+ '[' 0 -gt 0 ']'
+ exit 0
--snip--------------------------------------------

The old (working version) shows:
--snip--------------------------------------------
+ for x in '`echo "$xdg_user_dir:$xdg_system_dirs" | sed '\''s/:/ /g'\''`'
+ local file
+ '[' -r /home/paul/.local/share/applications/ssh.desktop ']'
+ file=/home/paul/.local/share/applications/ssh.desktop
+ '[' -r /home/paul/.local/share/applications/ssh.desktop ']'
++ sed -n 's/^Exec\(\[[^]]*\]\)\{0,1\}=//p' 
/home/paul/.local/share/applications/ssh.desktop
+ set -- /home/paul/bin/ssh-launcher
++ which /home/paul/bin/ssh-launcher
+ command_exec=/home/paul/bin/ssh-launcher
+ '[' -x /home/paul/bin/ssh-launcher ']'
+ shift
+ args=0
+ replaced=0
+ '[' 0 -gt 0 ']'
+ '[' 0 -eq 1 ']'
+ set -- ssh://172.101.0.52
+ /home/paul/bin/ssh-launcher ssh://172.101.0.52
+ '[' 0 -eq 0 ']'
+ exit_success
+ '[' 0 -gt 0 ']'
+ exit 0
--snip--------------------------------------------

The old version needs 20 lines where the new one uses 200 and fails...


I found that the problem was that there was a trailing space after
"[Desktop Entry]"... This only after adding a lot of debug echos in
the get_key function.

A fix for this is to strip trailing spaces:

--snip--------------------------------------------
--- /usr/bin/xdg-open   2015-10-05 21:19:48.000000000 +0200
+++ /tmp/xdg-open-new   2016-07-28 16:34:39.500446287 +0200
@@ -485,6 +485,7 @@
     IFS=""
     while read line
     do
+        line=$(expr "$line" : '\(.*[^ ]\) *$')
         case "$line" in
             "[Desktop Entry]")
                 desktop_entry="y"
--snip--------------------------------------------


Aside:
One other thing that I noticed when doing a quick diff between the
versions was that the function first_word() was replaced by last_word():

first_word()
{
    read first rest
    echo "$first"
}


last_word()
{
    read first rest
    echo "$rest"
}

Maybe the name of the function isn't quite right, but "read first rest"
doesn't put the last word in $rest, it puts the rest in $rest... So
*not* the last word unless there are only exactly 2: with just 1 word
it's empty.



-- System Information:
Debian Release: stretch/sid
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'oldstable'), (300, 'unstable'), 
(100, 'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.4.0-1-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

xdg-utils depends on no packages.

Versions of packages xdg-utils recommends:
ii  libfile-mimeinfo-perl  0.16-1
pn  libnet-dbus-perl       <none>
ii  libx11-protocol-perl   0.56-4
ii  x11-utils              7.7~1
ii  x11-xserver-utils      7.7~3

Versions of packages xdg-utils suggests:
un  gvfs-bin  <none>

-- no debconf information

Reply via email to