mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2026-09-15 15:43:05 -04:00
splitArgs treated any backslash inside quotes as an escape character, so a quoted Windows path such as -Dorg.lwjgl.glfw.libname="C:\Users\..." lost its path separators before reaching the JVM, causing java.nio.file.InvalidPathException at launch. A backslash inside quotes now only escapes the matching quote or another backslash, keeping escaped quotes functional while leaving Windows path separators intact. Signed-off-by: Nic <73386479+nicyoong@users.noreply.github.com>
40 lines
1.8 KiB
C++
40 lines
1.8 KiB
C++
#include <QTest>
|
|
|
|
#include <Commandline.h>
|
|
|
|
class CommandlineTest : public QObject {
|
|
Q_OBJECT
|
|
private slots:
|
|
void test_splitArgs_data()
|
|
{
|
|
QTest::addColumn<QString>("args");
|
|
QTest::addColumn<QStringList>("expected");
|
|
|
|
QTest::newRow("plain arguments") << "a b c" << QStringList{ "a", "b", "c" };
|
|
QTest::newRow("quoted argument with spaces") << "a \"b c\" d" << QStringList{ "a", "b c", "d" };
|
|
QTest::newRow("windows path without quotes") << "-Dorg.lwjgl.glfw.libname=C:\\Users\\user\\glfw3.dll"
|
|
<< QStringList{ "-Dorg.lwjgl.glfw.libname=C:\\Users\\user\\glfw3.dll" };
|
|
QTest::newRow("windows path in quotes keeps backslashes")
|
|
<< "-Dorg.lwjgl.glfw.libname=\"C:\\Users\\test user\\glfw3.dll\""
|
|
<< QStringList{ "-Dorg.lwjgl.glfw.libname=C:\\Users\\test user\\glfw3.dll" };
|
|
QTest::newRow("fully quoted argument keeps backslashes")
|
|
<< "\"-Dorg.lwjgl.glfw.libname=C:\\Users\\test user\\glfw3.dll\""
|
|
<< QStringList{ "-Dorg.lwjgl.glfw.libname=C:\\Users\\test user\\glfw3.dll" };
|
|
QTest::newRow("windows path in single quotes keeps backslashes")
|
|
<< "-Dfoo='C:\\Users\\test user\\glfw3.dll'" << QStringList{ "-Dfoo=C:\\Users\\test user\\glfw3.dll" };
|
|
QTest::newRow("escaped quotes") << "-Dfoo=\"say \\\"hi\\\" now\"" << QStringList{ "-Dfoo=say \"hi\" now" };
|
|
QTest::newRow("double backslash in quotes collapses")
|
|
<< "-Dfoo=\"C:\\\\path\\\\file.dll\"" << QStringList{ "-Dfoo=C:\\path\\file.dll" };
|
|
}
|
|
void test_splitArgs()
|
|
{
|
|
QFETCH(QString, args);
|
|
QFETCH(QStringList, expected);
|
|
|
|
QCOMPARE(Commandline::splitArgs(args), expected);
|
|
}
|
|
};
|
|
|
|
QTEST_GUILESS_MAIN(CommandlineTest)
|
|
#include "Commandline_test.moc"
|