Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
6.8.1
-
None
-
-
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 |
621924,5 | QUrl: avoid going up from the drive path on Windows file URLs | dev | qt/qtbase | Status: MERGED | +2 | 0 |
622442,2 | QUrl: avoid going up from the drive path on Windows file URLs | 6.9 | qt/qtbase | Status: MERGED | +2 | 0 |
622458,3 | QUrl: avoid going up from the drive path on Windows file URLs | 6.8 | qt/qtbase | Status: MERGED | +2 | 0 |