forked from qt-creator/qt-creator
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:
@@ -1444,16 +1444,15 @@ CommandLine CommandLine::fromUserInput(const QString &cmdline, MacroExpander *ex
|
|||||||
|
|
||||||
QString input = cmdline.trimmed();
|
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())
|
if (result.isEmpty())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
auto cmd = CommandLine(FilePath::fromUserInput(result.value(0)), result.mid(1));
|
return {FilePath::fromUserInput(result.value(0)), result.mid(1)};
|
||||||
if (expander)
|
|
||||||
cmd.m_arguments = expander->expand(cmd.m_arguments);
|
|
||||||
|
|
||||||
return cmd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandLine::addArg(const QString &arg)
|
void CommandLine::addArg(const QString &arg)
|
||||||
|
@@ -196,8 +196,7 @@ private slots:
|
|||||||
|
|
||||||
QTest::newRow("simple") << "command %{hello}"
|
QTest::newRow("simple") << "command %{hello}"
|
||||||
<< "command"
|
<< "command"
|
||||||
<< (HostOsInfo::isWindowsHost() ? "\"hello world\""
|
<< "hello world";
|
||||||
: "'hello world'");
|
|
||||||
|
|
||||||
QTest::newRow("simple-quoted")
|
QTest::newRow("simple-quoted")
|
||||||
<< "command \"%{hello}\""
|
<< "command \"%{hello}\""
|
||||||
@@ -226,15 +225,11 @@ private slots:
|
|||||||
CommandLine cmd = CommandLine::fromUserInput(input, &expander);
|
CommandLine cmd = CommandLine::fromUserInput(input, &expander);
|
||||||
QCOMPARE(cmd.executable().toUserOutput(), expectedExecutable);
|
QCOMPARE(cmd.executable().toUserOutput(), expectedExecutable);
|
||||||
|
|
||||||
// TODO: Fix (macro) escaping on windows
|
if (HostOsInfo::isWindowsHost()) {
|
||||||
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())
|
|
||||||
QEXPECT_FAIL("convert-to-quote-win",
|
QEXPECT_FAIL("convert-to-quote-win",
|
||||||
"Windows should convert single to double quotes",
|
"Windows should convert single to double quotes",
|
||||||
Continue);
|
Continue);
|
||||||
|
}
|
||||||
|
|
||||||
QCOMPARE(cmd.arguments(), expectedArguments);
|
QCOMPARE(cmd.arguments(), expectedArguments);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user