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>
This commit is contained in:
Eike Ziller
2015-03-09 13:20:18 +01:00
parent 6ecde4cdf0
commit ba64a7bb1b

View File

@@ -190,9 +190,13 @@ MimeType MimeDatabasePrivate::mimeTypeForFileNameAndData(const QString &fileName
// Disambiguate conflicting extensions (if magic matching found something) // Disambiguate conflicting extensions (if magic matching found something)
if (candidateByData.isValid() && magicAccuracy > 0) { 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(); 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) { foreach (const QString &m, candidatesByName) {
if (inherits(m, sniffedMime)) { if (inherits(m, sniffedMime)) {
// We have magic + pattern pointing to this, so it's a pretty good match // We have magic + pattern pointing to this, so it's a pretty good match