diff options
author | Eike Ziller <eike.ziller@theqtcompany.com> | 2015-03-09 13:20:18 +0100 |
---|---|---|
committer | Eike Ziller <eike.ziller@theqtcompany.com> | 2015-03-09 14:04:02 +0000 |
commit | ba64a7bb1b10ca5e0f6d2f556a07ef43962d90d1 (patch) | |
tree | 6518f345be9c4c2d64773766e3f08e75e688a627 /src/libs/utils/mimetypes/mimedatabase.cpp | |
parent | 6ecde4cdf0b60a249cea528023058dcf4c2767bc (diff) |
MimeDatabase: Fix that xml files were opened in bar descriptor editor
Fix MIME detection issues with magics in MIME hierarchies
Assume two MIME types A and B are registered, both with the same glob
pattern, A being parent of B, A with some magic rule, and B with another
magic rule. Given a file that matches the glob pattern and the magic rule
of A, the resulting MIME type depended on the order of registration of A
and B, because it would just check if some glob matching MIME type was
also a subclass of the magic matching MIME type.
The patch prefers the the MIME type that matches by magic if that
matches by glob pattern as well (i.e. A in our example).
The "recommended checking order" of the spec does handle that case.
Change-Id: Ia914aa7b6d0fb52f6c833897a5be69eb59fca6ab
Task-number: QTBUG-44846
Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com>
Diffstat (limited to 'src/libs/utils/mimetypes/mimedatabase.cpp')
-rw-r--r-- | src/libs/utils/mimetypes/mimedatabase.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/libs/utils/mimetypes/mimedatabase.cpp b/src/libs/utils/mimetypes/mimedatabase.cpp index 39f3cf7a2a9..be018edcc8e 100644 --- a/src/libs/utils/mimetypes/mimedatabase.cpp +++ b/src/libs/utils/mimetypes/mimedatabase.cpp @@ -190,9 +190,13 @@ MimeType MimeDatabasePrivate::mimeTypeForFileNameAndData(const QString &fileName // Disambiguate conflicting extensions (if magic matching found something) if (candidateByData.isValid() && magicAccuracy > 0) { - // "for glob_match in glob_matches:" - // "if glob_match is subclass or equal to sniffed_type, use glob_match" const QString sniffedMime = candidateByData.name(); + // If the sniffedMime matches a glob match, use it + if (candidatesByName.contains(sniffedMime)) { + *accuracyPtr = 100; + return candidateByData; + } + // If there is a glob match that is a sub class of sniffedMime, use it foreach (const QString &m, candidatesByName) { if (inherits(m, sniffedMime)) { // We have magic + pattern pointing to this, so it's a pretty good match |