Details
-
Bug
-
Resolution: Invalid
-
P2: Important
-
None
-
5.11.0
-
None
Description
Since updating to the latest Qt, I have had this problem where a normal text/plain file is being detected as text/x-microdvd. I believe the issue lies in change 180842, which has the corresponding bug report QTBUG-58938. I made a comment on that bug, but thought I would create another bug reports since it's really a separate issue. Below is that comment:
I believe this fix has caused a regression in how plain text files are handled. I have a problem where files that are generally treated as text/plain (as they should be) are now being detected as text/x-microdvd. I've tracked it down to QMimeDatabase::mimeTypeForFileNameAndData - I believe it's because candidatesByName.m_matchingMimeTypes (used to be just candidatesByName) is no longer sorted if there are more than one mime types for the file name, and findByData returns a valid mime type. I did some checking, and text/x-microdvd is added before text/plain to the mime cache, which also means that it's the first result in m_matchingMimeTypes and since text/x-microdvd inherits from text/plain, it will see that as a valid result.
This is some test code I wrote:
QFile file("~/Downloads/test.txt"); QMimeDatabase db; QMimeType type = db.mimeTypeForData(&file); QMimeType fileType = db.mimeTypeForFile(file.fileName(), QMimeDatabase::MatchExtension); QMimeType dataFileType = db.mimeTypeForFileNameAndData(file.fileName(), &file); QList<QMimeType> types = db.mimeTypesForFileName(file.fileName()); qInfo() << "Data" << type.name() << "file" << fileType.name() << "data and file" << dataFileType.name(); qInfo() << "Types"; for(QMimeType t: types) { qInfo() << t.name(); }
And here's the output:
Data "text/plain" file "text/plain" data and file "text/x-microdvd" Types "text/plain" "text/x-microdvd"
As you can see, it returns text/plain for both the data and filename tests, and it's also first in the mime types list (because that sorts the results).
I managed to work around this temporarily by adding a custom plain.xml under ~/.local/share/mime/text/, which causes it to be added to the cache before x-microdvd.