-
Bug
-
Resolution: Invalid
-
P2: Important
-
None
-
6.7
-
None
It seems that QFileInfo cannot handle ".." in filenames, for example:
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QtCore/QFileInfo>
#include <iostream>
#include <filesystem>
using namespace Qt::StringLiterals;
int main(int argc, char *argv[])
{
QString path
= u"/Users/sami/projects/qt-qmlls/qtdeclarative/tests/auto/qmldom/domdata/domitem/TestImports.qml/../.."_s;
QFileInfo info(path);
qDebug() << "canonical file path from QFileInfo: " << info.canonicalFilePath();
std::cout << "canonical file path from std::filesystem: "
<< std::filesystem::canonical(
"/Users/sami/projects/qt-qmlls/qtdeclarative/tests/"
"auto/qmldom/domdata/domitem/TestImports.qml/../..");
}
Will print the empty string for QFileInfo and the expected "/Users/sami/projects/qt-qmlls/qtdeclarative/tests/auto/qmldom/domdata" for std::filesystem.
Also, QFileInfo::exists() will return false for that same path. QFileInfo works correctly if the "/.." part happens behind a directory instead of a file, like "/Users/sami/projects/qt-qmlls/qtdeclarative/tests/auto/qmldom/domdata/domitem/.." is fine for example.