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

    • All
    • 4b1547adc (dev), a1610c6c6 (6.8), d7e24e538 (6.7), 4e610d384 (tqtc/lts-6.5), 78e2d2475 (dev), e7bcf41c0 (dev), 2ce3153b8 (6.8), 7359d6320 (6.8), 53f8cb526 (6.7), d74355d4d (6.7), 75f2ffc82 (tqtc/lts-6.5), 70cf3a3ea (tqtc/lts-6.5), 214fbc658 (6.8.0)

    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

        Issue Links

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

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: