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

QUrl::setEncodedQueryItems() does not replace existing query string.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.0.0
    • 5.0.0
    • Core: URL Handling
    • None
    • 79b14f42ba2062252bad5e5ad7c7986b967f6f6a

    Description

      We see a regression when passing a query string to QUrl::setEncodedQueryItems.
      The string get added to the query string that may already be present in the
      url. It used to replace any existing query string.

      The API documentation indicates that the passed query items are set to quesry
      string of url. Also, presence of equvalent add* functions (as opposed to set*
      suggest that the setters replace.

      Example code.

      main.cpp
      #include <QUrl>
      #include <QPair>
      #include <QList>
      #include <QDebug>
      
      typedef QPair<QByteArray, QByteArray> EncodedQueryItem;
      
      int main(int, char**) 
      {
          QUrl url("http://example.com");
      
          QList<EncodedQueryItem> list;
          list.append(EncodedQueryItem("foo", "123"));
          url.setEncodedQueryItems(list);
      
          list.clear();
          list.append(EncodedQueryItem("bar", "456"));
          url.setEncodedQueryItems(list);
          qDebug() << "Expected: \"http://example.com?bar=456\"";
          qDebug() << "Actual: " << url.toString();
      
          return 0;
      }
      

      Below are the result we get running the example code.

      Expected: "http://example.com?bar=456" 
      Actual:  "http://example.com?foo=123&bar=456"
      

      Attachments

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

        Activity

          People

            xcm Martin Petersson (Inactive)
            leonlee Leonard Lee
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes