diff --git a/src/corelib/mimetypes/qmimeglobpattern.cpp b/src/corelib/mimetypes/qmimeglobpattern.cpp index 049a947939..b11add87e4 100644 --- a/src/corelib/mimetypes/qmimeglobpattern.cpp +++ b/src/corelib/mimetypes/qmimeglobpattern.cpp @@ -165,15 +165,15 @@ void QMimeAllGlobPatterns::addGlob(const QMimeGlobPattern &glob) // The bulk of the patterns is *.foo with weight 50 --> those go into the fast patterns hash. const QString extension = pattern.mid(2).toLower(); QStringList &patterns = m_fastPatterns[extension]; // find or create - // This would just slow things down: if (!patterns.contains(glob.mimeType())) - patterns.append(glob.mimeType()); + if (!patterns.contains(glob.mimeType())) + patterns.append(glob.mimeType()); } else { if (glob.weight() > 50) { - // This would just slow things down: if (!m_highWeightGlobs.hasPattern(glob.mimeType(), glob.pattern())) - m_highWeightGlobs.append(glob); + if (!m_highWeightGlobs.hasPattern(glob.mimeType(), glob.pattern())) + m_highWeightGlobs.append(glob); } else { - //This would just slow things down: if (!m_lowWeightGlobs.hasPattern(glob.mimeType(), glob.pattern())) - m_lowWeightGlobs.append(glob); + if (!m_lowWeightGlobs.hasPattern(glob.mimeType(), glob.pattern())) + m_lowWeightGlobs.append(glob); } } } diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/qml-again.xml b/tests/auto/corelib/mimetypes/qmimedatabase/qml-again.xml new file mode 100644 index 0000000000..d2461e02f9 --- /dev/null +++ b/tests/auto/corelib/mimetypes/qmimedatabase/qml-again.xml @@ -0,0 +1,12 @@ + + + + Qt Markup Language file + + + + + + + + diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/test.qml b/tests/auto/corelib/mimetypes/qmimedatabase/test.qml new file mode 100644 index 0000000000..5603b599d1 --- /dev/null +++ b/tests/auto/corelib/mimetypes/qmimedatabase/test.qml @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2012 David Faure +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 1.1 +Item { +} diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp index 0d41328320..740a9ea388 100644 --- a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp +++ b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp @@ -52,6 +52,7 @@ #include static const char yastFileName[] ="yast2-metapackage-handler-mimetypes.xml"; +static const char qmlAgainFileName[] ="qml-again.xml"; void initializeLang() { @@ -121,6 +122,10 @@ void tst_QMimeDatabase::initTestCase() QVERIFY2(!m_yastMimeTypes.isEmpty(), qPrintable(QString::fromLatin1("Cannot find '%1' starting from '%2'"). arg(yastFileName, QDir::currentPath()))); + m_qmlAgainFileName = QFINDTESTDATA(qmlAgainFileName); + QVERIFY2(!m_qmlAgainFileName.isEmpty(), + qPrintable(QString::fromLatin1("Cannot find '%1' starting from '%2'"). + arg(qmlAgainFileName, QDir::currentPath()))); init(); } @@ -796,11 +801,14 @@ void tst_QMimeDatabase::installNewGlobalMimeType() const QString destDir = mimeDir + QLatin1String("/packages/"); const QString destFile = destDir + QLatin1String(yastFileName); QFile::remove(destFile); + const QString destQmlFile = destDir + QLatin1String(qmlAgainFileName); + QFile::remove(destQmlFile); //qDebug() << destFile; if (!QFileInfo(destDir).isDir()) QVERIFY(QDir(m_globalXdgDir).mkpath(destDir)); QVERIFY(QFile::copy(m_yastMimeTypes, destFile)); + QVERIFY(QFile::copy(m_qmlAgainFileName, destQmlFile)); if (!waitAndRunUpdateMimeDatabase(mimeDir)) QSKIP("shared-mime-info not found, skipping mime.cache test"); @@ -809,8 +817,17 @@ void tst_QMimeDatabase::installNewGlobalMimeType() QVERIFY(db.mimeTypeForName(QLatin1String("text/x-suse-ymp")).isValid()); checkHasMimeType("text/x-suse-ymp"); + // Test that a double-definition of a mimetype doesn't lead to sniffing ("conflicting globs"). + const QString qmlTestFile = QFINDTESTDATA("test.qml"); + QVERIFY2(!qmlTestFile.isEmpty(), + qPrintable(QString::fromLatin1("Cannot find '%1' starting from '%2'"). + arg("test.qml", QDir::currentPath()))); + QCOMPARE(db.mimeTypeForFile(qmlTestFile).name(), + QString::fromLatin1("text/x-qml")); + // Now test removing it again QFile::remove(destFile); + QFile::remove(destQmlFile); if (!waitAndRunUpdateMimeDatabase(mimeDir)) QSKIP("shared-mime-info not found, skipping mime.cache test"); QCOMPARE(db.mimeTypeForFile(QLatin1String("foo.ymu"), QMimeDatabase::MatchExtension).name(), diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h index ea050b5014..6db09e2078 100644 --- a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h +++ b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h @@ -97,6 +97,7 @@ private: QString m_globalXdgDir; QString m_localXdgDir; QString m_yastMimeTypes; + QString m_qmlAgainFileName; QTemporaryDir m_temporaryDir; QString m_testSuite; };