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

[REG 6.8.0 -> 6.8.1] QUrl::resolved() can produce an invalid path like "/../"

    XMLWordPrintable

Details

    • Linux/X11
    • 340c9d88a (dev), 8c5736e68 (6.9), d4ceec964 (6.8)

    Description

      Since Qt 6.8.1, resolving a local-file URL can produce an invalid path like "/../", for which QFileInfo{url.path()}.isRelative() returns false. Adjusting such an invalid-path URL via url=url.adjusted(QUrl::NormalizePathSegments) does not change it either.

      For example, with Qt 6.8.1, the following code

      auto url = QUrl::fromUserInput(QStringLiteral("/"));
      QUrl relative(QStringLiteral("../"));
      auto resolved = url.resolved(relative);
      qCritical() << url << relative << resolved;

      prints
      QUrl("file:///") QUrl("../") QUrl("file:///../")

      With Qt 5.15.16 (and, as far as I know, with Qt 6.8.0), the same code prints
      QUrl("file:///") QUrl("../") QUrl("file:///")

      The same issue also affects the following values of relative:

      • ".."
      • "../../../"
      • "../rel"

      Something similar happens on Windows, but in fewer scenarios:

      QUrl::fromUserInput("C:/").resolved("../../../") produces the path "/.." instead of "C:";
      QUrl::fromUserInput("C:/").resolved("../../relative") produces the path "/relative" instead of "C:/relative";
      QUrl::fromUserInput("C:/").resolved("../../../../../../../invalid") produces the path "/../../../../../invalid" instead of "C:/invalid";

      (the Windows examples may contain mistakes, because I have inferred them from KDevelop CI test failures)

      The behavior of older Qt versions matches standard operating system command line behaviors of the command cd .. :

      • running cd .. in the root directory in Bash keeps the root directory current (no change);
      • running cd .. in the root directory of a drive in Windows cmd keeps the drive root directory current (no change).

      This regression causes failures of KDevelop's TestPath unit test, but I am not aware of any problems for non-test code.

      Attachments

        For Gerrit Dashboard: QTBUG-133402
        # Subject Branch Project Status CR V

        Activity

          People

            thiago Thiago Macieira
            vedg Igor Kushnir
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes