From 6c561d2b7b1bb303cfcd8a013179b1838d315910 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Fri, 12 Mar 2021 15:26:56 +0100 Subject: [PATCH 1/1] qa: Modernize invocation of QProcess in ExecWrapper Don't use deprecated API for QProcess in ExecWrapper for starting a script; arguments should be given as a QStringList instead of a QString. Modernize and improve the parsing of the command line by switching to QRegularExpression from QRegExp. Resolves a deprecation warning that was introduced in Qt 5.15. --- src/client/execwrapper.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/client/execwrapper.cpp b/src/client/execwrapper.cpp index ee0e864a..7eac3521 100644 --- a/src/client/execwrapper.cpp +++ b/src/client/execwrapper.cpp @@ -22,6 +22,7 @@ #include #include +#include #include "client.h" #include "messagemodel.h" @@ -47,28 +48,32 @@ ExecWrapper::ExecWrapper(QObject* parent) void ExecWrapper::start(const BufferInfo& info, const QString& command) { _bufferInfo = info; - QString params; + _scriptName.clear(); - QRegExp rx(R"(^\s*(\S+)(\s+(.*))?$)"); - if (!rx.exactMatch(command)) { + QStringList params; + + static const QRegularExpression rx{R"(^\s*(\S+)(\s+(.*))?$)"}; + auto match = rx.match(command); + if (!match.hasMatch()) { emit error(tr("Invalid command string for /exec: %1").arg(command)); } else { - _scriptName = rx.cap(1); - params = rx.cap(3); + _scriptName = match.captured(1); + static const QRegularExpression splitRx{"\\s+"}; + params = match.captured(3).split(splitRx, QString::SkipEmptyParts); } // Make sure we don't execute something outside a script dir - if (_scriptName.contains("../") || _scriptName.contains("..\\")) + if (_scriptName.contains("../") || _scriptName.contains("..\\")) { emit error(tr(R"(Name "%1" is invalid: ../ or ..\ are not allowed!)").arg(_scriptName)); - - else { + } + else if (!_scriptName.isEmpty()) { foreach (QString scriptDir, Quassel::scriptDirPaths()) { QString fileName = scriptDir + _scriptName; if (!QFile::exists(fileName)) continue; _process.setWorkingDirectory(scriptDir); - _process.start('"' + fileName + "\" " + params); + _process.start(_scriptName, params); return; } emit error(tr("Could not find script \"%1\"").arg(_scriptName)); -- 2.20.1