Sanitize username to prevent single-instance detection failure (#12559)

---------

Co-authored-by: Jonathan White <support@dmapps.us>
This commit is contained in:
Siddhant Shekhar 2025-11-01 19:55:10 +05:30 committed by GitHub
parent f927c4c41a
commit d9ccf767d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 61 additions and 11 deletions

View file

@ -428,3 +428,26 @@ void TestTools::testIsTextMimeType()
QVERIFY(!Tools::isTextMimeType(noText));
}
}
// Test sanitization logic for Tools::cleanUsername
void TestTools::testCleanUsername()
{
// Test vars
QFETCH(QString, input);
QFETCH(QString, expected);
qputenv("USER", input.toUtf8());
qputenv("USERNAME", input.toUtf8());
QCOMPARE(Tools::cleanUsername(), expected);
}
void TestTools::testCleanUsername_data()
{
QTest::addColumn<QString>("input");
QTest::addColumn<QString>("expected");
QTest::newRow("Leading and trailing spaces") << " user " << "user";
QTest::newRow("Special characters") << R"(user<>:"/\|?*name)" << "user_________name";
QTest::newRow("Trailing dots and spaces") << "username... " << "username";
QTest::newRow("Combination of issues") << R"( user<>:"/\|?*name... )" << "user_________name";
}