Skip to content

Commit

Permalink
Fix passing of non-ASCII characters as command-line arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
lassoan authored and jcfr committed Jul 2, 2024
1 parent bdd082a commit 9998a7d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions Base/Testing/Cpp/ctkAppLauncherEnvironmentTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,24 @@ void ctkAppLauncherEnvironmentTester::cleanup()
QStringList originalEnvKeys = ctkAppLauncherEnvironment::envKeys(this->OriginalEnv);
foreach(const QString& varName, originalEnvKeys)
{
qputenv(varName.toLatin1(), this->OriginalEnv.value(varName).toLatin1());
qputenv(varName.toLocal8Bit(), this->OriginalEnv.value(varName).toLocal8Bit());
}
}

// ----------------------------------------------------------------------------
void ctkAppLauncherEnvironmentTester::setEnv(const QString& name, const QString& value)
{
qputenv(name.toLatin1(), value.toLatin1());
qputenv(name.toLocal8Bit(), value.toLocal8Bit());
this->VariableNames.insert(name);
}

// ----------------------------------------------------------------------------
void ctkAppLauncherEnvironmentTester::unsetEnv(const QString& name)
{
#if defined(_MSC_VER)
qputenv(name.toLatin1(), QString("").toLatin1());
qputenv(name.toLocal8Bit(), QString().toLocal8Bit());
#else
unsetenv(name.toLatin1());
unsetenv(name.toLocal8Bit());
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion Base/ctkAppArguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void ctkChar2DArray::setValues(const QStringList& list)
{
QString item = d->List.at(index);
d->Values[index] = new char[item.size() + 1];
qstrcpy(d->Values[index], item.toLatin1().data());
qstrcpy(d->Values[index], item.toLocal8Bit().data());
}
}

Expand Down
6 changes: 3 additions & 3 deletions Base/ctkAppLauncherEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ void ctkAppLauncherEnvironment::updateCurrentEnvironment(const QProcessEnvironme
foreach(const QString& varName, variablesToUnset)
{
#if defined(Q_OS_WIN32)
bool success = qputenv(varName.toLatin1(), QString("").toLatin1());
bool success = qputenv(varName.toLocal8Bit(), QString().toLocal8Bit());
#else
bool success = unsetenv(varName.toLatin1()) == EXIT_SUCCESS;
bool success = unsetenv(varName.toLocal8Bit()) == EXIT_SUCCESS;
#endif
if (!success)
{
Expand All @@ -180,7 +180,7 @@ void ctkAppLauncherEnvironment::updateCurrentEnvironment(const QProcessEnvironme
foreach(const QString& varName, envKeys)
{
QString varValue = environment.value(varName);
bool success = qputenv(varName.toLatin1(), varValue.toLatin1());
bool success = qputenv(varName.toLocal8Bit(), varValue.toLocal8Bit());
if (!success)
{
qWarning() << "Failed to set environment variable"
Expand Down
4 changes: 2 additions & 2 deletions Base/ctkTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ static void mouseEvent(QTest::MouseAction action, QWidget *widget, Qt::MouseButt
{
static const char *mouseActionNames[] =
{ "MousePress", "MouseRelease", "MouseClick", "MouseDClick", "MouseMove" };
QString warning = QString::fromLatin1("Mouse event \"%1\" not accepted by receiving widget");
QTest::qWarn(warning.arg(QString::fromLatin1(mouseActionNames[static_cast<int>(action)])).toLatin1());
QString warning = QLatin1String("Mouse event \"%1\" not accepted by receiving widget");
QTest::qWarn(warning.arg(QLatin1String(mouseActionNames[static_cast<int>(action)])).toLocal8Bit());
}
}

Expand Down

0 comments on commit 9998a7d

Please sign in to comment.