aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
authorSami Shalayel <sami.shalayel@qt.io>2023-07-04 17:12:32 +0200
committerSami Shalayel <sami.shalayel@qt.io>2023-08-10 19:55:40 +0200
commita130481af21af38f931b98a33b84eaa0637e69c7 (patch)
treea548fe660ea9fa5b632b6639eaaff9be9fa209a3 /src/qml
parent62014e9cecc633a046754e5f76cae66f052ae17b (diff)
qmlls: check user-supplied names on renaming
Implement the checking of user-supplied names for renaming operations in QmlLSUtils and qqmlrenamesymbolsupport.cpp Add a helper method QQmlLSUtils::isValidEcmaScriptIdentifier that runs the lexer on an identifier. Reject identifiers that do not parse as T_IDENTIFIER, like keywords and invalid unicode escapes, for example. Extend QQmlLSUtilsExpressionType to contain the name of the current object. Drive-by change: fix a off-by-one bug in the lexer, where files (or identifiers, in this case) could not be lexed when they were ending with an unicode-sequence. Also, do not crash on JSIdentifiers without semantic scope in resolveIdentifierExpressionType. Add some tests, and fix a warning about positionAfterOneIndent not being used in tst_qmlls_modules.cpp. Add QQmlLSUtils::isChangedSignalName next to QQmlLSUtils::isChangedHandlerName, and QQmlLSUtils::isHandlerName and add tests for all three. Fixes: QTBUG-114951 Task-number: QTBUG-114788 Change-Id: I0f1a544b70dfb69bca4aef355a8a8658f1d23081 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml')
-rw-r--r--src/qml/common/qqmlsignalnames.cpp12
-rw-r--r--src/qml/common/qqmlsignalnames_p.h1
-rw-r--r--src/qml/parser/qqmljslexer.cpp3
3 files changed, 15 insertions, 1 deletions
diff --git a/src/qml/common/qqmlsignalnames.cpp b/src/qml/common/qqmlsignalnames.cpp
index c08277e7f1..5d46531dfb 100644
--- a/src/qml/common/qqmlsignalnames.cpp
+++ b/src/qml/common/qqmlsignalnames.cpp
@@ -174,6 +174,18 @@ std::optional<QString> QQmlSignalNames::handlerNameToSignalName(QStringView hand
return signalName;
}
+bool QQmlSignalNames::isChangedSignalName(QStringView signalName)
+{
+ const qsizetype smallestAllowedSize = strlen("XChanged");
+ if (signalName.size() < smallestAllowedSize || !signalName.endsWith(u"Changed"_s))
+ return false;
+
+ if (auto letter = firstLetter(signalName, 0, strlen("Changed")))
+ return letter->isLower();
+
+ return true;
+}
+
bool QQmlSignalNames::isChangedHandlerName(QStringView signalName)
{
const qsizetype smallestAllowedSize = strlen("onXChanged");
diff --git a/src/qml/common/qqmlsignalnames_p.h b/src/qml/common/qqmlsignalnames_p.h
index 7c46a71b3a..f777e89812 100644
--- a/src/qml/common/qqmlsignalnames_p.h
+++ b/src/qml/common/qqmlsignalnames_p.h
@@ -44,6 +44,7 @@ public:
static std::optional<QString> handlerNameToSignalName(QStringView handler);
static bool isChangedHandlerName(QStringView signalName);
+ static bool isChangedSignalName(QStringView signalName);
static bool isHandlerName(QStringView signalName);
static QString addPrefixToPropertyName(QStringView prefix, QStringView propertyName);
diff --git a/src/qml/parser/qqmljslexer.cpp b/src/qml/parser/qqmljslexer.cpp
index 28f4684649..704c7eb00d 100644
--- a/src/qml/parser/qqmljslexer.cpp
+++ b/src/qml/parser/qqmljslexer.cpp
@@ -368,7 +368,8 @@ uint Lexer::decodeUnicodeEscapeCharacter(bool *ok)
{
Q_ASSERT(_state.currentChar == u'u');
scanChar(); // skip u
- if (_codePtr + 4 <= _endPtr && isHexDigit(_state.currentChar)) {
+ constexpr int distanceFromFirstHexToLastHex = 3;
+ if (_codePtr + distanceFromFirstHexToLastHex <= _endPtr && isHexDigit(_state.currentChar)) {
uint codePoint = 0;
for (int i = 0; i < 4; ++i) {
int digit = hexDigit(_state.currentChar);