Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QUrl encoding problem (Qt 5.0.2)
Forum Updated to NodeBB v4.3 + New Features

QUrl encoding problem (Qt 5.0.2)

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 4.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    isoiphone
    wrote on last edited by
    #1

    NOTE: It looks like this post may not display properly on the forum, raw text of it is here: http://codepad.org/ykMXCtXN

    Hey All,
    I've been banging my head against the wall with this issue for hours, hoping someone here has a workaround!

    Is there a way to set a QUrl without it being 'smart' and automatically messing with the URL encoding? This default behaviour makes it impossible to form a valid request.

    I am using a rest API that requires me to POST to a URL which contains a path+filename. Here is my attempt to upload a file named "first;second.jpg"

    I construct a QByteArray that has the encoding I want, and print it out:
    @QByteArray rawUrl;
    ...
    qDebug() << "as QByteArray" << rawUrl;

    OUTPUT: as QByteArray "https://www.example.com/0/io/init_upload/%2FDesktop Uploads%2Fsemicolons%2Ffirst%3Bsecond.jpg"@

    As you can see the semicolon is nicely encoded as a %3B

    Then I construct a QUrl from it:
    @QUrl url(rawUrl); // using url.setUrl(rawUrl, QUrl::StrictMode) has same effect
    Q_ASSERT(url.isValid()); // succeeds
    qDebug() << "as QUrl " << url.toEncoded(QUrl::FullyEncoded);

    OUTPUT: as QUrl "https://www.example.com/0/io/init_upload/%2FDesktop Uploads%2Fsemicolons%2Ffirst;second.jpg"@

    As you can see the semicolon was decoded. When I create a QNetworkRequest with this URL, and observe what it is doing on the network with Charles Proxy I can see the request being made exactly matches that debug output.

    The expected behaviour is that the semicolon remains as %3B
    (This request fails because ; is just like ? or & and cuts the URL short as if arguments were to follow, and they arent. ugh.)

    1 Reply Last reply
    0
    • I Offline
      I Offline
      isoiphone
      wrote on last edited by
      #2

      (on a related note, I had to URL encode this entire post for it to show up correctly. Looks like this forum automagically decodes things as well! haha dang.)

      1 Reply Last reply
      0
      • I Offline
        I Offline
        isoiphone
        wrote on last edited by
        #3

        The forum ate this post, here is the RAW text: http://codepad.org/ykMXCtXN

        1 Reply Last reply
        0
        • I Offline
          I Offline
          isoiphone
          wrote on last edited by
          #4

          To paraphrase.

          Is it possible to create a QUrl that contains %3B (percent-three-be) in it? Not a semicolon, but that exact sequence of three characters.

          I cannot find a way to do this.

          1 Reply Last reply
          0
          • C Offline
            C Offline
            ChrisW67
            wrote on last edited by
            #5

            @
            QUrl url;
            url.setScheme("https");
            url.setHost("www.example.com");
            url.setEncodedPath("0/io/init_upload/%2FDesktop%20Uploads%2Fsemicolons%2Ffirst%3Bsecond.jpg");
            qDebug() << url.toEncoded();

            url = QUrl::fromEncoded("https://www.example.com/0/io/init_upload/%2FDesktop Uploads%2Fsemicolons%2Ffirst%3Bsecond.jpg");
            qDebug() << url.toEncoded();
            @
            Outputs:
            @
            "https://www.example.com/0/io/init_upload/%2FDesktop Uploads%2Fsemicolons%2Ffirst%3Bsecond.jpg"
            "https://www.example.com/0/io/init_upload/%2FDesktop Uploads%2Fsemicolons%2Ffirst%3Bsecond.jpg"
            @

            1 Reply Last reply
            0
            • I Offline
              I Offline
              isoiphone
              wrote on last edited by
              #6

              That looks sound, but unfortunately setEncodedPath() doesn't seem to exist in QT 5.0.2 anymore :(

              @qurl.h
              ...
              QT_DEPRECATED void setEncodedPath(const QByteArray &value)
              { setPath(fromEncodedComponent_helper(value)); }
              ...
              @

              Is there a way to access the deprecated function, or something new in 5 that has replaced it?

              1 Reply Last reply
              0
              • C Offline
                C Offline
                ChrisW67
                wrote on last edited by
                #7

                Hmmm, nice change of behaviour. I'll have to give it some thought.

                1 Reply Last reply
                0
                • I Offline
                  I Offline
                  isoiphone
                  wrote on last edited by
                  #8

                  This is still an issue with no apparent way to work around.

                  How should I got about filing a bug / making a request?

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    ArunSinghK
                    wrote on last edited by
                    #9

                    Hi,

                    Even I am facing similar issue, in my case colon (:) is getting decoded by default.

                    I found this ticket https://bugreports.qt-project.org/browse/QTBUG-31660 logged for this issue, but it does not say anything about when the fix will be available.

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved