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

List:       kde-commits
Subject:    KDE/kdeutils/ark
From:       Raphael Kubo da Costa <kubito () gmail ! com>
Date:       2010-05-08 21:05:41
Message-ID: 20100508210541.C8A1DAC8B1 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1124326 by rkcosta:

Escape file names in CliInterface when necessary.

The infrastructure has been added, and is used by the clizip plugin so
that it is now possible to extract and delete files which have
characters such as '[' or '*' correctly (infozip accepts some wild
characters to make our lives little bit more difficult).

CCBUG: 208091

 M  +30 -5     kerfuffle/cliinterface.cpp  
 M  +27 -0     kerfuffle/cliinterface.h  
 M  +3 -1      plugins/clizipplugin/cliplugin.cpp  


--- trunk/KDE/kdeutils/ark/kerfuffle/cliinterface.cpp #1124325:1124326
@@ -209,7 +209,7 @@
         if (argument == "$Files") {
             args.removeAt(i);
             for (int j = 0; j < files.count(); ++j) {
-                args.insert(i + j, files.at(j).toString());
+                args.insert(i + j, escapeFileName(files.at(j).toString()));
                 ++i;
             }
             --i;
@@ -301,10 +301,7 @@
         if (argument == "$Files") {
             args.removeAt(i);
             for (int j = 0; j < files.count(); ++j) {
-
-                //QString relativeName = QDir::current().relativeFilePath(files.at(j));
-
-                args.insert(i + j, files.at(j).toString());
+                args.insert(i + j, escapeFileName(files.at(j).toString()));
                 ++i;
             }
             --i;
@@ -653,6 +650,34 @@
         }
     }
 }
+
+QString CliInterface::escapedCharacters()
+{
+    return m_escapedCharacters;
 }
 
+void CliInterface::setEscapedCharacters(const QString& characters)
+{
+    m_escapedCharacters = characters;
+}
+
+QString CliInterface::escapeFileName(const QString& fileName)
+{
+    QString quoted;
+    const int len = fileName.length();
+    const QLatin1Char backslash('\\');
+    quoted.reserve(len * 2);
+
+    for (int i = 0; i < len; ++i) {
+        if (m_escapedCharacters.contains(fileName.at(i)))
+            quoted.append(backslash);
+
+        quoted.append(fileName.at(i));
+    }
+
+    return quoted;
+}
+
+}
+
 #include "cliinterface.moc"
--- trunk/KDE/kdeutils/ark/kerfuffle/cliinterface.h #1124325:1124326
@@ -237,6 +237,23 @@
     bool doSuspend();
     bool doResume();
 
+    /**
+     * Returns the list of characters which are preceded by a
+     * backslash when a file name in an archive is passed to
+     * a program.
+     *
+     * @see setEscapedCharacters().
+     */
+    QString escapedCharacters();
+
+    /**
+     * Sets which characters will be preceded by a backslash when
+     * a file name in an archive is passed to a program.
+     *
+     * @see escapedCharacters().
+     */
+    void setEscapedCharacters(const QString& characters);
+
 private:
     bool findProgramAndCreateProcess(const QString& program);
     void substituteListVariables(QStringList& params);
@@ -251,6 +268,14 @@
 
     void failOperation();
 
+    /**
+     * Precedes the characters returned by escapedCharacters() with a
+     * backslash in @p fileName.
+     *
+     * @param fileName String to escape.
+     */
+    QString escapeFileName(const QString& fileName);
+
     QByteArray m_stdOutData;
     bool m_userCancelled;
     QRegExp m_existsPattern;
@@ -260,6 +285,8 @@
     ParameterList m_param;
     QVariantList m_removedFiles;
 
+    QString m_escapedCharacters;
+
 private slots:
     void started();
     void readStdout(bool handleAll = false);
--- trunk/KDE/kdeutils/ark/plugins/clizipplugin/cliplugin.cpp #1124325:1124326
@@ -39,7 +39,9 @@
     explicit CliPlugin(QObject *parent, const QVariantList & args)
             : CliInterface(parent, args),
             m_status(Header) {
-
+        // #208091: infozip applies special meanings to some characters
+        //          see match.c in infozip's source code
+        setEscapedCharacters(QLatin1String("[]*?^-\\!"));
     }
 
     virtual ~CliPlugin() {
[prev in list] [next in list] [prev in thread] [next in thread] 

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