forked from qt-creator/qt-creator
QmlDesigner: Do not allow JavaScript keywords as ids
Change-Id: Ifbbc7c36778dcc4e63df8c34929cd7f872875087 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
committed by
Tim Jenssen
parent
d81becd5fc
commit
d75d94c8c0
@@ -477,9 +477,9 @@ QString AbstractView::generateNewId(const QString &prefixName) const
|
|||||||
QString newId = QString(QStringLiteral("%1")).arg(firstCharToLower(prefixName));
|
QString newId = QString(QStringLiteral("%1")).arg(firstCharToLower(prefixName));
|
||||||
newId.remove(QRegExp(QStringLiteral("[^a-zA-Z0-9_]")));
|
newId.remove(QRegExp(QStringLiteral("[^a-zA-Z0-9_]")));
|
||||||
|
|
||||||
while (hasId(newId) || rootModelNode().hasProperty(newId.toUtf8()) || newId == "item") {
|
while (!ModelNode::isValidId(newId) || hasId(newId) || rootModelNode().hasProperty(newId.toUtf8()) || newId == "item") {
|
||||||
counter += 1;
|
counter += 1;
|
||||||
newId = QString(QStringLiteral("%1%2")).arg(firstCharToLower(prefixName)).arg(counter);
|
newId = QString(QStringLiteral("%1%2")).arg(firstCharToLower(prefixName)).arg(counter - 1);
|
||||||
newId.remove(QRegExp(QStringLiteral("[^a-zA-Z0-9_]")));
|
newId.remove(QRegExp(QStringLiteral("[^a-zA-Z0-9_]")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -143,8 +143,34 @@ QString ModelNode::validId()
|
|||||||
|
|
||||||
static bool idIsQmlKeyWord(const QString& id)
|
static bool idIsQmlKeyWord(const QString& id)
|
||||||
{
|
{
|
||||||
QStringList keywords;
|
QStringList keywords = { "import",
|
||||||
keywords << QLatin1String("import") << QLatin1String("as");
|
"as",
|
||||||
|
"break",
|
||||||
|
"case",
|
||||||
|
"catch",
|
||||||
|
"continue",
|
||||||
|
"debugger",
|
||||||
|
"default",
|
||||||
|
"delete",
|
||||||
|
"do",
|
||||||
|
"else",
|
||||||
|
"finally",
|
||||||
|
"for",
|
||||||
|
"function",
|
||||||
|
"if",
|
||||||
|
"in",
|
||||||
|
"instanceof",
|
||||||
|
"new",
|
||||||
|
"return",
|
||||||
|
"switch",
|
||||||
|
"this",
|
||||||
|
"throw",
|
||||||
|
"try",
|
||||||
|
"typeof",
|
||||||
|
"var",
|
||||||
|
"void",
|
||||||
|
"while",
|
||||||
|
"with" };
|
||||||
|
|
||||||
return keywords.contains(id);
|
return keywords.contains(id);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user