summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qurl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/io/qurl.cpp')
-rw-r--r--src/corelib/io/qurl.cpp85
1 files changed, 50 insertions, 35 deletions
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp
index 51c48b88d7..d4c5e03058 100644
--- a/src/corelib/io/qurl.cpp
+++ b/src/corelib/io/qurl.cpp
@@ -1,41 +1,33 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Copyright (C) 2012 Intel Corporation.
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL$
+** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
+** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-**
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -2338,7 +2330,7 @@ void QUrl::setHost(const QString &host, ParsingMode mode)
as DNS requests or in HTTP request headers). If that flag is not present,
this function returns the International Domain Name (IDN) in Unicode form,
according to the list of permissible top-level domains (see
- idnWhiteList()).
+ idnWhitelist()).
All other flags are ignored. Host names cannot contain control or percent
characters, so the returned value can be considered fully decoded.
@@ -2679,8 +2671,8 @@ void QUrl::setQuery(const QUrlQuery &query)
Sets the query string of the URL to an encoded version of \a
query. The contents of \a query are converted to a string
internally, each pair delimited by the character returned by
- pairDelimiter(), and the key and value are delimited by
- valueDelimiter().
+ queryPairDelimiter(), and the key and value are delimited by
+ queryValueDelimiter().
\note This method does not encode spaces (ASCII 0x20) as plus (+) signs,
like HTML forms do. If you need that kind of encoding, you must encode
@@ -2699,8 +2691,8 @@ void QUrl::setQuery(const QUrlQuery &query)
Sets the query string of the URL to the encoded version of \a
query. The contents of \a query are converted to a string
internally, each pair delimited by the character returned by
- pairDelimiter(), and the key and value are delimited by
- valueDelimiter().
+ queryPairDelimiter(), and the key and value are delimited by
+ queryValueDelimiter().
\obsolete Use QUrlQuery and setQuery().
@@ -2714,11 +2706,11 @@ void QUrl::setQuery(const QUrlQuery &query)
Inserts the pair \a key = \a value into the query string of the
URL.
- The key/value pair is encoded before it is added to the query. The
+ The key-value pair is encoded before it is added to the query. The
pair is converted into separate strings internally. The \a key and
\a value is first encoded into UTF-8 and then delimited by the
- character returned by valueDelimiter(). Each key/value pair is
- delimited by the character returned by pairDelimiter().
+ character returned by queryValueDelimiter(). Each key-value pair is
+ delimited by the character returned by queryPairDelimiter().
\note This method does not encode spaces (ASCII 0x20) as plus (+) signs,
like HTML forms do. If you need that kind of encoding, you must encode
@@ -2952,9 +2944,8 @@ QString QUrl::query(ComponentFormattingOptions options) const
The fragment is sometimes also referred to as the URL "reference".
Passing an argument of QString() (a null QString) will unset the fragment.
- Passing an argument of QString("") (an empty but not null QString)
- will set the fragment to an empty string (as if the original URL
- had a lone "#").
+ Passing an argument of QString("") (an empty but not null QString) will set the
+ fragment to an empty string (as if the original URL had a lone "#").
The \a fragment data is interpreted according to \a mode: in StrictMode,
any '%' characters must be followed by exactly two hexadecimal characters
@@ -3029,10 +3020,10 @@ QString QUrl::fragment(ComponentFormattingOptions options) const
The fragment is sometimes also referred to as the URL "reference".
- Passing an argument of QByteArray() (a null QByteArray) will unset
- the fragment. Passing an argument of QByteArray("") (an empty but
- not null QByteArray) will set the fragment to an empty string (as
- if the original URL had a lone "#").
+ Passing an argument of QByteArray() (a null QByteArray) will unset the fragment.
+ Passing an argument of QByteArray("") (an empty but not null QByteArray)
+ will set the fragment to an empty string (as if the original URL
+ had a lone "#").
\obsolete Use setFragment(), which has the same behavior of null / empty.
@@ -4088,6 +4079,11 @@ static QUrl adjustFtpPath(QUrl url)
return url;
}
+static bool isIp6(const QString &text)
+{
+ QIPAddressUtils::IPv6Address address;
+ return !text.isEmpty() && QIPAddressUtils::parseIp6(address, text.begin(), text.end()) == 0;
+}
// The following code has the following copyright:
/*
@@ -4144,8 +4140,18 @@ QUrl QUrl::fromUserInput(const QString &userInput, const QString &workingDirecto
if (trimmedString.isEmpty())
return QUrl();
- // Check both QUrl::isRelative (to detect full URLs) and QDir::isAbsolutePath (since on Windows drive letters can be interpreted as schemes)
+
+ // Check for IPv6 addresses, since a path starting with ":" is absolute (a resource)
+ // and IPv6 addresses can start with "c:" too
+ if (isIp6(trimmedString)) {
+ QUrl url;
+ url.setHost(trimmedString);
+ url.setScheme(QStringLiteral("http"));
+ return url;
+ }
+
QUrl url = QUrl(trimmedString, QUrl::TolerantMode);
+ // Check both QUrl::isRelative (to detect full URLs) and QDir::isAbsolutePath (since on Windows drive letters can be interpreted as schemes)
if (url.isRelative() && !QDir::isAbsolutePath(trimmedString)) {
QFileInfo fileInfo(QDir(workingDirectory), trimmedString);
if ((options & AssumeLocalFile) || fileInfo.exists())
@@ -4190,6 +4196,15 @@ QUrl QUrl::fromUserInput(const QString &userInput)
{
QString trimmedString = userInput.trimmed();
+ // Check for IPv6 addresses, since a path starting with ":" is absolute (a resource)
+ // and IPv6 addresses can start with "c:" too
+ if (isIp6(trimmedString)) {
+ QUrl url;
+ url.setHost(trimmedString);
+ url.setScheme(QStringLiteral("http"));
+ return url;
+ }
+
// Check first for files, since on Windows drive letters can be interpretted as schemes
if (QDir::isAbsolutePath(trimmedString))
return QUrl::fromLocalFile(trimmedString);