diff --git a/src/desktopentry.cpp b/src/desktopentry.cpp index 35f6e20..5dc3b2d 100644 --- a/src/desktopentry.cpp +++ b/src/desktopentry.cpp @@ -15,14 +15,22 @@ #include #include -auto DesktopEntry::parserGroupHeader(const QString &str) noexcept +auto DesktopEntry::parseGroupHeader(const QString &str) noexcept { + // https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#group-header + auto groupHeader = str.sliced(1, str.size() - 2).trimmed(); decltype(m_entryMap)::iterator it{m_entryMap.end()}; - QRegularExpression re{R"([^\x20-\x5a-\x5e-\x7e\x5c])"}; + // NOTE: + // This regex match '[', ']', control characters + // and all non-ascii characters. + // They are invalid in group header. + // https://regex101.com/r/bZhHZo/1 + QRegularExpression re{R"([^\x20-\x5a\x5e-\x7e\x5c])"}; auto matcher = re.match(groupHeader); if (matcher.hasMatch()) { + qWarning() << "group header invalid:" << str; return it; } @@ -31,6 +39,7 @@ auto DesktopEntry::parserGroupHeader(const QString &str) noexcept it = m_entryMap.insert(groupHeader, {}); } + qWarning() << "group header already exists:" << str; return it; } @@ -336,10 +345,9 @@ DesktopErrorCode DesktopEntry::parse(QTextStream &stream) noexcept } if (line.startsWith('[')) { - auto group = parserGroupHeader(line); + auto group = parseGroupHeader(line); if (group == m_entryMap.end()) { - qWarning() << "groupName format error or already exists:" << line; return DesktopErrorCode::InvalidFormat; } currentGroup = group; diff --git a/src/desktopentry.h b/src/desktopentry.h index c3ffec5..769b460 100644 --- a/src/desktopentry.h +++ b/src/desktopentry.h @@ -130,7 +130,7 @@ private: EntryContext m_context{EntryContext::EntryOuter}; QMap> m_entryMap; - auto parserGroupHeader(const QString &str) noexcept; + auto parseGroupHeader(const QString &str) noexcept; [[nodiscard]] bool checkMainEntryValidation() const noexcept; static bool skipCheck(const QString &line) noexcept; static DesktopErrorCode parseEntry(const QString &str, decltype(m_entryMap)::iterator ¤tGroup) noexcept;