diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2012-08-16 15:31:06 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-20 21:59:32 +0200 |
commit | ce9b010ec619aa6e5f19b6ae208b76a4e398b20b (patch) | |
tree | 7eccc6c7a4a5654dae1956df4a3f262dd8c0f109 /src/corelib/io/qurl.h | |
parent | 60818231d82ca34f1d33ccb9ba7500b5470a3d0d (diff) |
Fix decoding of QByteArray in the deprecated "encoded" setters in QUrl
The asymmetry is intentional: the getters can use toLatin1() because the
called functions, with a QUrl::FullyEncoded parameter, return ASCII
only. This gives a small performance improvement over the need to run
the UTF-8 encoder.
However, the data passed to setters could contain non-ASCII binary data,
in addition to the percent-encoded data. We can't use fromUtf8 because
it's binary and we can't use toPercentEncoded because it already encoded.
Change-Id: I5ecdb49be5af51ac86fd9764eb3a6aa96385f512
Reviewed-by: David Faure <faure@kde.org>
Diffstat (limited to 'src/corelib/io/qurl.h')
-rw-r--r-- | src/corelib/io/qurl.h | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/corelib/io/qurl.h b/src/corelib/io/qurl.h index 8055129e4b..2a651b92f6 100644 --- a/src/corelib/io/qurl.h +++ b/src/corelib/io/qurl.h @@ -274,37 +274,37 @@ public: QT_DEPRECATED inline void removeAllEncodedQueryItems(const QByteArray &key); QT_DEPRECATED void setEncodedUrl(const QByteArray &u, ParsingMode mode = TolerantMode) - { setUrl(QString::fromUtf8(u.constData(), u.size()), mode); } + { setUrl(fromEncodedComponent_helper(u), mode); } QT_DEPRECATED QByteArray encodedUserName() const { return userName(FullyEncoded).toLatin1(); } QT_DEPRECATED void setEncodedUserName(const QByteArray &value) - { setUserName(QString::fromLatin1(value)); } + { setUserName(fromEncodedComponent_helper(value)); } QT_DEPRECATED QByteArray encodedPassword() const { return password(FullyEncoded).toLatin1(); } QT_DEPRECATED void setEncodedPassword(const QByteArray &value) - { setPassword(QString::fromLatin1(value)); } + { setPassword(fromEncodedComponent_helper(value)); } QT_DEPRECATED QByteArray encodedHost() const { return host(FullyEncoded).toLatin1(); } QT_DEPRECATED void setEncodedHost(const QByteArray &value) - { setHost(QString::fromLatin1(value)); } + { setHost(fromEncodedComponent_helper(value)); } QT_DEPRECATED QByteArray encodedPath() const { return path(FullyEncoded).toLatin1(); } QT_DEPRECATED void setEncodedPath(const QByteArray &value) - { setPath(QString::fromLatin1(value)); } + { setPath(fromEncodedComponent_helper(value)); } QT_DEPRECATED QByteArray encodedQuery() const { return toLatin1_helper(query(FullyEncoded)); } QT_DEPRECATED void setEncodedQuery(const QByteArray &value) - { setQuery(value.isNull() ? QString() : QString::fromLatin1(value)); } + { setQuery(fromEncodedComponent_helper(value)); } QT_DEPRECATED QByteArray encodedFragment() const { return toLatin1_helper(fragment(FullyEncoded)); } QT_DEPRECATED void setEncodedFragment(const QByteArray &value) - { setFragment(value.isNull() ? QString() : QString::fromLatin1(value)); } + { setFragment(fromEncodedComponent_helper(value)); } private: // helper function for the encodedQuery and encodedFragment functions @@ -315,6 +315,8 @@ private: return string.toLatin1(); } #endif +private: + static QString fromEncodedComponent_helper(const QByteArray &ba); public: static QString fromAce(const QByteArray &); |