Bug 53886 - klipper inserts single quotes around URLs when trying to open in Mozilla
Summary: klipper inserts single quotes around URLs when trying to open in Mozilla
Status: RESOLVED FIXED
Alias: None
Product: klipper
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Mandrake RPMs Linux
: NOR normal
Target Milestone: ---
Assignee: Dirk Mueller
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-02-02 09:58 UTC by Jeremy Smith
Modified: 2003-05-30 04:08 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
Fix mozilla remote action. (672 bytes, patch)
2003-04-17 00:23 UTC, Roger Standridge
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jeremy Smith 2003-02-02 09:58:34 UTC
Version:            (using KDE KDE 3.1)
Installed from:    Mandrake RPMs
OS:          Linux

When actions are enabled and a URL is highlighted (put into the clipboard), and "Open with Mozilla" is selected, Mozilla gets an error "URL is invalid and cannot be loaded" as it tries to open the URL, and the URL shows up in the location bar as having single quotes.

This bug is mentioned on the freebsd/kde bug site (http://freebsd.kde.org/bugs.shtml)  but I found no mention of it anywhere else.
Comment 1 Jeremy Smith 2003-02-02 10:00:09 UTC
Sorry, I must have selected the wrong option for "Installed from."  I installed
via the Redhat 7.3 RPM's at kde-redhat.sourceforge.net
Comment 2 George Staikos 2003-02-13 05:24:18 UTC
Please give a url that exhibits this behaviour.  i cannot reproduce it on Linux with 
KDE-3.1-BRANCH (CVS) 
 
 
Comment 3 Jeremy Smith 2003-02-13 05:53:51 UTC
I exhibit this behavior on all URLs, when attempting to open in mozilla. 
Mozilla version is 1.0.1, Klipper version is 0.9.5

Comment 4 jan grant 2003-02-14 17:14:56 UTC
Mozilla 1.2.1, freebsd -stable, klipper 0.9.5/kde 3.1.0

The problem exists here too, all URLs. However, I found no such quoting problems
when I changed the action to,
      /home/jan/bin/startmoz "%s"

Which is the following script:

[[
#!/bin/sh

PATH=/usr/bin:/bin:/usr/local/bin:/usr/X11R6/bin
export PATH
echo "My parameters are: $*" >> /home/jan/tmp/startmoz.log
(ps x |grep -q '[m]ozilla' && mozilla -remote "openURL($1, new-window)" || \
mozilla "$1") 1>>/home/cmjg/tmp/startmoz.log 2> &1 &
]]
Comment 5 Jeremy Smith 2003-03-01 12:08:27 UTC
I was able to get around this by changing:
ps x |grep -q '[m]ozilla' && mozilla -remote "openURL(%s, new-window)" || mozilla %s
to
ps x |grep -q '[m]ozilla' && mozilla -remote "openURL(`echo %s`, new-window)" ||
mozilla %s
apparently klipper surrounds the clipboard contents with ' and mozilla's openURL
can't handle it anymore.

Jer
Comment 6 Roger Standridge 2003-04-17 00:23:26 UTC
Created attachment 1375 [details]
Fix mozilla remote action.
Comment 7 Roger Standridge 2003-04-17 00:37:51 UTC
I just ran into this same bug and spent some time fixing it.  I see the status
of this bug is still 'UNCONFIRMED' so I will supply some version information
regarding my own setup that reproduced this:

System : Debian Sid
Debian Klipper Version : 4:3.1.1-1
Debian mozilla-browser Version : 2:1.3-4 (Mozilla 1.3)

Steps to reproduce : 
1) Shut down all instances of Mozilla
2) select text http://www.google.com
3) Select 'Open with Mozilla' from klipper popup window
4) observe Mozilla opens to http://www.google.com
4a) - leave mozilla running -
5) select text http://rws.dnsalias.net
6) select 'Open with Mozilla' from klipper popup window
7) witness Mozilla window 'The URL is not valid and cannot be loaded.'
8) click 'Ok'
9) witness new mozilla window with the text 'http://rws.dnsalias.net'
   (including single quote characters) in location bar

