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>
This commit is contained in:
David Faure 2017-02-16 13:34:54 +01:00
parent 8d6d68d3d3
commit 6c9b558153
2 changed files with 5 additions and 1 deletions

View File

@ -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);
}

View File

@ -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()