Replace EscapeShell with KShell::joinArgs

This commit is contained in:
Ilya Fedin 2022-09-19 05:13:43 +04:00 committed by John Preston
parent 278ab5ebaf
commit 89879e355d
2 changed files with 8 additions and 34 deletions

View File

@ -35,6 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtWidgets/QSystemTrayIcon>
#include <QtCore/QStandardPaths>
#include <QtCore/QProcess>
#include <KShell>
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
#include <glibmm.h>
@ -172,36 +173,6 @@ void PortalAutostart(bool start, bool silent) {
}
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
QByteArray EscapeShell(const QByteArray &content) {
auto result = QByteArray();
auto b = content.constData(), e = content.constEnd();
for (auto ch = b; ch != e; ++ch) {
if (*ch == ' ' || *ch == '"' || *ch == '\'' || *ch == '\\') {
if (result.isEmpty()) {
result.reserve(content.size() * 2);
}
if (ch > b) {
result.append(b, ch - b);
}
result.append('\\');
b = ch;
}
}
if (result.isEmpty()) {
return content;
}
if (e > b) {
result.append(b, e - b);
}
return result;
}
QString EscapeShellInLauncher(const QString &content) {
return EscapeShell(content.toUtf8()).replace('\\', "\\\\");
}
QString FlatpakID() {
static const auto Result = [] {
if (!qEnvironmentVariableIsEmpty("FLATPAK_ID")) {
@ -255,9 +226,12 @@ bool GenerateDesktopFile(
QRegularExpression(
qsl("^Exec=telegram-desktop(.*)$"),
QRegularExpression::MultilineOption),
qsl("Exec=%1 -workdir %2\\1").arg(
EscapeShellInLauncher(cExeDir() + cExeName()),
EscapeShellInLauncher(cWorkingDir())));
qsl("Exec=%1\\1").arg(
KShell::joinArgs({
cExeDir() + cExeName(),
"-workdir",
cWorkingDir(),
}).replace('\\', "\\\\")));
fileText = fileText.replace(
QRegularExpression(

@ -1 +1 @@
Subproject commit cc5550de2766657ced8d0bb4d2db3f050363d3d5
Subproject commit d932f5048317b05dd414116741d995c82a528542