Browse Source

Improve parser for search engine versions.txt

The parse could fail when there is an extra empty line at the end of
file, this patch fixes it.
adaptive-webui-19844
Chocobo1 6 years ago
parent
commit
c1c28ce195
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 18
      src/base/search/searchpluginmanager.cpp

18
src/base/search/searchpluginmanager.cpp

@ -47,6 +47,7 @@
#include "base/net/downloadmanager.h" #include "base/net/downloadmanager.h"
#include "base/preferences.h" #include "base/preferences.h"
#include "base/profile.h" #include "base/profile.h"
#include "base/utils/bytearray.h"
#include "base/utils/foreignapps.h" #include "base/utils/foreignapps.h"
#include "base/utils/fs.h" #include "base/utils/fs.h"
#include "base/utils/misc.h" #include "base/utils/misc.h"
@ -495,25 +496,24 @@ void SearchPluginManager::parseVersionInfo(const QByteArray &info)
{ {
QHash<QString, PluginVersion> updateInfo; QHash<QString, PluginVersion> updateInfo;
int numCorrectData = 0; int numCorrectData = 0;
QList<QByteArray> lines = info.split('\n');
foreach (QByteArray line, lines) { const QList<QByteArray> lines = Utils::ByteArray::splitToViews(info, "\n", QString::SkipEmptyParts);
for (QByteArray line : lines) {
line = line.trimmed(); line = line.trimmed();
if (line.isEmpty()) continue; if (line.isEmpty()) continue;
if (line.startsWith('#')) continue; if (line.startsWith('#')) continue;
QList<QByteArray> list = line.split(' '); const QList<QByteArray> list = Utils::ByteArray::splitToViews(line, ":", QString::SkipEmptyParts);
if (list.size() != 2) continue; if (list.size() != 2) continue;
QString pluginName = QString(list.first()); const QString pluginName = list.first().trimmed();
if (!pluginName.endsWith(':')) continue; const PluginVersion version = PluginVersion::tryParse(list.last().trimmed(), {});
pluginName.chop(1); // remove trailing ':' if (!version.isValid()) continue;
PluginVersion version = PluginVersion::tryParse(list.last(), {});
if (version == PluginVersion()) continue;
++numCorrectData; ++numCorrectData;
if (isUpdateNeeded(pluginName, version)) { if (isUpdateNeeded(pluginName, version)) {
LogMsg(tr("Plugin %1 is outdated").arg(pluginName), Log::INFO); LogMsg(tr("Plugin \"%1\" is outdated, updating to version %2").arg(pluginName, version), Log::INFO);
updateInfo[pluginName] = version; updateInfo[pluginName] = version;
} }
} }

Loading…
Cancel
Save