QmlProjectExporter: Refuse to read qmldir files from illegal locations

Change-Id: Ifafbb252c38ed4b384abf4dcaeb9b3b2cbe8684e
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Knud Dollereder
2025-03-31 16:44:57 +02:00
parent 3d8237845e
commit 84d227e059
2 changed files with 25 additions and 0 deletions

View File

@@ -255,12 +255,36 @@ bool CMakeGenerator::isMockModule(const NodePtr &node) const
return false;
}
bool CMakeGenerator::checkQmlDirLocation(const Utils::FilePath &filePath) const
{
QTC_ASSERT(m_root, return false);
QTC_ASSERT(buildSystem(), return false);
Utils::FilePath dirPath = filePath.parentDir().cleanPath();
Utils::FilePath rootPath = m_root->dir.cleanPath();
if (dirPath==rootPath)
return false;
for (const QString &path : buildSystem()->allImports()) {
Utils::FilePath importPath = rootPath.pathAppended(path).cleanPath();
if (dirPath==importPath)
return false;
}
return true;
}
void CMakeGenerator::readQmlDir(const Utils::FilePath &filePath, NodePtr &node) const
{
node->uri = "";
node->name = "";
node->singletons.clear();
if (!checkQmlDirLocation(filePath)) {
QString text("Unexpected location for qmldir file.");
logIssue(ProjectExplorer::Task::Warning, text, filePath);
return;
}
if (isMockModule(node))
node->type = Node::Type::MockModule;
else

View File

@@ -44,6 +44,7 @@ private:
bool ignore(const Utils::FilePath &path) const;
bool checkUri(const QString& uri, const Utils::FilePath &path) const;
bool isMockModule(const NodePtr &node) const;
bool checkQmlDirLocation(const Utils::FilePath &path) const;
void createCMakeFiles(const NodePtr &node) const;
void createSourceFiles() const;