Utils: Fix CommandLine macro expansion

Moves macro expansion before assembling the command line
to correctly quote the resulting arguments on windows.

Change-Id: I62eded9376977ec6095e8648296cd2af53eb8e82
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marcus Tillmanns
2023-06-16 15:14:29 +02:00
parent 067c2096d4
commit 9f5a0e3834
2 changed files with 8 additions and 14 deletions

View File

@@ -1444,16 +1444,15 @@ CommandLine CommandLine::fromUserInput(const QString &cmdline, MacroExpander *ex
QString input = cmdline.trimmed();
QStringList result = ProcessArgs::splitArgs(cmdline, HostOsInfo::hostOs());
if (expander)
input = expander->expand(input);
const QStringList result = ProcessArgs::splitArgs(input, HostOsInfo::hostOs());
if (result.isEmpty())
return {};
auto cmd = CommandLine(FilePath::fromUserInput(result.value(0)), result.mid(1));
if (expander)
cmd.m_arguments = expander->expand(cmd.m_arguments);
return cmd;
return {FilePath::fromUserInput(result.value(0)), result.mid(1)};
}
void CommandLine::addArg(const QString &arg)

View File

@@ -196,8 +196,7 @@ private slots:
QTest::newRow("simple") << "command %{hello}"
<< "command"
<< (HostOsInfo::isWindowsHost() ? "\"hello world\""
: "'hello world'");
<< "hello world";
QTest::newRow("simple-quoted")
<< "command \"%{hello}\""
@@ -226,15 +225,11 @@ private slots:
CommandLine cmd = CommandLine::fromUserInput(input, &expander);
QCOMPARE(cmd.executable().toUserOutput(), expectedExecutable);
// TODO: Fix (macro) escaping on windows
if (HostOsInfo::isWindowsHost())
QEXPECT_FAIL("simple", "Windows does not correctly quote macro arguments", Continue);
if (HostOsInfo::isWindowsHost())
QEXPECT_FAIL("simple-quoted", "Windows removes quotes from macro arguments", Continue);
if (HostOsInfo::isWindowsHost())
if (HostOsInfo::isWindowsHost()) {
QEXPECT_FAIL("convert-to-quote-win",
"Windows should convert single to double quotes",
Continue);
}
QCOMPARE(cmd.arguments(), expectedArguments);
}