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>
This commit is contained in:
Assam Boudjelthia 2023-12-04 16:51:29 +02:00
parent 66a5f9fdd4
commit 82a40f084b
2 changed files with 10 additions and 5 deletions

View File

@ -449,9 +449,7 @@ static jboolean startQtAndroidPlugin(JNIEnv *env, jobject /*object*/, jstring pa
m_androidContentFileEngineHandler = new AndroidContentFileEngineHandler();
m_mainLibraryHnd = nullptr;
// QProcess::splitCommand() treats triple quotes as the quote character itself.
QString params = QJniObject(paramsString).toString().replace("\""_L1, "\"\"\""_L1);
const QStringList argsList = QProcess::splitCommand(params);
const QStringList argsList = QProcess::splitCommand(QJniObject(paramsString).toString());
for (const QString &arg : argsList)
m_applicationParams.append(arg.toUtf8());

View File

@ -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