diff options
Diffstat (limited to 'src/tools/androidtestrunner/main.cpp')
-rw-r--r-- | src/tools/androidtestrunner/main.cpp | 73 |
1 files changed, 2 insertions, 71 deletions
diff --git a/src/tools/androidtestrunner/main.cpp b/src/tools/androidtestrunner/main.cpp index efcc6ed7bc..3b9e53a5a5 100644 --- a/src/tools/androidtestrunner/main.cpp +++ b/src/tools/androidtestrunner/main.cpp @@ -39,6 +39,8 @@ #include <functional> #include <thread> +#include <shellquote_shared.h> + #ifdef Q_CC_MSVC #define popen _popen #define QT_POPEN_READ "rb" @@ -189,77 +191,6 @@ static bool execCommand(const QString &command, QByteArray *output = nullptr, bo return pclose(process) == 0; } -// Copy-pasted from qmake/library/ioutil.cpp -inline static bool hasSpecialChars(const QString &arg, const uchar (&iqm)[16]) -{ - for (int x = arg.length() - 1; x >= 0; --x) { - ushort c = arg.unicode()[x].unicode(); - if ((c < sizeof(iqm) * 8) && (iqm[c / 8] & (1 << (c & 7)))) - return true; - } - return false; -} - -static QString shellQuoteUnix(const QString &arg) -{ - // Chars that should be quoted (TM). This includes: - static const uchar iqm[] = { - 0xff, 0xff, 0xff, 0xff, 0xdf, 0x07, 0x00, 0xd8, - 0x00, 0x00, 0x00, 0x38, 0x01, 0x00, 0x00, 0x78 - }; // 0-32 \'"$`<>|;&(){}*?#!~[] - - if (!arg.length()) - return QStringLiteral("\"\""); - - QString ret(arg); - if (hasSpecialChars(ret, iqm)) { - ret.replace(u'\'', QStringLiteral("'\\''")); - ret.prepend(u'\''); - ret.append(u'\''); - } - return ret; -} - -static QString shellQuoteWin(const QString &arg) -{ - // Chars that should be quoted (TM). This includes: - // - control chars & space - // - the shell meta chars "&()<>^| - // - the potential separators ,;= - static const uchar iqm[] = { - 0xff, 0xff, 0xff, 0xff, 0x45, 0x13, 0x00, 0x78, - 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x10 - }; - - if (!arg.length()) - return QStringLiteral("\"\""); - - QString ret(arg); - if (hasSpecialChars(ret, iqm)) { - // Quotes are escaped and their preceding backslashes are doubled. - // It's impossible to escape anything inside a quoted string on cmd - // level, so the outer quoting must be "suspended". - ret.replace(QRegularExpression(QStringLiteral("(\\\\*)\"")), QStringLiteral("\"\\1\\1\\^\"\"")); - // The argument must not end with a \ since this would be interpreted - // as escaping the quote -- rather put the \ behind the quote: e.g. - // rather use "foo"\ than "foo\" - qsizetype i = ret.length(); - while (i > 0 && ret.at(i - 1) == u'\\') - --i; - ret.insert(i, u'"'); - ret.prepend(u'"'); - } - return ret; -} - -static QString shellQuote(const QString &arg) -{ - if (QDir::separator() == u'\\') - return shellQuoteWin(arg); - else - return shellQuoteUnix(arg); -} - static bool parseOptions() { QStringList arguments = QCoreApplication::arguments(); |