[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE_3_1_BRANCH: kdelibs/kdecore
From:       Waldo Bastian <bastian () kde ! org>
Date:       2003-09-15 12:58:54
[Download RAW message or body]

CVS commit by waba: 

Second attempt to clean path.


  M +35 -7     kurl.cpp   1.223.2.7


--- kdelibs/kdecore/kurl.cpp  #1.223.2.6:1.223.2.7
@@ -272,8 +272,35 @@ static QString decode(const QString &seg
 }
 
-static QString cleanpath(const QString &path, bool cleanDirSeparator=true)
+static QString cleanpath(const QString &_path, bool cleanDirSeparator, bool decodeDots)
 {
-  if (path.isEmpty()) return QString::null;
+  if (_path.isEmpty()) return QString::null;
+  
+  if (_path[0] != '/')
+     return _path; // Don't mangle mailto-style URLs
+  
+  QString path = _path;
+
   int len = path.length();
+
+  if (decodeDots)
+  {
+#ifndef KDE_QT_ONLY
+     static const QString &encodedDot = KGlobal::staticQString("%2e");
+#else
+     QString encodedDot("%2e");
+#endif
+     if (path.find(encodedDot, 0, false) != -1)
+     {
+#ifndef KDE_QT_ONLY
+        static const QString &encodedDOT = KGlobal::staticQString("%2E"); // Uppercase!
+#else
+        QString encodedDOT("%2E");
+#endif
+        path.replace(encodedDot, ".");
+        path.replace(encodedDOT, ".");
+        len = path.length();
+     }
+  }
+
   bool slash = (len && path[len-1] == '/') ||
                (len > 1 && path[len-2] == '/' && path[len-1] == '.');
@@ -514,4 +541,5 @@ KURL::KURL( const KURL& _u, const QStrin
        m_strPass = _u.m_strPass;
     }
+    cleanPath(false);
   }
 }
@@ -953,8 +981,8 @@ bool KURL::isParentOf( const KURL& _u ) 
         return false; // can't work with implicit paths
 
-    QString p1( cleanpath( path() ) );
+    QString p1( cleanpath( path(), true, false ) );
     if ( p1[p1.length()-1] != '/' )
         p1 += '/';
-    QString p2( cleanpath( _u.path() ) );
+    QString p2( cleanpath( _u.path(), true, false ) );
     if ( p2[p2.length()-1] != '/' )
         p2 += '/';
@@ -1010,7 +1038,7 @@ void KURL::setFileName( const QString& _
 void KURL::cleanPath( bool cleanDirSeparator ) // taken from the old KURL
 {
-  m_strPath = cleanpath(m_strPath, cleanDirSeparator);
+  m_strPath = cleanpath(m_strPath, cleanDirSeparator, false);
   // WABA: Is this safe when "/../" is encoded with %?
-  m_strPath_encoded = cleanpath(m_strPath_encoded, cleanDirSeparator);
+  m_strPath_encoded = cleanpath(m_strPath_encoded, cleanDirSeparator, true);
 }
 
@@ -1521,5 +1549,5 @@ bool KURL::cd( const QString& _dir )
   QString p = path(1);
   p += _dir;
-  p = cleanpath( p );
+  p = cleanpath( p, true, false );
   setPath( p );
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic