AndroidTestRunner: Fix treatement of quotes in test args

This has two parts, under testrunner, make sure to pass test args
that has quotes as \\\" so that the Android app gets a \" after parsing
the intent extras. The app args are then is passed to C++ where
QProcess::splitCommand() is used to parse the args string into a list,
and to preserve the quotes in this case, the former call expects triple
quotes to to get the quote character preserved in the split list.

Fixes: QTQAINFRA-5703
Change-Id: Iad81cadf24a6def21ef1536c882ecd510c4426cf
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
This commit is contained in:
Assam Boudjelthia 2023-11-26 12:50:45 +02:00
parent d2c29aee41
commit b044323c16
2 changed files with 9 additions and 4 deletions

View File

@ -36,6 +36,9 @@
#include <qpa/qwindowsysteminterface.h>
using namespace Qt::StringLiterals;
QT_BEGIN_NAMESPACE
static JavaVM *m_javaVM = nullptr;
@ -439,14 +442,16 @@ namespace QtAndroid
static jboolean startQtAndroidPlugin(JNIEnv *env, jobject /*object*/, jstring paramsString)
{
Q_UNUSED(env)
m_androidPlatformIntegration = nullptr;
m_androidAssetsFileEngineHandler = new AndroidAssetsFileEngineHandler();
m_androidContentFileEngineHandler = new AndroidContentFileEngineHandler();
m_mainLibraryHnd = nullptr;
const char *nativeString = env->GetStringUTFChars(paramsString, 0);
const QStringList argsList = QProcess::splitCommand(QString::fromUtf8(nativeString));
env->ReleaseStringUTFChars(paramsString, nativeString);
// QProcess::splitCommand() treats triple quotes as the quote character itself.
QString params = QJniObject(paramsString).toString().replace("\""_L1, "\"\"\""_L1);
const QStringList argsList = QProcess::splitCommand(params);
for (const QString &arg : argsList)
m_applicationParams.append(arg.toUtf8());

View File

@ -355,7 +355,7 @@ static bool parseTestArgs()
if (match.hasMatch()) {
logType = match.capturedTexts().at(1);
} else {
unhandledArgs << QStringLiteral(" \\\"%1\\\"").arg(arg);
unhandledArgs << " %1"_L1.arg(arg).replace("\""_L1, "\\\""_L1);
}
}
}