From 8a47838d94b43b437359753de8399b57c85e326d Mon Sep 17 00:00:00 2001 From: Albert S Date: Fri, 15 Jul 2022 18:26:02 +0200 Subject: [PATCH] EntryProvider: Support broken .desktop files that don't start with [Desktop Entry] --- entryprovider.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/entryprovider.cpp b/entryprovider.cpp index 319b957..ac2a8e8 100644 --- a/entryprovider.cpp +++ b/entryprovider.cpp @@ -30,15 +30,17 @@ EntryConfig EntryProvider::readFromDesktopFile(const QString &path) QTextStream stream(&file); // There should be nothing preceding this group in the desktop entry file but possibly one or more comments. // https://standards.freedesktop.org/desktop-entry-spec/latest/ar01s03.html#group-header - QString firstLine; + // Ignore that as there some that violate that in the wild + const QString startSection = "[Desktop Entry]"; + QString line; do { - firstLine = stream.readLine().trimmed(); - } while(!stream.atEnd() && (firstLine.isEmpty() || firstLine[0] == '#')); + line = stream.readLine().trimmed(); + } while(!stream.atEnd() && line != startSection); - if(firstLine != "[Desktop Entry]") + if(line != startSection) { - throw ConfigFormatException(".desktop file does not start with [Desktop Entry]: " + path.toStdString()); + throw ConfigFormatException(".desktop file does not contain [Desktop Entry] section: " + path.toStdString()); } while(!stream.atEnd())