From 8c627883b815ea9bfeb65dafa3a1d9517c17ad5a Mon Sep 17 00:00:00 2001 From: 0penBrain <48731257+0penBrain@users.noreply.github.com> Date: Sun, 8 Oct 2023 09:26:19 +0200 Subject: [PATCH] Sanitize bookmarks saving with percent-encoded strings, fixes #1117 --- src/qtgui/bookmarks.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/qtgui/bookmarks.cpp b/src/qtgui/bookmarks.cpp index d4593e5ac..8dd179a0a 100644 --- a/src/qtgui/bookmarks.cpp +++ b/src/qtgui/bookmarks.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include "bookmarks.h" @@ -71,6 +72,12 @@ void Bookmarks::remove(int index) bool Bookmarks::load() { + // define a lambda for loading percent-encoded string + auto loadEncoded = [](const QString &input){ + return QUrl::fromPercentEncoding(input.toUtf8()); + }; + + QFile file(m_bookmarksFile); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { @@ -94,7 +101,7 @@ bool Bookmarks::load() QStringList strings = line.split(";"); if(strings.count() == 2) { - TagInfo::sptr info = findOrAddTag(strings[0]); + TagInfo::sptr info = findOrAddTag(loadEncoded(strings[0])); info->color = QColor(strings[1].trimmed()); } else @@ -117,7 +124,7 @@ bool Bookmarks::load() { BookmarkInfo info; info.frequency = strings[0].toLongLong(); - info.name = strings[1].trimmed(); + info.name = loadEncoded(strings[1].trimmed()); info.modulation = strings[2].trimmed(); info.bandwidth = strings[3].toInt(); // Multiple Tags may be separated by comma. @@ -125,7 +132,7 @@ bool Bookmarks::load() QStringList TagList = strTags.split(","); for(int iTag=0; iTag::iterator i = usedTags.begin(); i != usedTags.end(); i++) { TagInfo::sptr info = *i; - stream << info->name.leftJustified(20) + "; " + info->color.name() << '\n'; + stream << saveEncoded(info->name).leftJustified(20) + "; " + info->color.name() << '\n'; } stream << '\n'; @@ -184,7 +195,7 @@ bool Bookmarks::save() { BookmarkInfo& info = m_BookmarkList[i]; QString line = QString::number(info.frequency).rightJustified(12) + - "; " + info.name.leftJustified(25) + "; " + + "; " + saveEncoded(info.name).leftJustified(25) + "; " + info.modulation.leftJustified(20)+ "; " + QString::number(info.bandwidth).rightJustified(10) + "; "; for(int iTag = 0; iTagname); + line.append(saveEncoded(tag->name)); } stream << line << '\n';