From 4f55b9a0fa2e1473e5b34eeceaebb9fb0bbb58d9 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Fri, 28 Feb 2020 16:34:19 +0100 Subject: [PATCH] QmlDesigner: Do not allow keywords as properties in annotations Otherwise we get a syntax error. Change-Id: Id69be9ef0426dae64c461f21dda14eca340f720d Reviewed-by: Tim Jenssen --- .../designercore/model/rewriterview.cpp | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/plugins/qmldesigner/designercore/model/rewriterview.cpp b/src/plugins/qmldesigner/designercore/model/rewriterview.cpp index 8dad77ad44c..541ed1ceaf3 100644 --- a/src/plugins/qmldesigner/designercore/model/rewriterview.cpp +++ b/src/plugins/qmldesigner/designercore/model/rewriterview.cpp @@ -483,6 +483,42 @@ static QString replaceIllegalPropertyNameChars(const QString &str) return ret; } +static bool idIsQmlKeyWord(const QString& id) +{ + static const QSet keywords = { + "as", + "break", + "case", + "catch", + "continue", + "debugger", + "default", + "delete", + "do", + "else", + "finally", + "for", + "function", + "if", + "import", + "in", + "instanceof", + "new", + "return", + "switch", + "this", + "throw", + "try", + "typeof", + "var", + "void", + "while", + "with" + }; + + return keywords.contains(id); +} + QString RewriterView::auxiliaryDataAsQML() const { bool hasAuxData = false; @@ -523,6 +559,9 @@ QString RewriterView::auxiliaryDataAsQML() const if (key.endsWith("@Internal")) continue; + if (idIsQmlKeyWord(key)) + continue; + const QVariant value = data.value(key.toUtf8()); QString strValue = value.toString();