summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Faure <david.faure@kdab.com>2017-02-16 13:34:54 +0100
committerDavid Faure <david.faure@kdab.com>2017-02-17 18:52:50 +0000
commit6c9b5581532388a36328d3fae82ad20c85dce58f (patch)
tree69b6a4b9b34ed93b6bf15236375b153a8841bae0
parent8d6d68d3d363bb6aa1faec2355b32e3ea290116c (diff)
QMimeDatabase: fix matching of filenames with different length when lowercase
AİİA.pdf takes 8 QChars, but after lowercasing it takes 10, so the code cannot assume the length to be the same. Task-number: QTBUG-58822 Change-Id: Id6fbb99f6afd08ee420099cd66372732d7598d9e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/corelib/mimetypes/qmimeprovider.cpp5
-rw-r--r--tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp1
2 files changed, 5 insertions, 1 deletions
diff --git a/src/corelib/mimetypes/qmimeprovider.cpp b/src/corelib/mimetypes/qmimeprovider.cpp
index 959421bf52..5c0acce4c3 100644
--- a/src/corelib/mimetypes/qmimeprovider.cpp
+++ b/src/corelib/mimetypes/qmimeprovider.cpp
@@ -296,12 +296,15 @@ QMimeGlobMatchResult QMimeBinaryProvider::findByFileName(const QString &fileName
const QString lowerFileName = fileName.toLower();
// TODO this parses in the order (local, global). Check that it handles "NOGLOBS" correctly.
for (CacheFile *cacheFile : qAsConst(m_cacheFiles)) {
+ // Check literals (e.g. "Makefile")
matchGlobList(result, cacheFile, cacheFile->getUint32(PosLiteralListOffset), fileName);
+ // Check complex globs (e.g. "callgrind.out[0-9]*")
matchGlobList(result, cacheFile, cacheFile->getUint32(PosGlobListOffset), fileName);
+ // Check the very common *.txt cases with the suffix tree
const int reverseSuffixTreeOffset = cacheFile->getUint32(PosReverseSuffixTreeOffset);
const int numRoots = cacheFile->getUint32(reverseSuffixTreeOffset);
const int firstRootOffset = cacheFile->getUint32(reverseSuffixTreeOffset + 4);
- matchSuffixTree(result, cacheFile, numRoots, firstRootOffset, lowerFileName, fileName.length() - 1, false);
+ matchSuffixTree(result, cacheFile, numRoots, firstRootOffset, lowerFileName, lowerFileName.length() - 1, false);
if (result.m_matchingMimeTypes.isEmpty())
matchSuffixTree(result, cacheFile, numRoots, firstRootOffset, fileName, fileName.length() - 1, true);
}
diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp
index 8058d3c897..2edb94d542 100644
--- a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp
+++ b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp
@@ -307,6 +307,7 @@ void tst_QMimeDatabase::mimeTypesForFileName_data()
QTest::newRow("txtfoobar, 0 hit") << "foo.foobar" << QStringList();
QTest::newRow("m, 2 hits") << "foo.m" << (QStringList() << "text/x-matlab" << "text/x-objcsrc");
QTest::newRow("sub, 3 hits") << "foo.sub" << (QStringList() << "text/x-microdvd" << "text/x-mpsub" << "text/x-subviewer");
+ QTest::newRow("non_ascii") << QString::fromUtf8("AİİA.pdf") << (QStringList() << "application/pdf");
}
void tst_QMimeDatabase::mimeTypesForFileName()