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

QUrl::fromLocalFile should return valid URLs for UNC paths with invalid hosts (\\wsl$)

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3: Somewhat important
    • Resolution: Done
    • Affects Version/s: 5.12.9, 5.13.1, 5.15.0
    • Fix Version/s: 5.15.2, 6.0.0
    • Component/s: Core: I/O
    • Labels:
      None
    • Environment:
      Tested under Windows with Qt 5.12, 5.13 and 5.15, both can reproduce this issue. Let me know if you need any additional info.
    • Platform/s:
      Windows
    • Commits:
      97de53ee8cce3dc6347b08668f0de45e1000f01c 9ef4fba108761bf30b9572fc53eaf98008bb4aae (qt/qtbase/5.15)

      Description

      When using WSL2 (Windows Subsystem for Linux 2), the file system can be accessed from such path like \\wsl$\Ubuntu\home\username\filename.png , but when trying to use QUrl to store that path, it will not store the hostname ("wsl$") properly.

      QString filePath(R"(\\wsl$\Ubuntu\home\username\filename.png)");
      QString filePath2(R"(\\wsl\Ubuntu\home\username\filename.png)");
      // according to the documentation of QUrl::fromLocalFile():
      // ... also accepts paths with a doubled leading slash (or backslash) to indicate a remote file, as in "//servername/path/to/file.txt" ...
      QUrl url1 = QUrl::fromLocalFile(filePath);
      QUrl url2 = QUrl::fromUserInput(filePath);
      QUrl url3 = QUrl::fromLocalFile(filePath2);
      qDebug() << url1 << url2 << url3 << url1.host() << url3.host();
      // will print: QUrl("file:///Ubuntu/home/username/filename.png") QUrl("file:///Ubuntu/home/username/filename.png") QUrl("file://wsl/Ubuntu/home/username/filename.png") "" "wsl"
      

      After a quick look at the implementation of QUrl::fromLocalFile(), I found out when calling QUrl::setHost() with "wsl$", it will not set "wsl$" as the hostname, which caused this issue. I haven't dig-in to much so still don't know what's the root of this issue.

      Let me know if you need any additional info for this issue.

      ps. I did submit this issue as QTBUG-86275 earlier today but I cannot find it anymore but it seems that bug is a completely different bug now, don't know why..

        Attachments

          Issue Links

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

            Activity

              People

              Assignee:
              thiago Thiago Macieira
              Reporter:
              blumia Gary Wang
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes