aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmldirparser.cpp
diff options
context:
space:
mode:
authorMatthew Vogt <matthew.vogt@nokia.com>2012-07-25 16:59:17 +1000
committerQt by Nokia <qt-info@nokia.com>2012-07-31 00:22:36 +0200
commitc9b7582a2e7ad9fcd03dd999c3b7a16b72803238 (patch)
treed1ffdb193576fef0c243600f46c69b180d2ad2a8 /src/qml/qml/qqmldirparser.cpp
parent2e6accbbbb9783ff6e5ad171f179d5021b0761af (diff)
Implement strict mode for qmldir modules
Allow a module's qmldir to contain a module directive, which when present specifies 'strict mode' import processing. In strict mode, type registrations are only permitted into the namespace identified in the qmldir file's module directive. In addition, any type registrations to that namespace originating from other modules are treated as error conditions. Task-number: QTBUG-26551 Change-Id: I081bde2d3b83d3f28524440177fb2cd1ccee34ad Reviewed-by: Chris Adams <christopher.adams@nokia.com> Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
Diffstat (limited to 'src/qml/qml/qqmldirparser.cpp')
-rw-r--r--src/qml/qml/qqmldirparser.cpp42
1 files changed, 41 insertions, 1 deletions
diff --git a/src/qml/qml/qqmldirparser.cpp b/src/qml/qml/qqmldirparser.cpp
index 0805a24e6d..705f715a00 100644
--- a/src/qml/qml/qqmldirparser.cpp
+++ b/src/qml/qml/qqmldirparser.cpp
@@ -99,11 +99,13 @@ bool QQmlDirParser::parse(const QString &source)
_scripts.clear();
int lineNumber = 0;
+ bool firstLine = true;
const QChar *ch = source.constData();
while (!ch->isNull()) {
++lineNumber;
+ bool invalidLine = false;
const QChar *lineStart = ch;
scanSpace(ch);
@@ -129,6 +131,7 @@ bool QQmlDirParser::parse(const QString &source)
} else {
reportError(lineNumber, start-lineStart, QLatin1String("unexpected token"));
scanToEnd(ch);
+ invalidLine = true;
break;
}
scanSpace(ch);
@@ -137,9 +140,32 @@ bool QQmlDirParser::parse(const QString &source)
if (!ch->isNull())
++ch;
- if (sectionCount == 0) {
+ if (invalidLine) {
+ reportError(lineNumber, -1,
+ QString::fromUtf8("invalid qmldir directive contains too many tokens"));
+ continue;
+ } else if (sectionCount == 0) {
continue; // no sections, no party.
+ } else if (sections[0] == QLatin1String("module")) {
+ if (sectionCount != 2) {
+ reportError(lineNumber, -1,
+ QString::fromUtf8("module directive requires one argument, but %1 were provided").arg(sectionCount - 1));
+ continue;
+ }
+ if (!_typeNamespace.isEmpty()) {
+ reportError(lineNumber, -1,
+ QString::fromUtf8("only one module directive may be defined in a qmldir file"));
+ continue;
+ }
+ if (!firstLine) {
+ reportError(lineNumber, -1,
+ QString::fromUtf8("module directive must be the first directive in a qmldir file"));
+ continue;
+ }
+
+ _typeNamespace = sections[1];
+
} else if (sections[0] == QLatin1String("plugin")) {
if (sectionCount < 2) {
reportError(lineNumber, -1,
@@ -209,6 +235,8 @@ bool QQmlDirParser::parse(const QString &source)
reportError(lineNumber, -1,
QString::fromUtf8("a component declaration requires two or three arguments, but %1 were provided").arg(sectionCount));
}
+
+ firstLine = false;
}
return hasError();
@@ -239,16 +267,28 @@ void QQmlDirParser::setError(const QQmlError &e)
QList<QQmlError> QQmlDirParser::errors(const QString &uri) const
{
+ QUrl url(uri);
QList<QQmlError> errors = _errors;
for (int i = 0; i < errors.size(); ++i) {
QQmlError &e = errors[i];
QString description = e.description();
description.replace(QLatin1String("$$URI$$"), uri);
e.setDescription(description);
+ e.setUrl(url);
}
return errors;
}
+QString QQmlDirParser::typeNamespace() const
+{
+ return _typeNamespace;
+}
+
+void QQmlDirParser::setTypeNamespace(const QString &s)
+{
+ _typeNamespace = s;
+}
+
QList<QQmlDirParser::Plugin> QQmlDirParser::plugins() const
{
return _plugins;