From 239dd9fef153286832c853eefb9fc075a1eafbe3 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 21 May 2012 15:14:40 +0200 Subject: Add the QUrl::DecodedMode parsing mode This mode will be used to support parsing of URL components in their fully-decoded forms. It is not permitted when parsing the full URL, as that would be ambiguous. Change-Id: Id8d39a740845ae8d1efef894085280b322e39c0a Reviewed-by: Lars Knoll Reviewed-by: David Faure Reviewed-by: Shane Kearns --- src/corelib/io/qurl.cpp | 23 ++++++++++++++++++----- src/corelib/io/qurl.h | 3 ++- 2 files changed, 20 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 319de070ee..bb97890d15 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -132,6 +132,12 @@ \value StrictMode Only valid URLs are accepted. This mode is useful for general URL validation. + \value DecodedMode QUrl will interpret the URL component in the fully-decoded form, + where percent characters stand for themselves, not as the beginning + of a percent-encoded sequence. This mode is only valid for the + setters setting components of a URL; it is not permitted in + the QUrl constructor, in fromEncoded() or in setUrl(). + In TolerantMode, the parser has the following behaviour: \list @@ -1460,7 +1466,8 @@ const QByteArray &QUrlPrivate::normalized() const will accept any character in any position. In StrictMode, encoding mistakes will not be tolerated and QUrl will also check that certain forbidden characters are not present in unencoded form. If an error is detected in - StrictMode, isValid() will return false. + StrictMode, isValid() will return false. The parsing mode DecodedMode is not + permitted in this context. Example: @@ -1550,14 +1557,19 @@ void QUrl::clear() will accept any character in any position. In StrictMode, encoding mistakes will not be tolerated and QUrl will also check that certain forbidden characters are not present in unencoded form. If an error is detected in - StrictMode, isValid() will return false. + StrictMode, isValid() will return false. The parsing mode DecodedMode is + not permitted in this context and will produce a run-time warning. \sa setEncodedUrl() */ void QUrl::setUrl(const QString &url, ParsingMode parsingMode) { - detach(); - d->parse(url, parsingMode); + if (parsingMode == DecodedMode) { + qWarning("QUrl: QUrl::DecodedMode is not permitted when parsing a full URL"); + } else { + detach(); + d->parse(url, parsingMode); + } } @@ -2219,7 +2231,8 @@ QByteArray QUrl::toEncoded(FormattingOptions options) const Parses \a input and returns the corresponding QUrl. \a input is assumed to be in encoded form, containing only ASCII characters. - Parses the URL using \a parsingMode. + Parses the URL using \a parsingMode. See setUrl() for more information on + this parameter. QUrl::DecodedMode is not permitted in this context. \sa toEncoded(), setUrl() */ diff --git a/src/corelib/io/qurl.h b/src/corelib/io/qurl.h index 79968e5587..533489ae2b 100644 --- a/src/corelib/io/qurl.h +++ b/src/corelib/io/qurl.h @@ -118,7 +118,8 @@ class Q_CORE_EXPORT QUrl public: enum ParsingMode { TolerantMode, - StrictMode + StrictMode, + DecodedMode }; // encoding / toString values -- cgit v1.2.3