summaryrefslogtreecommitdiff
path: root/src/libs/qmljs/qmljsutils.cpp
diff options
context:
space:
mode:
authorMarco Benelli <marco.benelli@theqtcompany.com>2016-05-10 09:48:36 +0200
committerMarco Benelli <marco.benelli@qt.io>2016-05-13 07:02:04 +0000
commit78944e60ba60703262eea582152e75a306041e5e (patch)
treea46081541ba48778a355748487a04fb6d8db145e /src/libs/qmljs/qmljsutils.cpp
parent60f092f6bb0b3ba76cc227bda94ca9e4ad84eaa0 (diff)
downloadqt-creator-78944e60ba60703262eea582152e75a306041e5e.tar.gz
QmlJs: handle the undefined version in module lookup.
The module lookup used to not consider the undefined version (-1.-1) a valid version number. This caused QtCreator to crash because of a failing assertion. This patch makes the assertion more permissive and handle the lookup of an undefined version by substituting it with an empty string. Task-number: QTCREATORBUG-16220 Change-Id: Iac574cfc04b4718b0d0809352e5c9456e4392e83 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Diffstat (limited to 'src/libs/qmljs/qmljsutils.cpp')
-rw-r--r--src/libs/qmljs/qmljsutils.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/libs/qmljs/qmljsutils.cpp b/src/libs/qmljs/qmljsutils.cpp
index a3ebed5081..8f87b2c98f 100644
--- a/src/libs/qmljs/qmljsutils.cpp
+++ b/src/libs/qmljs/qmljsutils.cpp
@@ -197,15 +197,19 @@ DiagnosticMessage QmlJS::errorMessage(const AST::SourceLocation &loc, const QStr
return DiagnosticMessage(Severity::Error, loc, message);
}
+namespace {
+const QString undefinedVersion = QLatin1String("-1.-1");
+}
+
/*!
* \brief Permissive validation of a string representing a module version.
* \param version
- * \return True if \p version is a valid version format (<digit(s)>.<digit(s)>) or if it is empty.
- * False otherwise.
+ * \return True if \p version is a valid version format (<digit(s)>.<digit(s)>), if it is the
+ * undefined version (-1.-1) or if it is empty. False otherwise.
*/
bool QmlJS::maybeModuleVersion(const QString &version) {
QRegularExpression re(QLatin1String("^\\d+\\.\\d+$"));
- return version.isEmpty() || re.match(version).hasMatch();
+ return version.isEmpty() || version == undefinedVersion || re.match(version).hasMatch();
}
/*!
@@ -235,12 +239,18 @@ QString QmlJS::modulePath(const QString &name, const QString &version,
if (importPaths.isEmpty())
return QString();
+ const QString sanitizedVersion = version == undefinedVersion ? QString() : version;
const QStringList parts = name.split(QLatin1Char('.'), QString::SkipEmptyParts);
auto mkpath = [] (const QStringList &xs) -> QString { return xs.join(QLatin1Char('/')); };
+ // Regular expression for building candidates by successively removing minor and major
+ // version numbers. It does not match the undefined version, so it has to be applied to the
+ // sanitized version.
+ const QRegularExpression re("\\.?\\d+$");
+
QString candidate;
- for (QString ver = version; ; ver.remove(QRegularExpression(QLatin1String("\\.?\\d+$")))) {
+ for (QString ver = sanitizedVersion; ; ver.remove(re)) {
for (const QString &path: importPaths) {
if (ver.isEmpty()) {
candidate = QDir::cleanPath(QString::fromLatin1("%1/%2").arg(path, mkpath(parts)));