I have attached a patch which I belive will fix this problem.

Perhaps mozilla should accept URLs surrounded by single quote characters. I also
think however that this should be fixed in klipper, if only because it is more
correct.
Comment 8 Roger Standridge 2003-04-17 00:42:00 UTC
BTW, the above patch is against KDE_3_1_BRANCH, file obtained from :

http://webcvs.kde.org/cgi-bin/cvsweb.cgi/kdebase/klipper/klipperrc.desktop?rev=1.81.2.3&content-type=text/x-cvsweb-markup
Comment 9 Lutz Maibaum 2003-04-27 07:30:04 UTC
I have this problem with all URLs, using Mozilla 1.3 and Klipper 0.95. Mozilla
gives the mentioned error message, but in my case the new tab is just empty and
has 'about:blank' in the address bar.

Jeremy's workaround (comment #5) worked for me.
Comment 10 Fergal Daly 2003-05-28 16:25:17 UTC
This has nothing to do with Mozilla. Klipper inserts single quotes in the
command line when the %s is in double quotes, except in the case of "%s".

To see this create a command called barf

#! /bin/bash

date > /tmp/barf
echo $1 >> /tmp/barf


then set up an action with a command of

barf "hello%s"

select some text, run the action, cat /tmp/barf to get

hello'selected text'

So the bug is that klipper sometimes puts in single quotes when you don't ask
for them and there's no way to turn it off. It just happens that the action for
Mozilla brings out this bug.
Comment 11 Dirk Mueller 2003-05-28 17:32:32 UTC
ok, there are two bugs. I'll fix the one outlined in comment #10, but 
the other one is a mozilla bug and KDE != mozilla.  
Comment 12 Fergal Daly 2003-05-28 17:56:30 UTC
Just in case anyone is worried, there is no Mozilla bug, (actually, there are
lots but they aren't related to this problem).
Comment 13 Dirk Mueller 2003-05-30 04:08:19 UTC
Subject: kdebase/klipper

CVS commit by mueller: 

do proper shell escaping
CCMAIL: 53886-done@bugs.kde.org


  M +5 -25     urlgrabber.cpp   1.38


--- kdebase/klipper/urlgrabber.cpp  #1.37:1.38
@@ -25,4 +25,5 @@
 #include <netwm.h>
 #include <kstringhandler.h>
+#include <kmacroexpander.h>
 
 #include "urlgrabber.h"
@@ -225,29 +226,8 @@ void URLGrabber::execute( const struct C
 {
     if ( command->isEnabled ) {
-        QString cmdLine = command->command;
-        QString escClipData = KProcess::quote(myClipData);
-
-        // replace "%s", '%s' and %s with the clipboard contents
-        // the quotes have to be replaced as well as they might
-        // be part of config files from older klipper versions
-        // replace \%s to %s
-        int pos = 0;
-        while ( (pos = cmdLine.find("%s", pos)) >= 0 ) {
-            if ( pos > 0 && cmdLine.at( pos - 1 ) == '\\' ) {
-                cmdLine.remove( pos -1, 1 ); // \%s -> %s
-                pos++;
-            }
-            else if (pos > 0 && (cmdLine[pos - 1] == '\'' || cmdLine[pos - 1] == '"') &&
-                     pos + 2 < cmdLine.length() && cmdLine[pos + 2] == cmdLine[pos - 1]) {
-                cmdLine.replace ( pos - 1, 4, escClipData );
-                pos += escClipData.length();
-            }
-            else {
-                cmdLine.replace( pos, 2, escClipData );
-                pos += escClipData.length();
-            }
-        }
+        QMap<QChar,QString> map;
+        map.insert( 's', myClipData );
+        QString cmdLine = KMacroExpander::expandMacrosShellQuote( command->command, map );
 
-        kdDebug() << "now starting " << cmdLine << endl;
         if ( cmdLine.isEmpty() )
             return;