From 646b60f0d3e45bcc240e5ad77a2700f4287c3162 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 30 Nov 2012 10:38:57 +0100 Subject: Limit case-sensitivity check in QML to file names. Provide for checking relative paths only; default to file names. Currently, the checking triggers on a drive letters and installation folder names, which is too strict. Task-number: QTBUG-28277 Change-Id: I2056a39b605f7891d2c3e395efc6bc541aa7e470 Reviewed-by: Kai Koehne --- src/declarative/qml/qdeclarativeengine.cpp | 17 ++++++++++++++++- src/declarative/qml/qdeclarativeglobal_p.h | 8 +++++++- .../qdeclarativelanguage/tst_qdeclarativelanguage.cpp | 9 +++++---- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index d91d54fb..fa7134ed 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -2469,7 +2469,7 @@ const QMetaObject *QDeclarativeEnginePrivate::metaObjectForType(int t) const } } -bool QDeclarative_isFileCaseCorrect(const QString &fileName) +bool QDeclarative_isFileCaseCorrect(const QString &fileName, int lengthIn /* = -1 */) { #if defined(Q_OS_MAC) || defined(Q_OS_WIN32) QFileInfo info(fileName); @@ -2493,6 +2493,20 @@ bool QDeclarative_isFileCaseCorrect(const QString &fileName) int canonicalLength = canonical.length(); int length = qMin(absoluteLength, canonicalLength); + if (lengthIn >= 0) { + length = qMin(lengthIn, length); + } else { + // No length given: Limit to file name. Do not trigger + // on drive letters or folder names. + int lastSlash = absolute.lastIndexOf(QLatin1Char('/')); + if (lastSlash < 0) + lastSlash = absolute.lastIndexOf(QLatin1Char('\\')); + if (lastSlash >= 0) { + const int fileNameLength = absoluteLength - 1 - lastSlash; + length = qMin(length, fileNameLength); + } + } + for (int ii = 0; ii < length; ++ii) { const QChar &a = absolute.at(absoluteLength - 1 - ii); const QChar &c = canonical.at(canonicalLength - 1 - ii); @@ -2503,6 +2517,7 @@ bool QDeclarative_isFileCaseCorrect(const QString &fileName) return false; } #else + Q_UNUSED(lengthIn) Q_UNUSED(fileName) #endif return true; diff --git a/src/declarative/qml/qdeclarativeglobal_p.h b/src/declarative/qml/qdeclarativeglobal_p.h index ab9725ba..9f0d5655 100644 --- a/src/declarative/qml/qdeclarativeglobal_p.h +++ b/src/declarative/qml/qdeclarativeglobal_p.h @@ -84,8 +84,14 @@ struct QDeclarativeGraphics_DerivedObject : public QObject It may have false positives (say the case is correct when it isn't), but it should never have a false negative (say the case is incorrect when it is correct). + + Length specifies specifies the number of characters to be checked from + behind. That is, if a file name results from a relative path specification + like "foo/bar.qml" and is made absolute, the original length (11) should + be passed indicating that only the last part of the relative path should + be checked. */ -bool QDeclarative_isFileCaseCorrect(const QString &fileName); +bool QDeclarative_isFileCaseCorrect(const QString &fileName, int length = -1); /*! Makes the \a object a child of \a parent. Note that when using this method, diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index 11633c06..e201807b 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -1818,15 +1818,16 @@ void tst_qdeclarativelanguage::importsOrder() void tst_qdeclarativelanguage::importIncorrectCase() { - QDeclarativeComponent component(&engine, testFileUrl("importIncorrectCase.qml")); + // Load "importIncorrectCase.qml" using wrong case + QDeclarativeComponent component(&engine, testFileUrl("ImportIncorrectCase.qml")); QList errors = component.errors(); QCOMPARE(errors.count(), 1); -#if defined(Q_OS_MAC) || defined(Q_OS_WIN32) - QString expectedError = QLatin1String("cannot load module \"com.Nokia.installedtest\": File name case mismatch for \"") + QFileInfo(__FILE__).absoluteDir().filePath("data/lib/com/Nokia/installedtest/qmldir") + QLatin1String("\""); +#if defined(Q_OS_MAC) || defined(Q_OS_WIN) + QString expectedError = QLatin1String("File name case mismatch"); #else - QString expectedError = QLatin1String("module \"com.Nokia.installedtest\" is not installed"); + QString expectedError = QLatin1String("File not found"); #endif QCOMPARE(errors.at(0).description(), expectedError); -- cgit v1.2.3