Fix errorneous whitespace handling in Desktop Entry parsing from DesktopFileParser
ClosedPublic

Authored by mpyne on Aug 7 2017, 2:03 AM.

Details

Summary

As reported in bug 310674, the Desktop Entry spec says that whitespace surrounding the = sign that separates the key and value in .desktop files should be ignored when interpreting the key and value portions.

That is, all four of these lines should be equivalent:

Type=Application
Type =Application
Type= Application
Type = Application

DesktopFileParser handles this for most key/value entries already (e.g. at src/lib/plugin/desktopfileparser.cpp:266), but there is a specific function to handle reading Type= entries from desktop files which doesn't handle spaces (and even has a TODO asking whether it should).

This patch implements the spec here by using QRegularExpression to match the part of the string after =\s*.

Test Plan

Existing autotests have been modified to include spaces around some of the Type= entries, and the updated autotests now pass.

Diff Detail

Repository
R244 KCoreAddons
Lint
Lint Skipped
Unit
Unit Tests Skipped
mpyne created this revision.Aug 7 2017, 2:03 AM
Restricted Application added a project: Frameworks. · View Herald TranscriptAug 7 2017, 2:03 AM
apol added a subscriber: apol.Aug 7 2017, 2:23 AM
apol added inline comments.
src/lib/plugin/desktopfileparser.cpp
213 ↗(On Diff #17792)

Wrong scope?

mpyne updated this revision to Diff 17913.Aug 9 2017, 3:48 AM

Joins the regex for the Type= line with its use.

mpyne marked an inline comment as done.Aug 9 2017, 3:49 AM
arichardson edited edge metadata.Aug 11 2017, 10:52 PM

Looks good to me. Using a regex engine for this seems like overkill but I guess compared to the I/O overhead of reading the desktop file it shouldn't matter.

This revision was automatically updated to reflect the committed changes.