From 7721c3d27c6ad98f27de5ecd008d32b2efb25d59 Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 22 Oct 2012 12:42:05 +0200 Subject: QMimeDatabase: Fix handling of duplicate mimetype definitions. When both freedesktop.org.xml and kde.xml define text/x-qml (*.qml), the XML provider would look up *.qml, see two mimetypes, and treat that as a glob conflict, and proceed with contents-based-determination, which for this sample file, would find "C source" due to the C comment. Fixed by ignoring duplicate pattern-mimetype associations. The binary-cache provider doesn't have this problem, update-mime-database already filters out duplicates when generating the on-disk extension tree. Change-Id: Ie335b0b419e7413fa0550779709513f68c2bfc68 Reviewed-by: Thiago Macieira --- .../corelib/mimetypes/qmimedatabase/qml-again.xml | 12 ++++++ .../auto/corelib/mimetypes/qmimedatabase/test.qml | 44 ++++++++++++++++++++++ .../mimetypes/qmimedatabase/tst_qmimedatabase.cpp | 17 +++++++++ .../mimetypes/qmimedatabase/tst_qmimedatabase.h | 1 + 4 files changed, 74 insertions(+) create mode 100644 tests/auto/corelib/mimetypes/qmimedatabase/qml-again.xml create mode 100644 tests/auto/corelib/mimetypes/qmimedatabase/test.qml (limited to 'tests/auto/corelib/mimetypes') 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; }; -- cgit v1.2.3