Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-122074

QFileInfo cannot handle ".." after filenames

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P2: Important
    • None
    • 6.7
    • Core: I/O
    • None

    Description

      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.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            sami.shalayel Sami Shalayel
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes