diff options
author | Sami Shalayel <sami.shalayel@qt.io> | 2022-11-17 18:17:26 +0100 |
---|---|---|
committer | Sami Shalayel <sami.shalayel@qt.io> | 2022-12-02 10:39:44 +0100 |
commit | 591306fb07346065482f796f6caf4bf7e0d8e826 (patch) | |
tree | 576b5929672f82da33fd15b4857f18a139e188f7 /tools | |
parent | ed83f0f795132ef20ee6fafbad911a3da0a6c481 (diff) |
qmltc: error out when encoutering invalid filenames
Dashes and other special characters in qml filenames makes
life quite complicated, the generated cpp file will contain
everywhere and be uncompilable.
Instead, directly print an error message explaoining which names
are allowed for type compilation and return.
Reasoning:
The name of the qml file is also the name of the qml object.
For example, using a dash in the filename makes the corresponding
qml type have a dash in its name and renders the type mostly
unsuable in qml.
Therefore, only allow characters, digits and underscores.
Pick-to: 6.4
Fixes: QTBUG-107079
Change-Id: I4bff12e4a644b479213e7cc578207c8a443fc517
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qmltc/main.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/tools/qmltc/main.cpp b/tools/qmltc/main.cpp index 5314b1a2c0..82860cfbfc 100644 --- a/tools/qmltc/main.cpp +++ b/tools/qmltc/main.cpp @@ -16,6 +16,7 @@ #include <QtCore/qfileinfo.h> #include <QtCore/qlibraryinfo.h> #include <QtCore/qcommandlineparser.h> +#include <QtCore/qregularexpression.h> #include <QtQml/private/qqmljslexer_p.h> #include <QtQml/private/qqmljsparser_p.h> @@ -123,6 +124,15 @@ int main(int argc, char **argv) return EXIT_FAILURE; } + static QRegularExpression nameChecker(u"^[a-zA-Z_][a-zA-Z0-9_]*\\.qml$"_s); + if (auto match = nameChecker.match(QUrl(url).fileName()); !match.hasMatch()) { + fprintf(stderr, + "The given QML filename is unsuited for type compilation: the name must consist of " + "letters, digits and underscores, starting with " + "a letter or an underscore and ending in '.qml'!\n"); + return EXIT_FAILURE; + } + QString sourceCode = loadUrl(url); if (sourceCode.isEmpty()) return EXIT_FAILURE; |