Strange comparison in konqueror/src/konqpixmapprovider.cpp

Jonathan Marten jjm2 at keelhaul.demon.co.uk
Fri Feb 6 12:33:23 GMT 2009


Spotted something that looks odd here while looking at another favicon
problem (bug 124482).  The fix looks reasonably simple, but since this
is in the depths of Konqueror's code I though that maybe some else had
better look at it first...

In KonqPixmapProvider::notifyChange(), when a new favicon arrives the
iconMap should be updated to reflect that.  In the case where isHost
is false, the hostOrURL parameter is the full URL of the page
including the protocol.  This means that the 3rd line of the comparison

        if ( url.protocol().startsWith("http") &&
            ( ( isHost && url.host() == hostOrURL ) ||
                ( url.host() + url.path() == hostOrURL ) ) )

can never be satisfied - url.host()+url.path() will be something like
"www.kde.org/index.html" which can never match hostOrURL in the form
"http://www.kde.org/index.html".

The following patch fixes the comparison.  Any comments?

Regards, Jonathan

------------------------------------------------------------------------
--- konqpixmapprovider.cpp      (revision 920187)
+++ konqpixmapprovider.cpp      (working copy)
@@ -131,14 +131,17 @@
 void KonqPixmapProvider::notifyChange( bool isHost, const QString& hostOrURL,
     const QString& iconName )
 {
+    KUrl u;
+    if ( !isHost ) u = KUrl(hostOrURL);
+
     for ( QMap<KUrl,QString>::iterator it = iconMap.begin();
           it != iconMap.end();
           ++it )
     {
         KUrl url( it.key() );
-        if ( url.protocol().startsWith("http") &&
-            ( ( isHost && url.host() == hostOrURL ) ||
-                ( url.host() + url.path() == hostOrURL ) ) )
+        if ( !url.protocol().startsWith("http")) continue;
+        if ( ( isHost && url.host() == hostOrURL ) ||
+             ( !isHost && url.host() == u.host() && url.path() == u.path() ) )
         {
             // For host default-icons still query the favicon manager to get
             // the correct icon for pages that have an own one.
------------------------------------------------------------------------

-- 
Jonathan Marten                         http://www.keelhaul.demon.co.uk
Twickenham, UK                          jjm2 at keelhaul.demon.co.uk




More information about the kfm-devel mailing list