forked from qt-creator/qt-creator
Utils: Fix quoting on Linux
To double-quote, we need to use '"'"' instead of \' since that does not work. Also adds a test for it. Task-number: QTCREATORBUG-32325 Change-Id: I9c5b92e29de264ffb71c3b299746ee68052c8859 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -516,7 +516,7 @@ QString ProcessArgs::quoteArgUnix(const QString &arg)
|
|||||||
if (arg == "&&" || arg == "||" || arg == "&" || arg == ';')
|
if (arg == "&&" || arg == "||" || arg == "&" || arg == ';')
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
ret.replace(QLatin1Char('\''), QLatin1String("'\\''"));
|
ret.replace(QLatin1Char('\''), QLatin1String(R"('"'"')"));
|
||||||
ret.prepend(QLatin1Char('\''));
|
ret.prepend(QLatin1Char('\''));
|
||||||
ret.append(QLatin1Char('\''));
|
ret.append(QLatin1Char('\''));
|
||||||
}
|
}
|
||||||
|
@@ -72,6 +72,48 @@ private slots:
|
|||||||
QCOMPARE(run(cmd), expected);
|
QCOMPARE(run(cmd), expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testMultiQuote_unix()
|
||||||
|
{
|
||||||
|
CommandLine cmd("echo", {"This is a long argument"}, OsTypeLinux);
|
||||||
|
CommandLine outer("echo", {}, OsTypeLinux);
|
||||||
|
|
||||||
|
outer.addCommandLineAsSingleArg(cmd, OsTypeLinux);
|
||||||
|
QCOMPARE(outer.toUserOutput(), R"(echo 'echo '"'"'This is a long argument'"'"'')");
|
||||||
|
|
||||||
|
CommandLine triple("echo", {}, OsTypeLinux);
|
||||||
|
QString expectedTriple
|
||||||
|
= R"(echo 'echo '"'"'echo '"'"'"'"'"'"'"'"'This is a long argument'"'"'"'"'"'"'"'"''"'"'')";
|
||||||
|
|
||||||
|
triple.addCommandLineAsSingleArg(outer, OsTypeLinux);
|
||||||
|
QCOMPARE(triple.toUserOutput(), expectedTriple);
|
||||||
|
}
|
||||||
|
|
||||||
|
void testMultiQuote_win()
|
||||||
|
{
|
||||||
|
CommandLine cmd("echo", {"This is a long argument"}, OsTypeWindows);
|
||||||
|
CommandLine outer("echo", {}, OsTypeWindows);
|
||||||
|
|
||||||
|
outer.addCommandLineAsSingleArg(cmd);
|
||||||
|
QCOMPARE(outer.toUserOutput(), R"(echo 'echo "This is a long argument"')");
|
||||||
|
|
||||||
|
CommandLine triple("echo", {}, OsTypeWindows);
|
||||||
|
triple.addCommandLineAsSingleArg(outer, OsTypeWindows);
|
||||||
|
QString expectedTriple = R"(echo "echo 'echo "\^""This is a long argument"\^""'")";
|
||||||
|
QCOMPARE(triple.toUserOutput(), expectedTriple);
|
||||||
|
}
|
||||||
|
|
||||||
|
void testMixedMultiQuote()
|
||||||
|
{
|
||||||
|
CommandLine
|
||||||
|
dockerExec("docker", {"exec", "not really an ID", "/bin/sh", "-c"}, OsTypeWindows);
|
||||||
|
CommandLine binsh("/bin/sh", {"-c", "echo 'Hello World'"}, OsTypeLinux);
|
||||||
|
|
||||||
|
dockerExec.addCommandLineAsSingleArg(binsh, OsTypeLinux);
|
||||||
|
QString expected
|
||||||
|
= R"(docker exec "not really an ID" /bin/sh -c '/bin/sh -c '"'"'echo '"'"'"'"'"'"'"'"'Hello World'"'"'"'"'"'"'"'"''"'"'')";
|
||||||
|
QCOMPARE(dockerExec.toUserOutput(), expected);
|
||||||
|
}
|
||||||
|
|
||||||
void testAnd()
|
void testAnd()
|
||||||
{
|
{
|
||||||
QStringList args = {"foo", "bar", "baz"};
|
QStringList args = {"foo", "bar", "baz"};
|
||||||
|
Reference in New Issue
Block a user