diff options
author | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2023-12-04 16:51:29 +0200 |
---|---|---|
committer | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2023-12-05 22:03:55 +0200 |
commit | 82a40f084b8ddb5f7f11d49f3296df9dba359301 (patch) | |
tree | 0fd5ffaa42cc6157c2e517b3c780294887090645 /src/tools | |
parent | 66a5f9fdd40485a4e64d447f84046698b7cacae3 (diff) |
AndroidTestRunner: fix args with quotes and spaces
First, replace double quote characters with 3 escaped double quotes
to allow QProcess::splitCommand() to treat it as an actual quote
character that's part of the tag.
Then, escape single quote characters so they don't interfere with
the shell command and also to be treated as part of the argument.
Lastly, surround the args with escaped double quote so that args
with spaces are also treated as one.
Amends b044323c1656aeeec508afab8457755cc1e8c587.
Example of this:
tst_qkeyevent::modifiers("M","e","t","a") for double quotes
tst_qunicodetools::wordBreakClass(two words) for spaces
tst_QSpinBox::stepSelectAll("don't select all") for single quotes
Task-number: QTQAINFRA-5703
Change-Id: Ie4317e4350bbac619bac41e41f42613f50cf1ad4
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/androidtestrunner/main.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/tools/androidtestrunner/main.cpp b/src/tools/androidtestrunner/main.cpp index 365ddab79e..03a38d0ec7 100644 --- a/src/tools/androidtestrunner/main.cpp +++ b/src/tools/androidtestrunner/main.cpp @@ -368,7 +368,14 @@ static bool parseTestArgs() if (match.hasMatch()) { logType = match.capturedTexts().at(1); } else { - unhandledArgs << " %1"_L1.arg(arg); + // Use triple literal quotes so that QProcess::splitCommand() in androidjnimain.cpp + // keeps quotes characters inside the string. + QString quotedArg = QString(arg).replace("\""_L1, "\\\"\\\"\\\""_L1); + // Escape single quotes so they don't interfere with the shell command, + // and so they get passed to the app as single quote inside the string. + quotedArg.replace("'"_L1, "\'"_L1); + // Add escaped double quote character so that args with spaces are treated as one. + unhandledArgs << " \\\"%1\\\""_L1.arg(quotedArg); } } } @@ -380,7 +387,7 @@ static bool parseTestArgs() testAppArgs += "-o output.%1,%1 "_L1.arg(format); testAppArgs += unhandledArgs.join(u' ').trimmed(); - testAppArgs = "'%1'"_L1.arg(testAppArgs); + testAppArgs = "\"%1\""_L1.arg(testAppArgs); const QString activityName = "%1/%2"_L1.arg(g_options.package).arg(g_options.activity); // Pass over any testlib env vars if set |