Commit 03a3ce34 authored by Sergey Kalinichev's avatar Sergey Kalinichev
Browse files

Use match accuracy when asking for mime type.

Ask KMimeType about match accuracy and if it's very low don't
register languages for that mime type.

Otherwise we can accidently register e.g. *.txt files as supported by
c++ language support plugin.

REVIEW: 120085
parent 1f111414
......@@ -297,11 +297,12 @@ QList<ILanguage*> LanguageController::languagesForUrl(const KUrl &url)
return languages;
KMimeType::Ptr mimeType;
int accuracy = 0;
if(!extension.isEmpty()) {
// If we have recognized a file extension, allow using the file-contents
// to look up the type. We will cache it after all.
mimeType = KMimeType::findByUrl(url);
mimeType = KMimeType::findByUrl(url, 0, false, false, &accuracy);
} else {
// If we have not recognized a file extension, do not allow using the file-contents
// to look up the type. We cannot cache the result, and thus we might end up reading
......@@ -319,8 +320,11 @@ QList<ILanguage*> LanguageController::languagesForUrl(const KUrl &url)
languages = languagesForMimetype(mimeType->name());
if(!extension.isEmpty())
// E.g. because of some txt file that begins with /* and considered as c++ file
// we don't want the c++ language support to parse all txt files.
if(!extension.isEmpty() && accuracy > 80) {
d->fileExtensionCache.insert(extension, languages);
}
return languages;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment