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

`QUrl::resolved` gives wrong result when there are more `..`s in relative reference

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.6.1
    • Core: URL Handling
    • None
    • All

    Description

      https://www.rfc-editor.org/rfc/rfc3986

      code:

      #include <QUrl>
      #include <boost/url.hpp>
      
      int main(int argc, char *argv[])
      {
          for (QUrl a1 : {
                   QUrl("scheme:a/b/c"),
                   QUrl("scheme:a/b/c/"),
                   QUrl("scheme:/a/b/c"),
                   QUrl("scheme:/a/b/c/"),
               })
          {
              for (QUrl a2 : {QUrl("../../../.."), QUrl("../../../../")})
              {
                  qDebug() << a1 << a1.scheme() << a1.userName() << a1.password() << a1.host() << a1.port() << a1.path() << a1.query() << a1.fragment();
      
                  qDebug() << a2 << a2.scheme() << a2.userName() << a2.password() << a2.host() << a2.port() << a2.path() << a2.query() << a2.fragment();
      
                  QUrl a3 = a1.resolved(a2);
                  qDebug() << a3 << a3.scheme() << a3.userName() << a3.password() << a3.host() << a3.port() << a3.path() << a3.query() << a3.fragment();
                  // a3 = a3.adjusted(QUrl::UrlFormattingOption::NormalizePathSegments);
                  // qDebug() << a3 << a3.scheme() << a3.userName() << a3.password() << a3.host() << a3.port() << a3.path() << a3.query() << a3.fragment();
      
                  qDebug() << "";
              }
          }
          for (boost::system::result<boost::urls::url_view> a1 : {
                   boost::urls::parse_uri(boost::core::string_view("scheme:a/b/c")),
                   boost::urls::parse_uri(boost::core::string_view("scheme:a/b/c/")),
                   boost::urls::parse_uri(boost::core::string_view("scheme:/a/b/c")),
                   boost::urls::parse_uri(boost::core::string_view("scheme:/a/b/c/")),
               })
          {
              for (boost::system::result<boost::urls::url_view> a2 : {boost::urls::parse_relative_ref(boost::core::string_view("../../../..")), boost::urls::parse_relative_ref(boost::core::string_view("../../../../"))})
              {
                  qDebug() << q_has_char8_t::QUtf8StringView(a1->buffer()) << q_has_char8_t::QUtf8StringView(a1->scheme()) << a1->user() << a1->password() << a1->host() << q_has_char8_t::QUtf8StringView(a1->port()) << a1->path() << a1->query() << a1->fragment();
      
                  qDebug() << q_has_char8_t::QUtf8StringView(a2->buffer()) << q_has_char8_t::QUtf8StringView(a2->scheme()) << a2->user() << a2->password() << a2->host() << q_has_char8_t::QUtf8StringView(a2->port()) << a2->path() << a2->query() << a2->fragment();
      
                  boost::urls::url a3;
                  boost::urls::resolve(a1.value(), a2.value(), a3);
                  qDebug() << q_has_char8_t::QUtf8StringView(a3.buffer()) << q_has_char8_t::QUtf8StringView(a3.scheme()) << a3.user() << a3.password() << a3.host() << q_has_char8_t::QUtf8StringView(a3.port()) << a3.path() << a3.query() << a3.fragment();
                  // a3.normalize();
                  // qDebug() << q_has_char8_t::QUtf8StringView(a3.buffer()) << q_has_char8_t::QUtf8StringView(a3.scheme()) << a3.user() << a3.password() << a3.host() << q_has_char8_t::QUtf8StringView(a3.port()) << a3.path() << a3.query() << a3.fragment();
      
                  qDebug() << "";
              }
          }
      }
      

      output:

      QUrl("scheme:a/b/c") "scheme" "" "" "" -1 "a/b/c" "" ""
      QUrl("../../../..") "" "" "" "" -1 "../../../.." "" ""
      QUrl("scheme:..") "scheme" "" "" "" -1 ".." "" ""
      
      QUrl("scheme:a/b/c") "scheme" "" "" "" -1 "a/b/c" "" ""
      QUrl("../../../../") "" "" "" "" -1 "../../../../" "" ""
      QUrl("scheme:../") "scheme" "" "" "" -1 "../" "" ""
      
      QUrl("scheme:a/b/c/") "scheme" "" "" "" -1 "a/b/c/" "" ""
      QUrl("../../../..") "" "" "" "" -1 "../../../.." "" ""
      QUrl("scheme:..") "scheme" "" "" "" -1 ".." "" ""
      
      QUrl("scheme:a/b/c/") "scheme" "" "" "" -1 "a/b/c/" "" ""
      QUrl("../../../../") "" "" "" "" -1 "../../../../" "" ""
      QUrl("scheme:%00") "scheme" "" "" "" -1 "\u0000" "" ""
      
      QUrl("scheme:/a/b/c") "scheme" "" "" "" -1 "/a/b/c" "" ""
      QUrl("../../../..") "" "" "" "" -1 "../../../.." "" ""
      QUrl("scheme:/") "scheme" "" "" "" -1 "/" "" ""
      
      QUrl("scheme:/a/b/c") "scheme" "" "" "" -1 "/a/b/c" "" ""
      QUrl("../../../../") "" "" "" "" -1 "../../../../" "" ""
      QUrl("scheme:/") "scheme" "" "" "" -1 "/" "" ""
      
      QUrl("scheme:/a/b/c/") "scheme" "" "" "" -1 "/a/b/c/" "" ""
      QUrl("../../../..") "" "" "" "" -1 "../../../.." "" ""
      QUrl("scheme:/") "scheme" "" "" "" -1 "/" "" ""
      
      QUrl("scheme:/a/b/c/") "scheme" "" "" "" -1 "/a/b/c/" "" ""
      QUrl("../../../../") "" "" "" "" -1 "../../../../" "" ""
      QUrl("scheme:/") "scheme" "" "" "" -1 "/" "" ""
      
      "scheme:a/b/c" "scheme" "" "" "" "" "a/b/c" "" ""
      "../../../.." "" "" "" "" "" "../../../.." "" ""
      "scheme:" "scheme" "" "" "" "" "" "" ""
      
      "scheme:a/b/c" "scheme" "" "" "" "" "a/b/c" "" ""
      "../../../../" "" "" "" "" "" "../../../../" "" ""
      "scheme:" "scheme" "" "" "" "" "" "" ""
      
      "scheme:a/b/c/" "scheme" "" "" "" "" "a/b/c/" "" ""
      "../../../.." "" "" "" "" "" "../../../.." "" ""
      "scheme:.." "scheme" "" "" "" "" ".." "" ""
      
      "scheme:a/b/c/" "scheme" "" "" "" "" "a/b/c/" "" ""
      "../../../../" "" "" "" "" "" "../../../../" "" ""
      "scheme:../" "scheme" "" "" "" "" "../" "" ""
      
      "scheme:/a/b/c" "scheme" "" "" "" "" "/a/b/c" "" ""
      "../../../.." "" "" "" "" "" "../../../.." "" ""
      "scheme:/" "scheme" "" "" "" "" "/" "" ""
      
      "scheme:/a/b/c" "scheme" "" "" "" "" "/a/b/c" "" ""
      "../../../../" "" "" "" "" "" "../../../../" "" ""
      "scheme:/../../" "scheme" "" "" "" "" "/../../" "" ""
      
      "scheme:/a/b/c/" "scheme" "" "" "" "" "/a/b/c/" "" ""
      "../../../.." "" "" "" "" "" "../../../.." "" ""
      "scheme:/.." "scheme" "" "" "" "" "/.." "" ""
      
      "scheme:/a/b/c/" "scheme" "" "" "" "" "/a/b/c/" "" ""
      "../../../../" "" "" "" "" "" "../../../../" "" ""
      "scheme:/../" "scheme" "" "" "" "" "/../" "" ""
      

      expected output:

      result url should be

      scheme:/

      , result's path should be

      /

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            jhcarl0814 Han Jiang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes