From 66159f42a1a546b8e23befe4a2b40b77392ae20f Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Mon, 17 Jan 2022 14:31:23 +0100 Subject: [PATCH] abandon needless # separator for scripts! --- src/librssguard/miscellaneous/textfactory.cpp | 44 +++++++++++++++++++ src/librssguard/miscellaneous/textfactory.h | 1 + .../services/standard/standardfeed.cpp | 10 ++--- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/src/librssguard/miscellaneous/textfactory.cpp b/src/librssguard/miscellaneous/textfactory.cpp index 46c3c614c..37521bd8a 100644 --- a/src/librssguard/miscellaneous/textfactory.cpp +++ b/src/librssguard/miscellaneous/textfactory.cpp @@ -160,6 +160,50 @@ QString TextFactory::capitalizeFirstLetter(const QString& sts) { } } +QStringList TextFactory::tokenizeProcessArguments(QStringView command) { + QStringList args; + QString tmp; + int quote_count = 0; + bool in_quote = false; + + for (int i = 0; i < command.size(); ++i) { + if (command.at(i) == QL1C('"')) { + ++quote_count; + + if (quote_count == 3) { + quote_count = 0; + tmp += command.at(i); + } + + continue; + } + + if (quote_count) { + if (quote_count == 1) { + in_quote = !in_quote; + } + + quote_count = 0; + } + + if (!in_quote && command.at(i).isSpace()) { + if (!tmp.isEmpty()) { + args += tmp; + tmp.clear(); + } + } + else { + tmp += command.at(i); + } + } + + if (!tmp.isEmpty()) { + args += tmp; + } + + return args; +} + QString TextFactory::shorten(const QString& input, int text_length_limit) { if (input.size() > text_length_limit) { return input.left(text_length_limit - ELLIPSIS_LENGTH) + QString(ELLIPSIS_LENGTH, QL1C('.')); diff --git a/src/librssguard/miscellaneous/textfactory.h b/src/librssguard/miscellaneous/textfactory.h index f3571e1f8..d82c3c7ea 100644 --- a/src/librssguard/miscellaneous/textfactory.h +++ b/src/librssguard/miscellaneous/textfactory.h @@ -32,6 +32,7 @@ class TextFactory { static QString decrypt(const QString& text, quint64 key = 0); static QString newline(); static QString capitalizeFirstLetter(const QString& sts); + static QStringList tokenizeProcessArguments(QStringView args); // Shortens input string according to given length limit. static QString shorten(const QString& input, int text_length_limit = TEXT_TITLE_LIMIT); diff --git a/src/librssguard/services/standard/standardfeed.cpp b/src/librssguard/services/standard/standardfeed.cpp index 7767282fd..ea90af8b8 100644 --- a/src/librssguard/services/standard/standardfeed.cpp +++ b/src/librssguard/services/standard/standardfeed.cpp @@ -25,6 +25,7 @@ #include "services/standard/rssparser.h" #include "services/standard/standardserviceroot.h" +#include #include #include #include @@ -506,14 +507,9 @@ void StandardFeed::setEncoding(const QString& encoding) { } QStringList StandardFeed::prepareExecutionLine(const QString& execution_line) { - auto split_exec = execution_line.split(QSL(EXECUTION_LINE_SEPARATOR), -#if QT_VERSION >= 0x050F00 // Qt >= 5.15.0 - Qt::SplitBehaviorFlags::SkipEmptyParts); -#else - QString::SplitBehavior::SkipEmptyParts); -#endif + auto args = TextFactory::tokenizeProcessArguments(execution_line); - return qApp->replaceDataUserDataFolderPlaceholder(split_exec); + return qApp->replaceDataUserDataFolderPlaceholder(args); } QString StandardFeed::runScriptProcess(const QStringList& cmd_args, const QString& working_directory,