[Qt-interest] QUrl issue while encoding an already encoded string

Thiago Macieira thiago at kde.org
Thu May 13 15:48:38 CEST 2010


Em Quinta-feira 13. Maio 2010, às 13.32.15, Mandeep Sandhu escreveu:
> >> But why is QUrl converting %2F to %252F contrary to the documentation
> >> of TolerantMode parsing?
> > 
> > Because you used the wrong function. If you have encoded data, you must
> > use the functions with "encoded" in the name (fromEncoded, toEncoded,
> > addEncodedQueryItem, encodedPath, etc.)
> 
> If I simply create a url like:
> 
> QUrl myUrl(<String with some pre-encoded param values>,
> QUrl::TolerantMode);
> 
> I'd expect QUrl to NOT touch the encoded part, as stated in the doc.
> 
> This seems like a bug.

No. Your expectation is wrong. It's a design flaw, not a bug: the constructor 
works as intended, but the intention is wrong.

I told you:
"Because you used the wrong function. If you have encoded data, you must use 
the functions with "encoded" in the name"

There's no "encoded" in your example. You used the QUrl constructor, which 
calls setUrl. Both the setUrl and the QUrl constructor it overloads say that 
the string you pass is expected to be unencoded:

"url is assumed to be in unicode format, with no percent encoding."
(http://doc.qt.nokia.com/4.6/qurl.html#setUrl)

Please use QUrl::fromEncoded if you have encoded data you need to place in a 
QUrl.

Forget QUrl's constructor, setUrl and toString. Those methods are a design 
flaw. They shouldn't exist, but now we have to put up with them until Qt 5.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100513/06c3fc4f/attachment.bin 


More information about the Qt-interest-old mailing list