Results 1 to 4 of 4

Thread: QUrl Percent Encoding and addQuery

  1. #1
    Join Date
    Nov 2012
    Posts
    47
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Question QUrl Percent Encoding and addQuery

    Qt Code:
    1. QString q1 = QUrl::toPercentEncoding(username,"","~");
    2.  
    3. QUrlQuery params;
    4. params.addQueryItem("id", q1);
    5.  
    6. QString temp1 = params.query();
    7. //temp1 is just testing
    To copy to clipboard, switch view to plain text mode 

    When I debug, q1 value is properly encoded.
    But for the params and temp1, some are not encoded?






    Example:

    1. Assigning username with value
    Qt Code:
    1. "~`!@#$%^&*()_+-=;':"<>?,./"
    To copy to clipboard, switch view to plain text mode 



    2. Now q1 will be
    Qt Code:
    1. "%7E%60%21%40%23%24%25%5E%26%2A%28%29_%2B-%3D%3B%27%3A%22%3C%3E%3F%2C.%2F"
    To copy to clipboard, switch view to plain text mode 
    Above 3 characters - _ and . is not encoded and its the correct thing, no problem here.




    3. But temp1 shows
    Qt Code:
    1. "id=~%60%21%40#%24%25%5E%26%2A%28%29_%2B-%3D%3B%27%3A%22%3C%3E%3F%2C.%2F"
    To copy to clipboard, switch view to plain text mode 
    Almost same as q1, but ~ and #is not encoded? Why is that



    4. Value of params.query id from debugging
    Qt Code:
    1. "~`%21%40#%24%25^&%2A%28%29_%2B-=%3B%27%3A"<>%3F%2C.%2F"
    To copy to clipboard, switch view to plain text mode 
    Many became not encoded, but not ALL. Cause as I know, without using to PercentEncoding, the @ character will not be encoded to %40





    I want value of params.query id to be encoded like q1.

    As you can see above, I insert q1 into params.addQuery.
    But then through debugging the params.query id value and temp1 is different from q1, some characters are not encoded.

    I don't use QUrl::FullyEncoded cause it does not actually encode URL reserve characters like @.Tried it
    How can I fix this?
    I'm a newbie. Don't trust me

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QUrl Percent Encoding and addQuery

    I think you should first construct your query and and then percent-encode it, not the other way round.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2012
    Posts
    47
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QUrl Percent Encoding and addQuery

    Quote Originally Posted by wysota View Post
    I think you should first construct your query and and then percent-encode it, not the other way round.
    percent encoding query will also encode characters like delimiter, in id = username, = will be %3D.
    There is no functions like setRawquery in QUrlQuery.


    Qt Code:
    1. QString q2 = QUrl::toPercentEncoding(username,"","~");
    2. params.addQueryItem("id", q1);
    3.  
    4. QString temp2 = params.query(QUrl::FullyEncoded);
    To copy to clipboard, switch view to plain text mode 

    q2, fully encoded including ~ and excluding *
    temp2 without QUrl::FullyEncoded, encoded all except ~ * and #
    temp2 with QUrl::FullyEncoded, encoded all except ~(wrong) and *(correct)

    Checking variables when debugging at right side window from this>params>d>itemList>1 show some not encoded, not only ~ * and #.
    How?
    Last edited by ttimt; 31st March 2015 at 16:04.
    I'm a newbie. Don't trust me

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QUrl Percent Encoding and addQuery

    Basically ~ and # don't need to be percent encoded. They are valid uri tokens.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QUrl with percent signs Issue
    By K_rol in forum Newbie
    Replies: 3
    Last Post: 21st February 2014, 05:32
  2. QUrl how to change it
    By alonso15 in forum Qt Programming
    Replies: 3
    Last Post: 4th August 2011, 15:54
  3. Replies: 0
    Last Post: 14th July 2011, 15:15
  4. QUrl and EUC-JP
    By Ignacio Serantes in forum Qt Programming
    Replies: 1
    Last Post: 22nd February 2009, 15:19
  5. QUrl parsing?
    By gfunk in forum Qt Programming
    Replies: 2
    Last Post: 17th January 2008, 10:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.