diff --git a/changelog/next.md b/changelog/next.md index 671afb2..b65b83f 100644 --- a/changelog/next.md +++ b/changelog/next.md @@ -2,3 +2,4 @@ - Fixed ScriptModel not sending role updates on changed data that compares equal by key or structure. - Fixed Hyprland workspaces keeping their old id after Hyprland changes it. +- Fixed desktop entries being parsed incorrectly with trailing whitespace or CRLF line endings. diff --git a/src/core/desktopentry.cpp b/src/core/desktopentry.cpp index 637f758..17e6057 100644 --- a/src/core/desktopentry.cpp +++ b/src/core/desktopentry.cpp @@ -158,22 +158,23 @@ ParsedDesktopEntryData DesktopEntry::parseText(const QString& id, const QString& }; for (auto& line: text.split(u'\n', Qt::SkipEmptyParts)) { - if (line.startsWith(u'#')) continue; + const auto trimmed = line.trimmed(); + if (trimmed.isEmpty() || trimmed.startsWith(u'#')) continue; - if (line.startsWith(u'[') && line.endsWith(u']')) { + if (trimmed.startsWith(u'[') && trimmed.endsWith(u']')) { finishCategory(); - groupName = line.sliced(1, line.length() - 2); + groupName = trimmed.sliced(1, trimmed.length() - 2); continue; } - auto splitIdx = line.indexOf(u'='); + auto splitIdx = trimmed.indexOf(u'='); if (splitIdx == -1) { qCWarning(logDesktopEntry) << "Encountered invalid line in desktop entry (no =)" << line; continue; } - auto key = line.sliced(0, splitIdx); - const auto& value = line.sliced(splitIdx + 1); + auto key = trimmed.sliced(0, splitIdx); + const auto& value = trimmed.sliced(splitIdx + 1); auto localeIdx = key.indexOf('['); Locale locale;