| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qurl.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||||||||
| 4 | ** Copyright (C) 2012 Intel Corporation. | - | ||||||||||||||||||||||||
| 5 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
| 6 | ** | - | ||||||||||||||||||||||||
| 7 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||||||||
| 8 | ** | - | ||||||||||||||||||||||||
| 9 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||||||||
| 10 | ** Commercial License Usage | - | ||||||||||||||||||||||||
| 11 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||
| 12 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||
| 13 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||
| 14 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
| 15 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
| 16 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||||||||
| 17 | ** | - | ||||||||||||||||||||||||
| 18 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||
| 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||
| 20 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||||||||
| 21 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||||||||
| 22 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||||||||
| 23 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||||||||
| 24 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||||||||
| 25 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||||||||
| 26 | ** | - | ||||||||||||||||||||||||
| 27 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||||||||
| 28 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||||||||
| 29 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||||||||
| 30 | ** | - | ||||||||||||||||||||||||
| 31 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
| 32 | ** | - | ||||||||||||||||||||||||
| 33 | ****************************************************************************/ | - | ||||||||||||||||||||||||
| 34 | - | |||||||||||||||||||||||||
| 35 | /*! | - | ||||||||||||||||||||||||
| 36 | \class QUrl | - | ||||||||||||||||||||||||
| 37 | \inmodule QtCore | - | ||||||||||||||||||||||||
| 38 | - | |||||||||||||||||||||||||
| 39 | \brief The QUrl class provides a convenient interface for working | - | ||||||||||||||||||||||||
| 40 | with URLs. | - | ||||||||||||||||||||||||
| 41 | - | |||||||||||||||||||||||||
| 42 | \reentrant | - | ||||||||||||||||||||||||
| 43 | \ingroup io | - | ||||||||||||||||||||||||
| 44 | \ingroup network | - | ||||||||||||||||||||||||
| 45 | \ingroup shared | - | ||||||||||||||||||||||||
| 46 | - | |||||||||||||||||||||||||
| 47 | - | |||||||||||||||||||||||||
| 48 | It can parse and construct URLs in both encoded and unencoded | - | ||||||||||||||||||||||||
| 49 | form. QUrl also has support for internationalized domain names | - | ||||||||||||||||||||||||
| 50 | (IDNs). | - | ||||||||||||||||||||||||
| 51 | - | |||||||||||||||||||||||||
| 52 | The most common way to use QUrl is to initialize it via the | - | ||||||||||||||||||||||||
| 53 | constructor by passing a QString. Otherwise, setUrl() can also | - | ||||||||||||||||||||||||
| 54 | be used. | - | ||||||||||||||||||||||||
| 55 | - | |||||||||||||||||||||||||
| 56 | URLs can be represented in two forms: encoded or unencoded. The | - | ||||||||||||||||||||||||
| 57 | unencoded representation is suitable for showing to users, but | - | ||||||||||||||||||||||||
| 58 | the encoded representation is typically what you would send to | - | ||||||||||||||||||||||||
| 59 | a web server. For example, the unencoded URL | - | ||||||||||||||||||||||||
| 60 | "http://bühler.example.com/List of applicants.xml" | - | ||||||||||||||||||||||||
| 61 | would be sent to the server as | - | ||||||||||||||||||||||||
| 62 | "http://xn--bhler-kva.example.com/List%20of%20applicants.xml". | - | ||||||||||||||||||||||||
| 63 | - | |||||||||||||||||||||||||
| 64 | A URL can also be constructed piece by piece by calling | - | ||||||||||||||||||||||||
| 65 | setScheme(), setUserName(), setPassword(), setHost(), setPort(), | - | ||||||||||||||||||||||||
| 66 | setPath(), setQuery() and setFragment(). Some convenience | - | ||||||||||||||||||||||||
| 67 | functions are also available: setAuthority() sets the user name, | - | ||||||||||||||||||||||||
| 68 | password, host and port. setUserInfo() sets the user name and | - | ||||||||||||||||||||||||
| 69 | password at once. | - | ||||||||||||||||||||||||
| 70 | - | |||||||||||||||||||||||||
| 71 | Call isValid() to check if the URL is valid. This can be done at any point | - | ||||||||||||||||||||||||
| 72 | during the constructing of a URL. If isValid() returns \c false, you should | - | ||||||||||||||||||||||||
| 73 | clear() the URL before proceeding, or start over by parsing a new URL with | - | ||||||||||||||||||||||||
| 74 | setUrl(). | - | ||||||||||||||||||||||||
| 75 | - | |||||||||||||||||||||||||
| 76 | Constructing a query is particularly convenient through the use of the \l | - | ||||||||||||||||||||||||
| 77 | QUrlQuery class and its methods QUrlQuery::setQueryItems(), | - | ||||||||||||||||||||||||
| 78 | QUrlQuery::addQueryItem() and QUrlQuery::removeQueryItem(). Use | - | ||||||||||||||||||||||||
| 79 | QUrlQuery::setQueryDelimiters() to customize the delimiters used for | - | ||||||||||||||||||||||||
| 80 | generating the query string. | - | ||||||||||||||||||||||||
| 81 | - | |||||||||||||||||||||||||
| 82 | For the convenience of generating encoded URL strings or query | - | ||||||||||||||||||||||||
| 83 | strings, there are two static functions called | - | ||||||||||||||||||||||||
| 84 | fromPercentEncoding() and toPercentEncoding() which deal with | - | ||||||||||||||||||||||||
| 85 | percent encoding and decoding of QString objects. | - | ||||||||||||||||||||||||
| 86 | - | |||||||||||||||||||||||||
| 87 | Calling isRelative() will tell whether or not the URL is | - | ||||||||||||||||||||||||
| 88 | relative. A relative URL can be resolved by passing it as argument | - | ||||||||||||||||||||||||
| 89 | to resolved(), which returns an absolute URL. isParentOf() is used | - | ||||||||||||||||||||||||
| 90 | for determining whether one URL is a parent of another. | - | ||||||||||||||||||||||||
| 91 | - | |||||||||||||||||||||||||
| 92 | fromLocalFile() constructs a QUrl by parsing a local | - | ||||||||||||||||||||||||
| 93 | file path. toLocalFile() converts a URL to a local file path. | - | ||||||||||||||||||||||||
| 94 | - | |||||||||||||||||||||||||
| 95 | The human readable representation of the URL is fetched with | - | ||||||||||||||||||||||||
| 96 | toString(). This representation is appropriate for displaying a | - | ||||||||||||||||||||||||
| 97 | URL to a user in unencoded form. The encoded form however, as | - | ||||||||||||||||||||||||
| 98 | returned by toEncoded(), is for internal use, passing to web | - | ||||||||||||||||||||||||
| 99 | servers, mail clients and so on. Both forms are technically correct | - | ||||||||||||||||||||||||
| 100 | and represent the same URL unambiguously -- in fact, passing either | - | ||||||||||||||||||||||||
| 101 | form to QUrl's constructor or to setUrl() will yield the same QUrl | - | ||||||||||||||||||||||||
| 102 | object. | - | ||||||||||||||||||||||||
| 103 | - | |||||||||||||||||||||||||
| 104 | QUrl conforms to the URI specification from | - | ||||||||||||||||||||||||
| 105 | \l{RFC 3986} (Uniform Resource Identifier: Generic Syntax), and includes | - | ||||||||||||||||||||||||
| 106 | scheme extensions from \l{RFC 1738} (Uniform Resource Locators). Case | - | ||||||||||||||||||||||||
| 107 | folding rules in QUrl conform to \l{RFC 3491} (Nameprep: A Stringprep | - | ||||||||||||||||||||||||
| 108 | Profile for Internationalized Domain Names (IDN)). It is also compatible with the | - | ||||||||||||||||||||||||
| 109 | \l{http://freedesktop.org/wiki/Specifications/file-uri-spec/}{file URI specification} | - | ||||||||||||||||||||||||
| 110 | from freedesktop.org, provided that the locale encodes file names using | - | ||||||||||||||||||||||||
| 111 | UTF-8 (required by IDN). | - | ||||||||||||||||||||||||
| 112 | - | |||||||||||||||||||||||||
| 113 | \section2 Error checking | - | ||||||||||||||||||||||||
| 114 | - | |||||||||||||||||||||||||
| 115 | QUrl is capable of detecting many errors in URLs while parsing it or when | - | ||||||||||||||||||||||||
| 116 | components of the URL are set with individual setter methods (like | - | ||||||||||||||||||||||||
| 117 | setScheme(), setHost() or setPath()). If the parsing or setter function is | - | ||||||||||||||||||||||||
| 118 | successful, any previously recorded error conditions will be discarded. | - | ||||||||||||||||||||||||
| 119 | - | |||||||||||||||||||||||||
| 120 | By default, QUrl setter methods operate in QUrl::TolerantMode, which means | - | ||||||||||||||||||||||||
| 121 | they accept some common mistakes and mis-representation of data. An | - | ||||||||||||||||||||||||
| 122 | alternate method of parsing is QUrl::StrictMode, which applies further | - | ||||||||||||||||||||||||
| 123 | checks. See QUrl::ParsingMode for a description of the difference of the | - | ||||||||||||||||||||||||
| 124 | parsing modes. | - | ||||||||||||||||||||||||
| 125 | - | |||||||||||||||||||||||||
| 126 | QUrl only checks for conformance with the URL specification. It does not | - | ||||||||||||||||||||||||
| 127 | try to verify that high-level protocol URLs are in the format they are | - | ||||||||||||||||||||||||
| 128 | expected to be by handlers elsewhere. For example, the following URIs are | - | ||||||||||||||||||||||||
| 129 | all considered valid by QUrl, even if they do not make sense when used: | - | ||||||||||||||||||||||||
| 130 | - | |||||||||||||||||||||||||
| 131 | \list | - | ||||||||||||||||||||||||
| 132 | \li "http:/filename.html" | - | ||||||||||||||||||||||||
| 133 | \li "mailto://example.com" | - | ||||||||||||||||||||||||
| 134 | \endlist | - | ||||||||||||||||||||||||
| 135 | - | |||||||||||||||||||||||||
| 136 | When the parser encounters an error, it signals the event by making | - | ||||||||||||||||||||||||
| 137 | isValid() return false and toString() / toEncoded() return an empty string. | - | ||||||||||||||||||||||||
| 138 | If it is necessary to show the user the reason why the URL failed to parse, | - | ||||||||||||||||||||||||
| 139 | the error condition can be obtained from QUrl by calling errorString(). | - | ||||||||||||||||||||||||
| 140 | Note that this message is highly technical and may not make sense to | - | ||||||||||||||||||||||||
| 141 | end-users. | - | ||||||||||||||||||||||||
| 142 | - | |||||||||||||||||||||||||
| 143 | QUrl is capable of recording only one error condition. If more than one | - | ||||||||||||||||||||||||
| 144 | error is found, it is undefined which error is reported. | - | ||||||||||||||||||||||||
| 145 | - | |||||||||||||||||||||||||
| 146 | \section2 Character Conversions | - | ||||||||||||||||||||||||
| 147 | - | |||||||||||||||||||||||||
| 148 | Follow these rules to avoid erroneous character conversion when | - | ||||||||||||||||||||||||
| 149 | dealing with URLs and strings: | - | ||||||||||||||||||||||||
| 150 | - | |||||||||||||||||||||||||
| 151 | \list | - | ||||||||||||||||||||||||
| 152 | \li When creating a QString to contain a URL from a QByteArray or a | - | ||||||||||||||||||||||||
| 153 | char*, always use QString::fromUtf8(). | - | ||||||||||||||||||||||||
| 154 | \endlist | - | ||||||||||||||||||||||||
| 155 | */ | - | ||||||||||||||||||||||||
| 156 | - | |||||||||||||||||||||||||
| 157 | /*! | - | ||||||||||||||||||||||||
| 158 | \enum QUrl::ParsingMode | - | ||||||||||||||||||||||||
| 159 | - | |||||||||||||||||||||||||
| 160 | The parsing mode controls the way QUrl parses strings. | - | ||||||||||||||||||||||||
| 161 | - | |||||||||||||||||||||||||
| 162 | \value TolerantMode QUrl will try to correct some common errors in URLs. | - | ||||||||||||||||||||||||
| 163 | This mode is useful for parsing URLs coming from sources | - | ||||||||||||||||||||||||
| 164 | not known to be strictly standards-conforming. | - | ||||||||||||||||||||||||
| 165 | - | |||||||||||||||||||||||||
| 166 | \value StrictMode Only valid URLs are accepted. This mode is useful for | - | ||||||||||||||||||||||||
| 167 | general URL validation. | - | ||||||||||||||||||||||||
| 168 | - | |||||||||||||||||||||||||
| 169 | \value DecodedMode QUrl will interpret the URL component in the fully-decoded form, | - | ||||||||||||||||||||||||
| 170 | where percent characters stand for themselves, not as the beginning | - | ||||||||||||||||||||||||
| 171 | of a percent-encoded sequence. This mode is only valid for the | - | ||||||||||||||||||||||||
| 172 | setters setting components of a URL; it is not permitted in | - | ||||||||||||||||||||||||
| 173 | the QUrl constructor, in fromEncoded() or in setUrl(). | - | ||||||||||||||||||||||||
| 174 | For more information on this mode, see the documentation for | - | ||||||||||||||||||||||||
| 175 | \l {QUrl::ComponentFormattingOption}{QUrl::FullyDecoded}. | - | ||||||||||||||||||||||||
| 176 | - | |||||||||||||||||||||||||
| 177 | In TolerantMode, the parser has the following behaviour: | - | ||||||||||||||||||||||||
| 178 | - | |||||||||||||||||||||||||
| 179 | \list | - | ||||||||||||||||||||||||
| 180 | - | |||||||||||||||||||||||||
| 181 | \li Spaces and "%20": unencoded space characters will be accepted and will | - | ||||||||||||||||||||||||
| 182 | be treated as equivalent to "%20". | - | ||||||||||||||||||||||||
| 183 | - | |||||||||||||||||||||||||
| 184 | \li Single "%" characters: Any occurrences of a percent character "%" not | - | ||||||||||||||||||||||||
| 185 | followed by exactly two hexadecimal characters (e.g., "13% coverage.html") | - | ||||||||||||||||||||||||
| 186 | will be replaced by "%25". Note that one lone "%" character will trigger | - | ||||||||||||||||||||||||
| 187 | the correction mode for all percent characters. | - | ||||||||||||||||||||||||
| 188 | - | |||||||||||||||||||||||||
| 189 | \li Reserved and unreserved characters: An encoded URL should only | - | ||||||||||||||||||||||||
| 190 | contain a few characters as literals; all other characters should | - | ||||||||||||||||||||||||
| 191 | be percent-encoded. In TolerantMode, these characters will be | - | ||||||||||||||||||||||||
| 192 | accepted if they are found in the URL: | - | ||||||||||||||||||||||||
| 193 | space / double-quote / "<" / ">" / "\" / | - | ||||||||||||||||||||||||
| 194 | "^" / "`" / "{" / "|" / "}" | - | ||||||||||||||||||||||||
| 195 | Those same characters can be decoded again by passing QUrl::DecodeReserved | - | ||||||||||||||||||||||||
| 196 | to toString() or toEncoded(). In the getters of individual components, | - | ||||||||||||||||||||||||
| 197 | those characters are often returned in decoded form. | - | ||||||||||||||||||||||||
| 198 | - | |||||||||||||||||||||||||
| 199 | \endlist | - | ||||||||||||||||||||||||
| 200 | - | |||||||||||||||||||||||||
| 201 | When in StrictMode, if a parsing error is found, isValid() will return \c | - | ||||||||||||||||||||||||
| 202 | false and errorString() will return a message describing the error. | - | ||||||||||||||||||||||||
| 203 | If more than one error is detected, it is undefined which error gets | - | ||||||||||||||||||||||||
| 204 | reported. | - | ||||||||||||||||||||||||
| 205 | - | |||||||||||||||||||||||||
| 206 | Note that TolerantMode is not usually enough for parsing user input, which | - | ||||||||||||||||||||||||
| 207 | often contains more errors and expectations than the parser can deal with. | - | ||||||||||||||||||||||||
| 208 | When dealing with data coming directly from the user -- as opposed to data | - | ||||||||||||||||||||||||
| 209 | coming from data-transfer sources, such as other programs -- it is | - | ||||||||||||||||||||||||
| 210 | recommended to use fromUserInput(). | - | ||||||||||||||||||||||||
| 211 | - | |||||||||||||||||||||||||
| 212 | \sa fromUserInput(), setUrl(), toString(), toEncoded(), QUrl::FormattingOptions | - | ||||||||||||||||||||||||
| 213 | */ | - | ||||||||||||||||||||||||
| 214 | - | |||||||||||||||||||||||||
| 215 | /*! | - | ||||||||||||||||||||||||
| 216 | \enum QUrl::UrlFormattingOption | - | ||||||||||||||||||||||||
| 217 | - | |||||||||||||||||||||||||
| 218 | The formatting options define how the URL is formatted when written out | - | ||||||||||||||||||||||||
| 219 | as text. | - | ||||||||||||||||||||||||
| 220 | - | |||||||||||||||||||||||||
| 221 | \value None The format of the URL is unchanged. | - | ||||||||||||||||||||||||
| 222 | \value RemoveScheme The scheme is removed from the URL. | - | ||||||||||||||||||||||||
| 223 | \value RemovePassword Any password in the URL is removed. | - | ||||||||||||||||||||||||
| 224 | \value RemoveUserInfo Any user information in the URL is removed. | - | ||||||||||||||||||||||||
| 225 | \value RemovePort Any specified port is removed from the URL. | - | ||||||||||||||||||||||||
| 226 | \value RemoveAuthority | - | ||||||||||||||||||||||||
| 227 | \value RemovePath The URL's path is removed, leaving only the scheme, | - | ||||||||||||||||||||||||
| 228 | host address, and port (if present). | - | ||||||||||||||||||||||||
| 229 | \value RemoveQuery The query part of the URL (following a '?' character) | - | ||||||||||||||||||||||||
| 230 | is removed. | - | ||||||||||||||||||||||||
| 231 | \value RemoveFragment | - | ||||||||||||||||||||||||
| 232 | \value RemoveFilename The filename (i.e. everything after the last '/' in the path) is removed. | - | ||||||||||||||||||||||||
| 233 | The trailing '/' is kept, unless StripTrailingSlash is set. | - | ||||||||||||||||||||||||
| 234 | Only valid if RemovePath is not set. | - | ||||||||||||||||||||||||
| 235 | \value PreferLocalFile If the URL is a local file according to isLocalFile() | - | ||||||||||||||||||||||||
| 236 | and contains no query or fragment, a local file path is returned. | - | ||||||||||||||||||||||||
| 237 | \value StripTrailingSlash The trailing slash is removed if one is present. | - | ||||||||||||||||||||||||
| 238 | \value NormalizePathSegments Modifies the path to remove redundant directory separators, | - | ||||||||||||||||||||||||
| 239 | and to resolve "."s and ".."s (as far as possible). | - | ||||||||||||||||||||||||
| 240 | - | |||||||||||||||||||||||||
| 241 | Note that the case folding rules in \l{RFC 3491}{Nameprep}, which QUrl | - | ||||||||||||||||||||||||
| 242 | conforms to, require host names to always be converted to lower case, | - | ||||||||||||||||||||||||
| 243 | regardless of the Qt::FormattingOptions used. | - | ||||||||||||||||||||||||
| 244 | - | |||||||||||||||||||||||||
| 245 | The options from QUrl::ComponentFormattingOptions are also possible. | - | ||||||||||||||||||||||||
| 246 | - | |||||||||||||||||||||||||
| 247 | \sa QUrl::ComponentFormattingOptions | - | ||||||||||||||||||||||||
| 248 | */ | - | ||||||||||||||||||||||||
| 249 | - | |||||||||||||||||||||||||
| 250 | /*! | - | ||||||||||||||||||||||||
| 251 | \enum QUrl::ComponentFormattingOption | - | ||||||||||||||||||||||||
| 252 | \since 5.0 | - | ||||||||||||||||||||||||
| 253 | - | |||||||||||||||||||||||||
| 254 | The component formatting options define how the components of an URL will | - | ||||||||||||||||||||||||
| 255 | be formatted when written out as text. They can be combined with the | - | ||||||||||||||||||||||||
| 256 | options from QUrl::FormattingOptions when used in toString() and | - | ||||||||||||||||||||||||
| 257 | toEncoded(). | - | ||||||||||||||||||||||||
| 258 | - | |||||||||||||||||||||||||
| 259 | \value PrettyDecoded The component is returned in a "pretty form", with | - | ||||||||||||||||||||||||
| 260 | most percent-encoded characters decoded. The exact | - | ||||||||||||||||||||||||
| 261 | behavior of PrettyDecoded varies from component to | - | ||||||||||||||||||||||||
| 262 | component and may also change from Qt release to Qt | - | ||||||||||||||||||||||||
| 263 | release. This is the default. | - | ||||||||||||||||||||||||
| 264 | - | |||||||||||||||||||||||||
| 265 | \value EncodeSpaces Leave space characters in their encoded form ("%20"). | - | ||||||||||||||||||||||||
| 266 | - | |||||||||||||||||||||||||
| 267 | \value EncodeUnicode Leave non-US-ASCII characters encoded in their UTF-8 | - | ||||||||||||||||||||||||
| 268 | percent-encoded form (e.g., "%C3%A9" for the U+00E9 | - | ||||||||||||||||||||||||
| 269 | codepoint, LATIN SMALL LETTER E WITH ACUTE). | - | ||||||||||||||||||||||||
| 270 | - | |||||||||||||||||||||||||
| 271 | \value EncodeDelimiters Leave certain delimiters in their encoded form, as | - | ||||||||||||||||||||||||
| 272 | would appear in the URL when the full URL is | - | ||||||||||||||||||||||||
| 273 | represented as text. The delimiters are affected | - | ||||||||||||||||||||||||
| 274 | by this option change from component to component. | - | ||||||||||||||||||||||||
| 275 | This flag has no effect in toString() or toEncoded(). | - | ||||||||||||||||||||||||
| 276 | - | |||||||||||||||||||||||||
| 277 | \value EncodeReserved Leave US-ASCII characters not permitted in the URL by | - | ||||||||||||||||||||||||
| 278 | the specification in their encoded form. This is the | - | ||||||||||||||||||||||||
| 279 | default on toString() and toEncoded(). | - | ||||||||||||||||||||||||
| 280 | - | |||||||||||||||||||||||||
| 281 | \value DecodeReserved Decode the US-ASCII characters that the URL specification | - | ||||||||||||||||||||||||
| 282 | does not allow to appear in the URL. This is the | - | ||||||||||||||||||||||||
| 283 | default on the getters of individual components. | - | ||||||||||||||||||||||||
| 284 | - | |||||||||||||||||||||||||
| 285 | \value FullyEncoded Leave all characters in their properly-encoded form, | - | ||||||||||||||||||||||||
| 286 | as this component would appear as part of a URL. When | - | ||||||||||||||||||||||||
| 287 | used with toString(), this produces a fully-compliant | - | ||||||||||||||||||||||||
| 288 | URL in QString form, exactly equal to the result of | - | ||||||||||||||||||||||||
| 289 | toEncoded() | - | ||||||||||||||||||||||||
| 290 | - | |||||||||||||||||||||||||
| 291 | \value FullyDecoded Attempt to decode as much as possible. For individual | - | ||||||||||||||||||||||||
| 292 | components of the URL, this decodes every percent | - | ||||||||||||||||||||||||
| 293 | encoding sequence, including control characters (U+0000 | - | ||||||||||||||||||||||||
| 294 | to U+001F) and UTF-8 sequences found in percent-encoded form. | - | ||||||||||||||||||||||||
| 295 | Use of this mode may cause data loss, see below for more information. | - | ||||||||||||||||||||||||
| 296 | - | |||||||||||||||||||||||||
| 297 | The values of EncodeReserved and DecodeReserved should not be used together | - | ||||||||||||||||||||||||
| 298 | in one call. The behavior is undefined if that happens. They are provided | - | ||||||||||||||||||||||||
| 299 | as separate values because the behavior of the "pretty mode" with regards | - | ||||||||||||||||||||||||
| 300 | to reserved characters is different on certain components and specially on | - | ||||||||||||||||||||||||
| 301 | the full URL. | - | ||||||||||||||||||||||||
| 302 | - | |||||||||||||||||||||||||
| 303 | \section2 Full decoding | - | ||||||||||||||||||||||||
| 304 | - | |||||||||||||||||||||||||
| 305 | The FullyDecoded mode is similar to the behavior of the functions returning | - | ||||||||||||||||||||||||
| 306 | QString in Qt 4.x, in that every character represents itself and never has | - | ||||||||||||||||||||||||
| 307 | any special meaning. This is true even for the percent character ('%'), | - | ||||||||||||||||||||||||
| 308 | which should be interpreted to mean a literal percent, not the beginning of | - | ||||||||||||||||||||||||
| 309 | a percent-encoded sequence. The same actual character, in all other | - | ||||||||||||||||||||||||
| 310 | decoding modes, is represented by the sequence "%25". | - | ||||||||||||||||||||||||
| 311 | - | |||||||||||||||||||||||||
| 312 | Whenever re-applying data obtained with QUrl::FullyDecoded into a QUrl, | - | ||||||||||||||||||||||||
| 313 | care must be taken to use the QUrl::DecodedMode parameter to the setters | - | ||||||||||||||||||||||||
| 314 | (like setPath() and setUserName()). Failure to do so may cause | - | ||||||||||||||||||||||||
| 315 | re-interpretation of the percent character ('%') as the beginning of a | - | ||||||||||||||||||||||||
| 316 | percent-encoded sequence. | - | ||||||||||||||||||||||||
| 317 | - | |||||||||||||||||||||||||
| 318 | This mode is quite useful when portions of a URL are used in a non-URL | - | ||||||||||||||||||||||||
| 319 | context. For example, to extract the username, password or file paths in an | - | ||||||||||||||||||||||||
| 320 | FTP client application, the FullyDecoded mode should be used. | - | ||||||||||||||||||||||||
| 321 | - | |||||||||||||||||||||||||
| 322 | This mode should be used with care, since there are two conditions that | - | ||||||||||||||||||||||||
| 323 | cannot be reliably represented in the returned QString. They are: | - | ||||||||||||||||||||||||
| 324 | - | |||||||||||||||||||||||||
| 325 | \list | - | ||||||||||||||||||||||||
| 326 | \li \b{Non-UTF-8 sequences:} URLs may contain sequences of | - | ||||||||||||||||||||||||
| 327 | percent-encoded characters that do not form valid UTF-8 sequences. Since | - | ||||||||||||||||||||||||
| 328 | URLs need to be decoded using UTF-8, any decoder failure will result in | - | ||||||||||||||||||||||||
| 329 | the QString containing one or more replacement characters where the | - | ||||||||||||||||||||||||
| 330 | sequence existed. | - | ||||||||||||||||||||||||
| 331 | - | |||||||||||||||||||||||||
| 332 | \li \b{Encoded delimiters:} URLs are also allowed to make a distinction | - | ||||||||||||||||||||||||
| 333 | between a delimiter found in its literal form and its equivalent in | - | ||||||||||||||||||||||||
| 334 | percent-encoded form. This is most commonly found in the query, but is | - | ||||||||||||||||||||||||
| 335 | permitted in most parts of the URL. | - | ||||||||||||||||||||||||
| 336 | \endlist | - | ||||||||||||||||||||||||
| 337 | - | |||||||||||||||||||||||||
| 338 | The following example illustrates the problem: | - | ||||||||||||||||||||||||
| 339 | - | |||||||||||||||||||||||||
| 340 | \code | - | ||||||||||||||||||||||||
| 341 | QUrl original("http://example.com/?q=a%2B%3Db%26c"); | - | ||||||||||||||||||||||||
| 342 | QUrl copy(original); | - | ||||||||||||||||||||||||
| 343 | copy.setQuery(copy.query(QUrl::FullyDecoded), QUrl::DecodedMode); | - | ||||||||||||||||||||||||
| 344 | - | |||||||||||||||||||||||||
| 345 | qDebug() << original.toString(); // prints: http://example.com/?q=a%2B%3Db%26c | - | ||||||||||||||||||||||||
| 346 | qDebug() << copy.toString(); // prints: http://example.com/?q=a+=b&c | - | ||||||||||||||||||||||||
| 347 | \endcode | - | ||||||||||||||||||||||||
| 348 | - | |||||||||||||||||||||||||
| 349 | If the two URLs were used via HTTP GET, the interpretation by the web | - | ||||||||||||||||||||||||
| 350 | server would probably be different. In the first case, it would interpret | - | ||||||||||||||||||||||||
| 351 | as one parameter, with a key of "q" and value "a+=b&c". In the second | - | ||||||||||||||||||||||||
| 352 | case, it would probably interpret as two parameters, one with a key of "q" | - | ||||||||||||||||||||||||
| 353 | and value "a =b", and the second with a key "c" and no value. | - | ||||||||||||||||||||||||
| 354 | - | |||||||||||||||||||||||||
| 355 | \sa QUrl::FormattingOptions | - | ||||||||||||||||||||||||
| 356 | */ | - | ||||||||||||||||||||||||
| 357 | - | |||||||||||||||||||||||||
| 358 | /*! | - | ||||||||||||||||||||||||
| 359 | \enum QUrl::UserInputResolutionOption | - | ||||||||||||||||||||||||
| 360 | \since 5.4 | - | ||||||||||||||||||||||||
| 361 | - | |||||||||||||||||||||||||
| 362 | The user input resolution options define how fromUserInput() should | - | ||||||||||||||||||||||||
| 363 | interpret strings that could either be a relative path or the short | - | ||||||||||||||||||||||||
| 364 | form of a HTTP URL. For instance \c{file.pl} can be either a local file | - | ||||||||||||||||||||||||
| 365 | or the URL \c{http://file.pl}. | - | ||||||||||||||||||||||||
| 366 | - | |||||||||||||||||||||||||
| 367 | \value DefaultResolution The default resolution mechanism is to check | - | ||||||||||||||||||||||||
| 368 | whether a local file exists, in the working | - | ||||||||||||||||||||||||
| 369 | directory given to fromUserInput, and only | - | ||||||||||||||||||||||||
| 370 | return a local path in that case. Otherwise a URL | - | ||||||||||||||||||||||||
| 371 | is assumed. | - | ||||||||||||||||||||||||
| 372 | \value AssumeLocalFile This option makes fromUserInput() always return | - | ||||||||||||||||||||||||
| 373 | a local path unless the input contains a scheme, such as | - | ||||||||||||||||||||||||
| 374 | \c{http://file.pl}. This is useful for applications | - | ||||||||||||||||||||||||
| 375 | such as text editors, which are able to create | - | ||||||||||||||||||||||||
| 376 | the file if it doesn't exist. | - | ||||||||||||||||||||||||
| 377 | - | |||||||||||||||||||||||||
| 378 | \sa fromUserInput() | - | ||||||||||||||||||||||||
| 379 | */ | - | ||||||||||||||||||||||||
| 380 | - | |||||||||||||||||||||||||
| 381 | /*! | - | ||||||||||||||||||||||||
| 382 | \fn QUrl::QUrl(QUrl &&other) | - | ||||||||||||||||||||||||
| 383 | - | |||||||||||||||||||||||||
| 384 | Move-constructs a QUrl instance, making it point at the same | - | ||||||||||||||||||||||||
| 385 | object that \a other was pointing to. | - | ||||||||||||||||||||||||
| 386 | - | |||||||||||||||||||||||||
| 387 | \since 5.2 | - | ||||||||||||||||||||||||
| 388 | */ | - | ||||||||||||||||||||||||
| 389 | - | |||||||||||||||||||||||||
| 390 | /*! | - | ||||||||||||||||||||||||
| 391 | \fn QUrl &QUrl::operator=(QUrl &&other) | - | ||||||||||||||||||||||||
| 392 | - | |||||||||||||||||||||||||
| 393 | Move-assigns \a other to this QUrl instance. | - | ||||||||||||||||||||||||
| 394 | - | |||||||||||||||||||||||||
| 395 | \since 5.2 | - | ||||||||||||||||||||||||
| 396 | */ | - | ||||||||||||||||||||||||
| 397 | - | |||||||||||||||||||||||||
| 398 | #include "qurl.h" | - | ||||||||||||||||||||||||
| 399 | #include "qurl_p.h" | - | ||||||||||||||||||||||||
| 400 | #include "qplatformdefs.h" | - | ||||||||||||||||||||||||
| 401 | #include "qstring.h" | - | ||||||||||||||||||||||||
| 402 | #include "qstringlist.h" | - | ||||||||||||||||||||||||
| 403 | #include "qdebug.h" | - | ||||||||||||||||||||||||
| 404 | #include "qhash.h" | - | ||||||||||||||||||||||||
| 405 | #include "qdir.h" // for QDir::fromNativeSeparators | - | ||||||||||||||||||||||||
| 406 | #include "qdatastream.h" | - | ||||||||||||||||||||||||
| 407 | #include "qtldurl_p.h" | - | ||||||||||||||||||||||||
| 408 | #include "private/qipaddress_p.h" | - | ||||||||||||||||||||||||
| 409 | #include "qurlquery.h" | - | ||||||||||||||||||||||||
| 410 | #if defined(Q_OS_WINCE_WM) | - | ||||||||||||||||||||||||
| 411 | #pragma optimize("g", off) | - | ||||||||||||||||||||||||
| 412 | #endif | - | ||||||||||||||||||||||||
| 413 | - | |||||||||||||||||||||||||
| 414 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
| 415 | extern QString qt_normalizePathSegments(const QString &name, bool allowUncPaths); // qdir.cpp | - | ||||||||||||||||||||||||
| 416 | - | |||||||||||||||||||||||||
| 417 | inline static bool isHex(char c) | - | ||||||||||||||||||||||||
| 418 | { | - | ||||||||||||||||||||||||
| 419 | c |= 0x20; | - | ||||||||||||||||||||||||
| 420 | return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f'); executed 59 times by 2 tests: return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f');Executed by:
| 0-59 | ||||||||||||||||||||||||
| 421 | } | - | ||||||||||||||||||||||||
| 422 | - | |||||||||||||||||||||||||
| 423 | static inline QString ftpScheme() | - | ||||||||||||||||||||||||
| 424 | { | - | ||||||||||||||||||||||||
| 425 | return QStringLiteral("ftp"); executed 55 times by 2 tests: return ([]() -> QString { enum { Size = sizeof(u"" "ftp")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "ftp" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());Executed by:
executed 55 times by 2 tests: return qstring_literal_temp;Executed by:
| 55 | ||||||||||||||||||||||||
| 426 | } | - | ||||||||||||||||||||||||
| 427 | - | |||||||||||||||||||||||||
| 428 | static inline QString fileScheme() | - | ||||||||||||||||||||||||
| 429 | { | - | ||||||||||||||||||||||||
| 430 | return QStringLiteral("file"); executed 17052 times by 34 tests: return ([]() -> QString { enum { Size = sizeof(u"" "file")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "file" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());Executed by:
executed 17052 times by 34 tests: return qstring_literal_temp;Executed by:
| 17052 | ||||||||||||||||||||||||
| 431 | } | - | ||||||||||||||||||||||||
| 432 | - | |||||||||||||||||||||||||
| 433 | static inline QString webDavScheme() | - | ||||||||||||||||||||||||
| 434 | { | - | ||||||||||||||||||||||||
| 435 | return QStringLiteral("webdavs"); executed 1 time by 1 test: return ([]() -> QString { enum { Size = sizeof(u"" "webdavs")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "webdavs" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());Executed by:
executed 1 time by 1 test: return qstring_literal_temp;Executed by:
| 1 | ||||||||||||||||||||||||
| 436 | } | - | ||||||||||||||||||||||||
| 437 | - | |||||||||||||||||||||||||
| 438 | static inline QString webDavSslTag() | - | ||||||||||||||||||||||||
| 439 | { | - | ||||||||||||||||||||||||
| 440 | return QStringLiteral("@SSL"); executed 4 times by 1 test: return ([]() -> QString { enum { Size = sizeof(u"" "@SSL")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "@SSL" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());Executed by:
executed 4 times by 1 test: return qstring_literal_temp;Executed by:
| 4 | ||||||||||||||||||||||||
| 441 | } | - | ||||||||||||||||||||||||
| 442 | - | |||||||||||||||||||||||||
| 443 | #ifdef Q_COMPILER_CLASS_ENUM | - | ||||||||||||||||||||||||
| 444 | # define colon_uchar : uchar | - | ||||||||||||||||||||||||
| 445 | #else | - | ||||||||||||||||||||||||
| 446 | # define colon_uchar | - | ||||||||||||||||||||||||
| 447 | #endif | - | ||||||||||||||||||||||||
| 448 | - | |||||||||||||||||||||||||
| 449 | class QUrlPrivate | - | ||||||||||||||||||||||||
| 450 | { | - | ||||||||||||||||||||||||
| 451 | public: | - | ||||||||||||||||||||||||
| 452 | enum Section colon_uchar { | - | ||||||||||||||||||||||||
| 453 | Scheme = 0x01, | - | ||||||||||||||||||||||||
| 454 | UserName = 0x02, | - | ||||||||||||||||||||||||
| 455 | Password = 0x04, | - | ||||||||||||||||||||||||
| 456 | UserInfo = UserName | Password, | - | ||||||||||||||||||||||||
| 457 | Host = 0x08, | - | ||||||||||||||||||||||||
| 458 | Port = 0x10, | - | ||||||||||||||||||||||||
| 459 | Authority = UserInfo | Host | Port, | - | ||||||||||||||||||||||||
| 460 | Path = 0x20, | - | ||||||||||||||||||||||||
| 461 | Hierarchy = Authority | Path, | - | ||||||||||||||||||||||||
| 462 | Query = 0x40, | - | ||||||||||||||||||||||||
| 463 | Fragment = 0x80, | - | ||||||||||||||||||||||||
| 464 | FullUrl = 0xff | - | ||||||||||||||||||||||||
| 465 | }; | - | ||||||||||||||||||||||||
| 466 | - | |||||||||||||||||||||||||
| 467 | enum Flags colon_uchar { | - | ||||||||||||||||||||||||
| 468 | IsLocalFile = 0x01 | - | ||||||||||||||||||||||||
| 469 | }; | - | ||||||||||||||||||||||||
| 470 | - | |||||||||||||||||||||||||
| 471 | enum ErrorCode { | - | ||||||||||||||||||||||||
| 472 | // the high byte of the error code matches the Section | - | ||||||||||||||||||||||||
| 473 | // the first item in each value must be the generic "Invalid xxx Error" | - | ||||||||||||||||||||||||
| 474 | InvalidSchemeError = Scheme << 8, | - | ||||||||||||||||||||||||
| 475 | - | |||||||||||||||||||||||||
| 476 | InvalidUserNameError = UserName << 8, | - | ||||||||||||||||||||||||
| 477 | - | |||||||||||||||||||||||||
| 478 | InvalidPasswordError = Password << 8, | - | ||||||||||||||||||||||||
| 479 | - | |||||||||||||||||||||||||
| 480 | InvalidRegNameError = Host << 8, | - | ||||||||||||||||||||||||
| 481 | InvalidIPv4AddressError, | - | ||||||||||||||||||||||||
| 482 | InvalidIPv6AddressError, | - | ||||||||||||||||||||||||
| 483 | InvalidCharacterInIPv6Error, | - | ||||||||||||||||||||||||
| 484 | InvalidIPvFutureError, | - | ||||||||||||||||||||||||
| 485 | HostMissingEndBracket, | - | ||||||||||||||||||||||||
| 486 | - | |||||||||||||||||||||||||
| 487 | InvalidPortError = Port << 8, | - | ||||||||||||||||||||||||
| 488 | PortEmptyError, | - | ||||||||||||||||||||||||
| 489 | - | |||||||||||||||||||||||||
| 490 | InvalidPathError = Path << 8, | - | ||||||||||||||||||||||||
| 491 | - | |||||||||||||||||||||||||
| 492 | InvalidQueryError = Query << 8, | - | ||||||||||||||||||||||||
| 493 | - | |||||||||||||||||||||||||
| 494 | InvalidFragmentError = Fragment << 8, | - | ||||||||||||||||||||||||
| 495 | - | |||||||||||||||||||||||||
| 496 | // the following two cases are only possible in combination | - | ||||||||||||||||||||||||
| 497 | // with presence/absence of the authority and scheme. See validityError(). | - | ||||||||||||||||||||||||
| 498 | AuthorityPresentAndPathIsRelative = Authority << 8 | Path << 8 | 0x10000, | - | ||||||||||||||||||||||||
| 499 | RelativeUrlPathContainsColonBeforeSlash = Scheme << 8 | Authority << 8 | Path << 8 | 0x10000, | - | ||||||||||||||||||||||||
| 500 | - | |||||||||||||||||||||||||
| 501 | NoError = 0 | - | ||||||||||||||||||||||||
| 502 | }; | - | ||||||||||||||||||||||||
| 503 | - | |||||||||||||||||||||||||
| 504 | struct Error { | - | ||||||||||||||||||||||||
| 505 | QString source; | - | ||||||||||||||||||||||||
| 506 | ErrorCode code; | - | ||||||||||||||||||||||||
| 507 | int position; | - | ||||||||||||||||||||||||
| 508 | }; | - | ||||||||||||||||||||||||
| 509 | - | |||||||||||||||||||||||||
| 510 | QUrlPrivate(); | - | ||||||||||||||||||||||||
| 511 | QUrlPrivate(const QUrlPrivate ©); | - | ||||||||||||||||||||||||
| 512 | ~QUrlPrivate(); | - | ||||||||||||||||||||||||
| 513 | - | |||||||||||||||||||||||||
| 514 | void parse(const QString &url, QUrl::ParsingMode parsingMode); | - | ||||||||||||||||||||||||
| 515 | bool isEmpty() const | - | ||||||||||||||||||||||||
| 516 | { return sectionIsPresent == 0 && port == -1 && path.isEmpty(); } executed 17287 times by 33 tests: return sectionIsPresent == 0 && port == -1 && path.isEmpty();Executed by:
| 1-17287 | ||||||||||||||||||||||||
| 517 | - | |||||||||||||||||||||||||
| 518 | Error *cloneError() const; | - | ||||||||||||||||||||||||
| 519 | void clearError(); | - | ||||||||||||||||||||||||
| 520 | void setError(ErrorCode errorCode, const QString &source, int supplement = -1); | - | ||||||||||||||||||||||||
| 521 | ErrorCode validityError(QString *source = 0, int *position = 0) const; | - | ||||||||||||||||||||||||
| 522 | bool validateComponent(Section section, const QString &input, int begin, int end); | - | ||||||||||||||||||||||||
| 523 | bool validateComponent(Section section, const QString &input) | - | ||||||||||||||||||||||||
| 524 | { return validateComponent(section, input, 0, uint(input.length())); } executed 21 times by 1 test: return validateComponent(section, input, 0, uint(input.length()));Executed by:
| 21 | ||||||||||||||||||||||||
| 525 | - | |||||||||||||||||||||||||
| 526 | // no QString scheme() const; | - | ||||||||||||||||||||||||
| 527 | void appendAuthority(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const; | - | ||||||||||||||||||||||||
| 528 | void appendUserInfo(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const; | - | ||||||||||||||||||||||||
| 529 | void appendUserName(QString &appendTo, QUrl::FormattingOptions options) const; | - | ||||||||||||||||||||||||
| 530 | void appendPassword(QString &appendTo, QUrl::FormattingOptions options) const; | - | ||||||||||||||||||||||||
| 531 | void appendHost(QString &appendTo, QUrl::FormattingOptions options) const; | - | ||||||||||||||||||||||||
| 532 | void appendPath(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const; | - | ||||||||||||||||||||||||
| 533 | void appendQuery(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const; | - | ||||||||||||||||||||||||
| 534 | void appendFragment(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const; | - | ||||||||||||||||||||||||
| 535 | - | |||||||||||||||||||||||||
| 536 | // the "end" parameters are like STL iterators: they point to one past the last valid element | - | ||||||||||||||||||||||||
| 537 | bool setScheme(const QString &value, int len, bool doSetError); | - | ||||||||||||||||||||||||
| 538 | void setAuthority(const QString &auth, int from, int end, QUrl::ParsingMode mode); | - | ||||||||||||||||||||||||
| 539 | void setUserInfo(const QString &userInfo, int from, int end); | - | ||||||||||||||||||||||||
| 540 | void setUserName(const QString &value, int from, int end); | - | ||||||||||||||||||||||||
| 541 | void setPassword(const QString &value, int from, int end); | - | ||||||||||||||||||||||||
| 542 | bool setHost(const QString &value, int from, int end, QUrl::ParsingMode mode); | - | ||||||||||||||||||||||||
| 543 | void setPath(const QString &value, int from, int end); | - | ||||||||||||||||||||||||
| 544 | void setQuery(const QString &value, int from, int end); | - | ||||||||||||||||||||||||
| 545 | void setFragment(const QString &value, int from, int end); | - | ||||||||||||||||||||||||
| 546 | - | |||||||||||||||||||||||||
| 547 | inline bool hasScheme() const { return sectionIsPresent & Scheme; } executed 10910 times by 33 tests: return sectionIsPresent & Scheme;Executed by:
| 10910 | ||||||||||||||||||||||||
| 548 | inline bool hasAuthority() const { return sectionIsPresent & Authority; } executed 10514 times by 31 tests: return sectionIsPresent & Authority;Executed by:
| 10514 | ||||||||||||||||||||||||
| 549 | inline bool hasUserInfo() const { return sectionIsPresent & UserInfo; } executed 7098 times by 22 tests: return sectionIsPresent & UserInfo;Executed by:
| 7098 | ||||||||||||||||||||||||
| 550 | inline bool hasUserName() const { return sectionIsPresent & UserName; } executed 4584 times by 18 tests: return sectionIsPresent & UserName;Executed by:
| 4584 | ||||||||||||||||||||||||
| 551 | inline bool hasPassword() const { return sectionIsPresent & Password; } executed 4373 times by 18 tests: return sectionIsPresent & Password;Executed by:
| 4373 | ||||||||||||||||||||||||
| 552 | inline bool hasHost() const { return sectionIsPresent & Host; } never executed: return sectionIsPresent & Host; | 0 | ||||||||||||||||||||||||
| 553 | inline bool hasPort() const { return port != -1; } never executed: return port != -1; | 0 | ||||||||||||||||||||||||
| 554 | inline bool hasPath() const { return !path.isEmpty(); } never executed: return !path.isEmpty(); | 0 | ||||||||||||||||||||||||
| 555 | inline bool hasQuery() const { return sectionIsPresent & Query; } executed 10998 times by 35 tests: return sectionIsPresent & Query;Executed by:
| 10998 | ||||||||||||||||||||||||
| 556 | inline bool hasFragment() const { return sectionIsPresent & Fragment; } executed 11000 times by 31 tests: return sectionIsPresent & Fragment;Executed by:
| 11000 | ||||||||||||||||||||||||
| 557 | - | |||||||||||||||||||||||||
| 558 | inline bool isLocalFile() const { return flags & IsLocalFile; } executed 21087 times by 35 tests: return flags & IsLocalFile;Executed by:
| 21087 | ||||||||||||||||||||||||
| 559 | QString toLocalFile(QUrl::FormattingOptions options) const; | - | ||||||||||||||||||||||||
| 560 | - | |||||||||||||||||||||||||
| 561 | QString mergePaths(const QString &relativePath) const; | - | ||||||||||||||||||||||||
| 562 | - | |||||||||||||||||||||||||
| 563 | QAtomicInt ref; | - | ||||||||||||||||||||||||
| 564 | int port; | - | ||||||||||||||||||||||||
| 565 | - | |||||||||||||||||||||||||
| 566 | QString scheme; | - | ||||||||||||||||||||||||
| 567 | QString userName; | - | ||||||||||||||||||||||||
| 568 | QString password; | - | ||||||||||||||||||||||||
| 569 | QString host; | - | ||||||||||||||||||||||||
| 570 | QString path; | - | ||||||||||||||||||||||||
| 571 | QString query; | - | ||||||||||||||||||||||||
| 572 | QString fragment; | - | ||||||||||||||||||||||||
| 573 | - | |||||||||||||||||||||||||
| 574 | Error *error; | - | ||||||||||||||||||||||||
| 575 | - | |||||||||||||||||||||||||
| 576 | // not used for: | - | ||||||||||||||||||||||||
| 577 | // - Port (port == -1 means absence) | - | ||||||||||||||||||||||||
| 578 | // - Path (there's no path delimiter, so we optimize its use out of existence) | - | ||||||||||||||||||||||||
| 579 | // Schemes are never supposed to be empty, but we keep the flag anyway | - | ||||||||||||||||||||||||
| 580 | uchar sectionIsPresent; | - | ||||||||||||||||||||||||
| 581 | uchar flags; | - | ||||||||||||||||||||||||
| 582 | - | |||||||||||||||||||||||||
| 583 | // 32-bit: 2 bytes tail padding available | - | ||||||||||||||||||||||||
| 584 | // 64-bit: 6 bytes tail padding available | - | ||||||||||||||||||||||||
| 585 | }; | - | ||||||||||||||||||||||||
| 586 | #undef colon_uchar | - | ||||||||||||||||||||||||
| 587 | - | |||||||||||||||||||||||||
| 588 | inline QUrlPrivate::QUrlPrivate() | - | ||||||||||||||||||||||||
| 589 | : ref(1), port(-1), | - | ||||||||||||||||||||||||
| 590 | error(0), | - | ||||||||||||||||||||||||
| 591 | sectionIsPresent(0), | - | ||||||||||||||||||||||||
| 592 | flags(0) | - | ||||||||||||||||||||||||
| 593 | { | - | ||||||||||||||||||||||||
| 594 | } executed 24121 times by 56 tests: end of blockExecuted by:
| 24121 | ||||||||||||||||||||||||
| 595 | - | |||||||||||||||||||||||||
| 596 | inline QUrlPrivate::QUrlPrivate(const QUrlPrivate ©) | - | ||||||||||||||||||||||||
| 597 | : ref(1), port(copy.port), | - | ||||||||||||||||||||||||
| 598 | scheme(copy.scheme), | - | ||||||||||||||||||||||||
| 599 | userName(copy.userName), | - | ||||||||||||||||||||||||
| 600 | password(copy.password), | - | ||||||||||||||||||||||||
| 601 | host(copy.host), | - | ||||||||||||||||||||||||
| 602 | path(copy.path), | - | ||||||||||||||||||||||||
| 603 | query(copy.query), | - | ||||||||||||||||||||||||
| 604 | fragment(copy.fragment), | - | ||||||||||||||||||||||||
| 605 | error(copy.cloneError()), | - | ||||||||||||||||||||||||
| 606 | sectionIsPresent(copy.sectionIsPresent), | - | ||||||||||||||||||||||||
| 607 | flags(copy.flags) | - | ||||||||||||||||||||||||
| 608 | { | - | ||||||||||||||||||||||||
| 609 | } executed 9134 times by 18 tests: end of blockExecuted by:
| 9134 | ||||||||||||||||||||||||
| 610 | - | |||||||||||||||||||||||||
| 611 | inline QUrlPrivate::~QUrlPrivate() | - | ||||||||||||||||||||||||
| 612 | { | - | ||||||||||||||||||||||||
| 613 | delete error; | - | ||||||||||||||||||||||||
| 614 | } executed 33248 times by 63 tests: end of blockExecuted by:
| 33248 | ||||||||||||||||||||||||
| 615 | - | |||||||||||||||||||||||||
| 616 | inline QUrlPrivate::Error *QUrlPrivate::cloneError() const | - | ||||||||||||||||||||||||
| 617 | { | - | ||||||||||||||||||||||||
| 618 | return error ? new Error(*error) : 0; executed 9134 times by 18 tests: return error ? new Error(*error) : 0;Executed by:
| 0-9134 | ||||||||||||||||||||||||
| 619 | } | - | ||||||||||||||||||||||||
| 620 | - | |||||||||||||||||||||||||
| 621 | inline void QUrlPrivate::clearError() | - | ||||||||||||||||||||||||
| 622 | { | - | ||||||||||||||||||||||||
| 623 | delete error; | - | ||||||||||||||||||||||||
| 624 | error = 0; | - | ||||||||||||||||||||||||
| 625 | } executed 46530 times by 56 tests: end of blockExecuted by:
| 46530 | ||||||||||||||||||||||||
| 626 | - | |||||||||||||||||||||||||
| 627 | inline void QUrlPrivate::setError(ErrorCode errorCode, const QString &source, int supplement) | - | ||||||||||||||||||||||||
| 628 | { | - | ||||||||||||||||||||||||
| 629 | if (error) {
| 41-263 | ||||||||||||||||||||||||
| 630 | // don't overwrite an error set in a previous section during parsing | - | ||||||||||||||||||||||||
| 631 | return; executed 41 times by 5 tests: return;Executed by:
| 41 | ||||||||||||||||||||||||
| 632 | } | - | ||||||||||||||||||||||||
| 633 | error = new Error; | - | ||||||||||||||||||||||||
| 634 | error->code = errorCode; | - | ||||||||||||||||||||||||
| 635 | error->source = source; | - | ||||||||||||||||||||||||
| 636 | error->position = supplement; | - | ||||||||||||||||||||||||
| 637 | } executed 263 times by 8 tests: end of blockExecuted by:
| 263 | ||||||||||||||||||||||||
| 638 | - | |||||||||||||||||||||||||
| 639 | // From RFC 3986, Appendix A Collected ABNF for URI | - | ||||||||||||||||||||||||
| 640 | // URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] | - | ||||||||||||||||||||||||
| 641 | //[...] | - | ||||||||||||||||||||||||
| 642 | // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) | - | ||||||||||||||||||||||||
| 643 | // | - | ||||||||||||||||||||||||
| 644 | // authority = [ userinfo "@" ] host [ ":" port ] | - | ||||||||||||||||||||||||
| 645 | // userinfo = *( unreserved / pct-encoded / sub-delims / ":" ) | - | ||||||||||||||||||||||||
| 646 | // host = IP-literal / IPv4address / reg-name | - | ||||||||||||||||||||||||
| 647 | // port = *DIGIT | - | ||||||||||||||||||||||||
| 648 | //[...] | - | ||||||||||||||||||||||||
| 649 | // reg-name = *( unreserved / pct-encoded / sub-delims ) | - | ||||||||||||||||||||||||
| 650 | //[..] | - | ||||||||||||||||||||||||
| 651 | // pchar = unreserved / pct-encoded / sub-delims / ":" / "@" | - | ||||||||||||||||||||||||
| 652 | // | - | ||||||||||||||||||||||||
| 653 | // query = *( pchar / "/" / "?" ) | - | ||||||||||||||||||||||||
| 654 | // | - | ||||||||||||||||||||||||
| 655 | // fragment = *( pchar / "/" / "?" ) | - | ||||||||||||||||||||||||
| 656 | // | - | ||||||||||||||||||||||||
| 657 | // pct-encoded = "%" HEXDIG HEXDIG | - | ||||||||||||||||||||||||
| 658 | // | - | ||||||||||||||||||||||||
| 659 | // unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" | - | ||||||||||||||||||||||||
| 660 | // reserved = gen-delims / sub-delims | - | ||||||||||||||||||||||||
| 661 | // gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@" | - | ||||||||||||||||||||||||
| 662 | // sub-delims = "!" / "$" / "&" / "'" / "(" / ")" | - | ||||||||||||||||||||||||
| 663 | // / "*" / "+" / "," / ";" / "=" | - | ||||||||||||||||||||||||
| 664 | // the path component has a complex ABNF that basically boils down to | - | ||||||||||||||||||||||||
| 665 | // slash-separated segments of "pchar" | - | ||||||||||||||||||||||||
| 666 | - | |||||||||||||||||||||||||
| 667 | // The above is the strict definition of the URL components and we mostly | - | ||||||||||||||||||||||||
| 668 | // adhere to it, with few exceptions. QUrl obeys the following behavior: | - | ||||||||||||||||||||||||
| 669 | // - percent-encoding sequences always use uppercase HEXDIG; | - | ||||||||||||||||||||||||
| 670 | // - unreserved characters are *always* decoded, no exceptions; | - | ||||||||||||||||||||||||
| 671 | // - the space character and bytes with the high bit set are controlled by | - | ||||||||||||||||||||||||
| 672 | // the EncodeSpaces and EncodeUnicode bits; | - | ||||||||||||||||||||||||
| 673 | // - control characters, the percent sign itself, and bytes with the high | - | ||||||||||||||||||||||||
| 674 | // bit set that don't form valid UTF-8 sequences are always encoded, | - | ||||||||||||||||||||||||
| 675 | // except in FullyDecoded mode; | - | ||||||||||||||||||||||||
| 676 | // - sub-delims are always left alone, except in FullyDecoded mode; | - | ||||||||||||||||||||||||
| 677 | // - gen-delim change behavior depending on which section of the URL (or | - | ||||||||||||||||||||||||
| 678 | // the entire URL) we're looking at; see below; | - | ||||||||||||||||||||||||
| 679 | // - characters not mentioned above, like "<", and ">", are usually | - | ||||||||||||||||||||||||
| 680 | // decoded in individual sections of the URL, but encoded when the full | - | ||||||||||||||||||||||||
| 681 | // URL is put together (we can change on subjective definition of | - | ||||||||||||||||||||||||
| 682 | // "pretty"). | - | ||||||||||||||||||||||||
| 683 | // | - | ||||||||||||||||||||||||
| 684 | // The behavior for the delimiters bears some explanation. The spec says in | - | ||||||||||||||||||||||||
| 685 | // section 2.2: | - | ||||||||||||||||||||||||
| 686 | // URIs that differ in the replacement of a reserved character with its | - | ||||||||||||||||||||||||
| 687 | // corresponding percent-encoded octet are not equivalent. | - | ||||||||||||||||||||||||
| 688 | // (note: QUrl API mistakenly uses the "reserved" term, so we will refer to | - | ||||||||||||||||||||||||
| 689 | // them here as "delimiters"). | - | ||||||||||||||||||||||||
| 690 | // | - | ||||||||||||||||||||||||
| 691 | // For that reason, we cannot encode delimiters found in decoded form and we | - | ||||||||||||||||||||||||
| 692 | // cannot decode the ones found in encoded form if that would change the | - | ||||||||||||||||||||||||
| 693 | // interpretation. Conversely, we *can* perform the transformation if it would | - | ||||||||||||||||||||||||
| 694 | // not change the interpretation. From the last component of a URL to the first, | - | ||||||||||||||||||||||||
| 695 | // here are the gen-delims we can unambiguously transform when the field is | - | ||||||||||||||||||||||||
| 696 | // taken in isolation: | - | ||||||||||||||||||||||||
| 697 | // - fragment: none, since it's the last | - | ||||||||||||||||||||||||
| 698 | // - query: "#" is unambiguous | - | ||||||||||||||||||||||||
| 699 | // - path: "#" and "?" are unambiguous | - | ||||||||||||||||||||||||
| 700 | // - host: completely special but never ambiguous, see setHost() below. | - | ||||||||||||||||||||||||
| 701 | // - password: the "#", "?", "/", "[", "]" and "@" characters are unambiguous | - | ||||||||||||||||||||||||
| 702 | // - username: the "#", "?", "/", "[", "]", "@", and ":" characters are unambiguous | - | ||||||||||||||||||||||||
| 703 | // - scheme: doesn't accept any delimiter, see setScheme() below. | - | ||||||||||||||||||||||||
| 704 | // | - | ||||||||||||||||||||||||
| 705 | // Internally, QUrl stores each component in the format that corresponds to the | - | ||||||||||||||||||||||||
| 706 | // default mode (PrettyDecoded). It deviates from the "strict" FullyEncoded | - | ||||||||||||||||||||||||
| 707 | // mode in the following way: | - | ||||||||||||||||||||||||
| 708 | // - spaces are decoded | - | ||||||||||||||||||||||||
| 709 | // - valid UTF-8 sequences are decoded | - | ||||||||||||||||||||||||
| 710 | // - gen-delims that can be unambiguously transformed are decoded | - | ||||||||||||||||||||||||
| 711 | // - characters controlled by DecodeReserved are often decoded, though this behavior | - | ||||||||||||||||||||||||
| 712 | // can change depending on the subjective definition of "pretty" | - | ||||||||||||||||||||||||
| 713 | // | - | ||||||||||||||||||||||||
| 714 | // Note that the list of gen-delims that we can transform is different for the | - | ||||||||||||||||||||||||
| 715 | // user info (user name + password) and the authority (user info + host + | - | ||||||||||||||||||||||||
| 716 | // port). | - | ||||||||||||||||||||||||
| 717 | - | |||||||||||||||||||||||||
| 718 | - | |||||||||||||||||||||||||
| 719 | // list the recoding table modifications to be used with the recodeFromUser and | - | ||||||||||||||||||||||||
| 720 | // appendToUser functions, according to the rules above. Spaces and UTF-8 | - | ||||||||||||||||||||||||
| 721 | // sequences are handled outside the tables. | - | ||||||||||||||||||||||||
| 722 | - | |||||||||||||||||||||||||
| 723 | // the encodedXXX tables are run with the delimiters set to "leave" by default; | - | ||||||||||||||||||||||||
| 724 | // the decodedXXX tables are run with the delimiters set to "decode" by default | - | ||||||||||||||||||||||||
| 725 | // (except for the query, which doesn't use these functions) | - | ||||||||||||||||||||||||
| 726 | - | |||||||||||||||||||||||||
| 727 | #define decode(x) ushort(x) | - | ||||||||||||||||||||||||
| 728 | #define leave(x) ushort(0x100 | (x)) | - | ||||||||||||||||||||||||
| 729 | #define encode(x) ushort(0x200 | (x)) | - | ||||||||||||||||||||||||
| 730 | - | |||||||||||||||||||||||||
| 731 | static const ushort userNameInIsolation[] = { | - | ||||||||||||||||||||||||
| 732 | decode(':'), // 0 | - | ||||||||||||||||||||||||
| 733 | decode('@'), // 1 | - | ||||||||||||||||||||||||
| 734 | decode(']'), // 2 | - | ||||||||||||||||||||||||
| 735 | decode('['), // 3 | - | ||||||||||||||||||||||||
| 736 | decode('/'), // 4 | - | ||||||||||||||||||||||||
| 737 | decode('?'), // 5 | - | ||||||||||||||||||||||||
| 738 | decode('#'), // 6 | - | ||||||||||||||||||||||||
| 739 | - | |||||||||||||||||||||||||
| 740 | decode('"'), // 7 | - | ||||||||||||||||||||||||
| 741 | decode('<'), | - | ||||||||||||||||||||||||
| 742 | decode('>'), | - | ||||||||||||||||||||||||
| 743 | decode('^'), | - | ||||||||||||||||||||||||
| 744 | decode('\\'), | - | ||||||||||||||||||||||||
| 745 | decode('|'), | - | ||||||||||||||||||||||||
| 746 | decode('{'), | - | ||||||||||||||||||||||||
| 747 | decode('}'), | - | ||||||||||||||||||||||||
| 748 | 0 | - | ||||||||||||||||||||||||
| 749 | }; | - | ||||||||||||||||||||||||
| 750 | static const ushort * const passwordInIsolation = userNameInIsolation + 1; | - | ||||||||||||||||||||||||
| 751 | static const ushort * const pathInIsolation = userNameInIsolation + 5; | - | ||||||||||||||||||||||||
| 752 | static const ushort * const queryInIsolation = userNameInIsolation + 6; | - | ||||||||||||||||||||||||
| 753 | static const ushort * const fragmentInIsolation = userNameInIsolation + 7; | - | ||||||||||||||||||||||||
| 754 | - | |||||||||||||||||||||||||
| 755 | static const ushort userNameInUserInfo[] = { | - | ||||||||||||||||||||||||
| 756 | encode(':'), // 0 | - | ||||||||||||||||||||||||
| 757 | decode('@'), // 1 | - | ||||||||||||||||||||||||
| 758 | decode(']'), // 2 | - | ||||||||||||||||||||||||
| 759 | decode('['), // 3 | - | ||||||||||||||||||||||||
| 760 | decode('/'), // 4 | - | ||||||||||||||||||||||||
| 761 | decode('?'), // 5 | - | ||||||||||||||||||||||||
| 762 | decode('#'), // 6 | - | ||||||||||||||||||||||||
| 763 | - | |||||||||||||||||||||||||
| 764 | decode('"'), // 7 | - | ||||||||||||||||||||||||
| 765 | decode('<'), | - | ||||||||||||||||||||||||
| 766 | decode('>'), | - | ||||||||||||||||||||||||
| 767 | decode('^'), | - | ||||||||||||||||||||||||
| 768 | decode('\\'), | - | ||||||||||||||||||||||||
| 769 | decode('|'), | - | ||||||||||||||||||||||||
| 770 | decode('{'), | - | ||||||||||||||||||||||||
| 771 | decode('}'), | - | ||||||||||||||||||||||||
| 772 | 0 | - | ||||||||||||||||||||||||
| 773 | }; | - | ||||||||||||||||||||||||
| 774 | static const ushort * const passwordInUserInfo = userNameInUserInfo + 1; | - | ||||||||||||||||||||||||
| 775 | - | |||||||||||||||||||||||||
| 776 | static const ushort userNameInAuthority[] = { | - | ||||||||||||||||||||||||
| 777 | encode(':'), // 0 | - | ||||||||||||||||||||||||
| 778 | encode('@'), // 1 | - | ||||||||||||||||||||||||
| 779 | encode(']'), // 2 | - | ||||||||||||||||||||||||
| 780 | encode('['), // 3 | - | ||||||||||||||||||||||||
| 781 | decode('/'), // 4 | - | ||||||||||||||||||||||||
| 782 | decode('?'), // 5 | - | ||||||||||||||||||||||||
| 783 | decode('#'), // 6 | - | ||||||||||||||||||||||||
| 784 | - | |||||||||||||||||||||||||
| 785 | decode('"'), // 7 | - | ||||||||||||||||||||||||
| 786 | decode('<'), | - | ||||||||||||||||||||||||
| 787 | decode('>'), | - | ||||||||||||||||||||||||
| 788 | decode('^'), | - | ||||||||||||||||||||||||
| 789 | decode('\\'), | - | ||||||||||||||||||||||||
| 790 | decode('|'), | - | ||||||||||||||||||||||||
| 791 | decode('{'), | - | ||||||||||||||||||||||||
| 792 | decode('}'), | - | ||||||||||||||||||||||||
| 793 | 0 | - | ||||||||||||||||||||||||
| 794 | }; | - | ||||||||||||||||||||||||
| 795 | static const ushort * const passwordInAuthority = userNameInAuthority + 1; | - | ||||||||||||||||||||||||
| 796 | - | |||||||||||||||||||||||||
| 797 | static const ushort userNameInUrl[] = { | - | ||||||||||||||||||||||||
| 798 | encode(':'), // 0 | - | ||||||||||||||||||||||||
| 799 | encode('@'), // 1 | - | ||||||||||||||||||||||||
| 800 | encode(']'), // 2 | - | ||||||||||||||||||||||||
| 801 | encode('['), // 3 | - | ||||||||||||||||||||||||
| 802 | encode('/'), // 4 | - | ||||||||||||||||||||||||
| 803 | encode('?'), // 5 | - | ||||||||||||||||||||||||
| 804 | encode('#'), // 6 | - | ||||||||||||||||||||||||
| 805 | - | |||||||||||||||||||||||||
| 806 | // no need to list encode(x) for the other characters | - | ||||||||||||||||||||||||
| 807 | 0 | - | ||||||||||||||||||||||||
| 808 | }; | - | ||||||||||||||||||||||||
| 809 | static const ushort * const passwordInUrl = userNameInUrl + 1; | - | ||||||||||||||||||||||||
| 810 | static const ushort * const pathInUrl = userNameInUrl + 5; | - | ||||||||||||||||||||||||
| 811 | static const ushort * const queryInUrl = userNameInUrl + 6; | - | ||||||||||||||||||||||||
| 812 | static const ushort * const fragmentInUrl = userNameInUrl + 6; | - | ||||||||||||||||||||||||
| 813 | - | |||||||||||||||||||||||||
| 814 | static inline void parseDecodedComponent(QString &data) | - | ||||||||||||||||||||||||
| 815 | { | - | ||||||||||||||||||||||||
| 816 | data.replace(QLatin1Char('%'), QStringLiteral("%25")); executed 14769 times by 41 tests: return qstring_literal_temp;Executed by:
| 14769 | ||||||||||||||||||||||||
| 817 | } executed 14769 times by 41 tests: end of blockExecuted by:
| 14769 | ||||||||||||||||||||||||
| 818 | - | |||||||||||||||||||||||||
| 819 | static inline QString | - | ||||||||||||||||||||||||
| 820 | recodeFromUser(const QString &input, const ushort *actions, int from, int to) | - | ||||||||||||||||||||||||
| 821 | { | - | ||||||||||||||||||||||||
| 822 | QString output; | - | ||||||||||||||||||||||||
| 823 | const QChar *begin = input.constData() + from; | - | ||||||||||||||||||||||||
| 824 | const QChar *end = input.constData() + to; | - | ||||||||||||||||||||||||
| 825 | if (qt_urlRecode(output, begin, end, 0, actions))
| 197-19684 | ||||||||||||||||||||||||
| 826 | return output; executed 197 times by 6 tests: return output;Executed by:
| 197 | ||||||||||||||||||||||||
| 827 | - | |||||||||||||||||||||||||
| 828 | return input.mid(from, to - from); executed 19684 times by 36 tests: return input.mid(from, to - from);Executed by:
| 19684 | ||||||||||||||||||||||||
| 829 | } | - | ||||||||||||||||||||||||
| 830 | - | |||||||||||||||||||||||||
| 831 | // appendXXXX functions: copy from the internal form to the external, user form. | - | ||||||||||||||||||||||||
| 832 | // the internal value is stored in its PrettyDecoded form, so that case is easy. | - | ||||||||||||||||||||||||
| 833 | static inline void appendToUser(QString &appendTo, const QString &value, QUrl::FormattingOptions options, | - | ||||||||||||||||||||||||
| 834 | const ushort *actions) | - | ||||||||||||||||||||||||
| 835 | { | - | ||||||||||||||||||||||||
| 836 | if (options == QUrl::PrettyDecoded) {
| 291-25181 | ||||||||||||||||||||||||
| 837 | appendTo += value; | - | ||||||||||||||||||||||||
| 838 | return; executed 291 times by 4 tests: return;Executed by:
| 291 | ||||||||||||||||||||||||
| 839 | } | - | ||||||||||||||||||||||||
| 840 | - | |||||||||||||||||||||||||
| 841 | if (!qt_urlRecode(appendTo, value.constData(), value.constEnd(), options, actions))
| 939-24242 | ||||||||||||||||||||||||
| 842 | appendTo += value; executed 24242 times by 35 tests: appendTo += value;Executed by:
| 24242 | ||||||||||||||||||||||||
| 843 | } executed 25181 times by 35 tests: end of blockExecuted by:
| 25181 | ||||||||||||||||||||||||
| 844 | - | |||||||||||||||||||||||||
| 845 | inline void QUrlPrivate::appendAuthority(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const | - | ||||||||||||||||||||||||
| 846 | { | - | ||||||||||||||||||||||||
| 847 | if ((options & QUrl::RemoveUserInfo) != QUrl::RemoveUserInfo) {
| 1081-4584 | ||||||||||||||||||||||||
| 848 | appendUserInfo(appendTo, options, appendingTo); | - | ||||||||||||||||||||||||
| 849 | - | |||||||||||||||||||||||||
| 850 | // add '@' only if we added anything | - | ||||||||||||||||||||||||
| 851 | if (hasUserName() || (hasPassword() && (options & QUrl::RemovePassword) == 0))
| 7-3957 | ||||||||||||||||||||||||
| 852 | appendTo += QLatin1Char('@'); executed 634 times by 5 tests: appendTo += QLatin1Char('@');Executed by:
| 634 | ||||||||||||||||||||||||
| 853 | } executed 4584 times by 18 tests: end of blockExecuted by:
| 4584 | ||||||||||||||||||||||||
| 854 | appendHost(appendTo, options); | - | ||||||||||||||||||||||||
| 855 | if (!(options & QUrl::RemovePort) && port != -1)
| 4-5661 | ||||||||||||||||||||||||
| 856 | appendTo += QLatin1Char(':') + QString::number(port); executed 1784 times by 9 tests: appendTo += QLatin1Char(':') + QString::number(port);Executed by:
| 1784 | ||||||||||||||||||||||||
| 857 | } executed 5665 times by 21 tests: end of blockExecuted by:
| 5665 | ||||||||||||||||||||||||
| 858 | - | |||||||||||||||||||||||||
| 859 | inline void QUrlPrivate::appendUserInfo(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const | - | ||||||||||||||||||||||||
| 860 | { | - | ||||||||||||||||||||||||
| 861 | if (Q_LIKELY(!hasUserInfo()))
| 790-6308 | ||||||||||||||||||||||||
| 862 | return; executed 6308 times by 21 tests: return;Executed by:
| 6308 | ||||||||||||||||||||||||
| 863 | - | |||||||||||||||||||||||||
| 864 | const ushort *userNameActions; | - | ||||||||||||||||||||||||
| 865 | const ushort *passwordActions; | - | ||||||||||||||||||||||||
| 866 | if (options & QUrl::EncodeDelimiters) {
| 185-605 | ||||||||||||||||||||||||
| 867 | userNameActions = userNameInUrl; | - | ||||||||||||||||||||||||
| 868 | passwordActions = passwordInUrl; | - | ||||||||||||||||||||||||
| 869 | } else { executed 605 times by 5 tests: end of blockExecuted by:
| 605 | ||||||||||||||||||||||||
| 870 | switch (appendingTo) { | - | ||||||||||||||||||||||||
| 871 | case UserInfo: executed 57 times by 2 tests: case UserInfo:Executed by:
| 57 | ||||||||||||||||||||||||
| 872 | userNameActions = userNameInUserInfo; | - | ||||||||||||||||||||||||
| 873 | passwordActions = passwordInUserInfo; | - | ||||||||||||||||||||||||
| 874 | break; executed 57 times by 2 tests: break;Executed by:
| 57 | ||||||||||||||||||||||||
| 875 | - | |||||||||||||||||||||||||
| 876 | case Authority: executed 25 times by 1 test: case Authority:Executed by:
| 25 | ||||||||||||||||||||||||
| 877 | userNameActions = userNameInAuthority; | - | ||||||||||||||||||||||||
| 878 | passwordActions = passwordInAuthority; | - | ||||||||||||||||||||||||
| 879 | break; executed 25 times by 1 test: break;Executed by:
| 25 | ||||||||||||||||||||||||
| 880 | - | |||||||||||||||||||||||||
| 881 | case FullUrl: executed 103 times by 2 tests: case FullUrl:Executed by:
| 103 | ||||||||||||||||||||||||
| 882 | userNameActions = userNameInUrl; | - | ||||||||||||||||||||||||
| 883 | passwordActions = passwordInUrl; | - | ||||||||||||||||||||||||
| 884 | break; executed 103 times by 2 tests: break;Executed by:
| 103 | ||||||||||||||||||||||||
| 885 | - | |||||||||||||||||||||||||
| 886 | default: never executed: default: | 0 | ||||||||||||||||||||||||
| 887 | // can't happen | - | ||||||||||||||||||||||||
| 888 | Q_UNREACHABLE(); | - | ||||||||||||||||||||||||
| 889 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 890 | } | - | ||||||||||||||||||||||||
| 891 | } | - | ||||||||||||||||||||||||
| 892 | - | |||||||||||||||||||||||||
| 893 | if (!qt_urlRecode(appendTo, userName.constData(), userName.constEnd(), options, userNameActions))
| 67-723 | ||||||||||||||||||||||||
| 894 | appendTo += userName; executed 723 times by 5 tests: appendTo += userName;Executed by:
| 723 | ||||||||||||||||||||||||
| 895 | if (options & QUrl::RemovePassword || !hasPassword()) {
| 191-225 | ||||||||||||||||||||||||
| 896 | return; executed 565 times by 5 tests: return;Executed by:
| 565 | ||||||||||||||||||||||||
| 897 | } else { | - | ||||||||||||||||||||||||
| 898 | appendTo += QLatin1Char(':'); | - | ||||||||||||||||||||||||
| 899 | if (!qt_urlRecode(appendTo, password.constData(), password.constEnd(), options, passwordActions))
| 57-168 | ||||||||||||||||||||||||
| 900 | appendTo += password; executed 168 times by 2 tests: appendTo += password;Executed by:
| 168 | ||||||||||||||||||||||||
| 901 | } executed 225 times by 2 tests: end of blockExecuted by:
| 225 | ||||||||||||||||||||||||
| 902 | } | - | ||||||||||||||||||||||||
| 903 | - | |||||||||||||||||||||||||
| 904 | inline void QUrlPrivate::appendUserName(QString &appendTo, QUrl::FormattingOptions options) const | - | ||||||||||||||||||||||||
| 905 | { | - | ||||||||||||||||||||||||
| 906 | // only called from QUrl::userName() | - | ||||||||||||||||||||||||
| 907 | appendToUser(appendTo, userName, options, | - | ||||||||||||||||||||||||
| 908 | options & QUrl::EncodeDelimiters ? userNameInUrl : userNameInIsolation); | - | ||||||||||||||||||||||||
| 909 | } executed 783 times by 3 tests: end of blockExecuted by:
| 783 | ||||||||||||||||||||||||
| 910 | - | |||||||||||||||||||||||||
| 911 | inline void QUrlPrivate::appendPassword(QString &appendTo, QUrl::FormattingOptions options) const | - | ||||||||||||||||||||||||
| 912 | { | - | ||||||||||||||||||||||||
| 913 | // only called from QUrl::password() | - | ||||||||||||||||||||||||
| 914 | appendToUser(appendTo, password, options, | - | ||||||||||||||||||||||||
| 915 | options & QUrl::EncodeDelimiters ? passwordInUrl : passwordInIsolation); | - | ||||||||||||||||||||||||
| 916 | } executed 577 times by 6 tests: end of blockExecuted by:
| 577 | ||||||||||||||||||||||||
| 917 | - | |||||||||||||||||||||||||
| 918 | inline void QUrlPrivate::appendPath(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const | - | ||||||||||||||||||||||||
| 919 | { | - | ||||||||||||||||||||||||
| 920 | QString thePath = path; | - | ||||||||||||||||||||||||
| 921 | if (options & QUrl::NormalizePathSegments) {
| 19-22456 | ||||||||||||||||||||||||
| 922 | thePath = qt_normalizePathSegments(path, false); | - | ||||||||||||||||||||||||
| 923 | } executed 19 times by 1 test: end of blockExecuted by:
| 19 | ||||||||||||||||||||||||
| 924 | if (options & QUrl::RemoveFilename) {
| 54-22421 | ||||||||||||||||||||||||
| 925 | const int slash = path.lastIndexOf(QLatin1Char('/')); | - | ||||||||||||||||||||||||
| 926 | if (slash == -1)
| 5-49 | ||||||||||||||||||||||||
| 927 | return; executed 5 times by 1 test: return;Executed by:
| 5 | ||||||||||||||||||||||||
| 928 | thePath = path.left(slash+1); | - | ||||||||||||||||||||||||
| 929 | } executed 49 times by 1 test: end of blockExecuted by:
| 49 | ||||||||||||||||||||||||
| 930 | // check if we need to remove trailing slashes | - | ||||||||||||||||||||||||
| 931 | if (options & QUrl::StripTrailingSlash) {
| 44-22426 | ||||||||||||||||||||||||
| 932 | while (thePath.length() > 1 && thePath.endsWith(QLatin1Char('/')))
| 16-58 | ||||||||||||||||||||||||
| 933 | thePath.chop(1); executed 30 times by 1 test: thePath.chop(1);Executed by:
| 30 | ||||||||||||||||||||||||
| 934 | } executed 44 times by 1 test: end of blockExecuted by:
| 44 | ||||||||||||||||||||||||
| 935 | - | |||||||||||||||||||||||||
| 936 | appendToUser(appendTo, thePath, options, | - | ||||||||||||||||||||||||
| 937 | appendingTo == FullUrl || options & QUrl::EncodeDelimiters ? pathInUrl : pathInIsolation); | - | ||||||||||||||||||||||||
| 938 | - | |||||||||||||||||||||||||
| 939 | } executed 22470 times by 35 tests: end of blockExecuted by:
| 22470 | ||||||||||||||||||||||||
| 940 | - | |||||||||||||||||||||||||
| 941 | inline void QUrlPrivate::appendFragment(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const | - | ||||||||||||||||||||||||
| 942 | { | - | ||||||||||||||||||||||||
| 943 | appendToUser(appendTo, fragment, options, | - | ||||||||||||||||||||||||
| 944 | options & QUrl::EncodeDelimiters ? fragmentInUrl : | - | ||||||||||||||||||||||||
| 945 | appendingTo == FullUrl ? 0 : fragmentInIsolation); | - | ||||||||||||||||||||||||
| 946 | } executed 920 times by 4 tests: end of blockExecuted by:
| 920 | ||||||||||||||||||||||||
| 947 | - | |||||||||||||||||||||||||
| 948 | inline void QUrlPrivate::appendQuery(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const | - | ||||||||||||||||||||||||
| 949 | { | - | ||||||||||||||||||||||||
| 950 | appendToUser(appendTo, query, options, | - | ||||||||||||||||||||||||
| 951 | appendingTo == FullUrl || options & QUrl::EncodeDelimiters ? queryInUrl : queryInIsolation); | - | ||||||||||||||||||||||||
| 952 | } executed 722 times by 4 tests: end of blockExecuted by:
| 722 | ||||||||||||||||||||||||
| 953 | - | |||||||||||||||||||||||||
| 954 | // setXXX functions | - | ||||||||||||||||||||||||
| 955 | - | |||||||||||||||||||||||||
| 956 | inline bool QUrlPrivate::setScheme(const QString &value, int len, bool doSetError) | - | ||||||||||||||||||||||||
| 957 | { | - | ||||||||||||||||||||||||
| 958 | // schemes are strictly RFC-compliant: | - | ||||||||||||||||||||||||
| 959 | // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) | - | ||||||||||||||||||||||||
| 960 | // we also lowercase the scheme | - | ||||||||||||||||||||||||
| 961 | - | |||||||||||||||||||||||||
| 962 | // schemes in URLs are not allowed to be empty, but they can be in | - | ||||||||||||||||||||||||
| 963 | // "Relative URIs" which QUrl also supports. QUrl::setScheme does | - | ||||||||||||||||||||||||
| 964 | // not call us with len == 0, so this can only be from parse() | - | ||||||||||||||||||||||||
| 965 | scheme.clear(); | - | ||||||||||||||||||||||||
| 966 | if (len == 0)
| 6-12039 | ||||||||||||||||||||||||
| 967 | return false; executed 6 times by 4 tests: return false;Executed by:
| 6 | ||||||||||||||||||||||||
| 968 | - | |||||||||||||||||||||||||
| 969 | sectionIsPresent |= Scheme; | - | ||||||||||||||||||||||||
| 970 | - | |||||||||||||||||||||||||
| 971 | // validate it: | - | ||||||||||||||||||||||||
| 972 | int needsLowercasing = -1; | - | ||||||||||||||||||||||||
| 973 | const ushort *p = reinterpret_cast<const ushort *>(value.constData()); | - | ||||||||||||||||||||||||
| 974 | for (int i = 0; i < len; ++i) {
| 11910-50535 | ||||||||||||||||||||||||
| 975 | if (p[i] >= 'a' && p[i] <= 'z')
| 18-49628 | ||||||||||||||||||||||||
| 976 | continue; executed 49610 times by 34 tests: continue;Executed by:
| 49610 | ||||||||||||||||||||||||
| 977 | if (p[i] >= 'A' && p[i] <= 'Z') {
| 36-617 | ||||||||||||||||||||||||
| 978 | needsLowercasing = i; | - | ||||||||||||||||||||||||
| 979 | continue; executed 272 times by 1 test: continue;Executed by:
| 272 | ||||||||||||||||||||||||
| 980 | } | - | ||||||||||||||||||||||||
| 981 | if (i) {
| 38-615 | ||||||||||||||||||||||||
| 982 | if (p[i] >= '0' && p[i] <= '9')
| 47-423 | ||||||||||||||||||||||||
| 983 | continue; executed 145 times by 4 tests: continue;Executed by:
| 145 | ||||||||||||||||||||||||
| 984 | if (p[i] == '+' || p[i] == '-' || p[i] == '.')
| 8-462 | ||||||||||||||||||||||||
| 985 | continue; executed 379 times by 3 tests: continue;Executed by:
| 379 | ||||||||||||||||||||||||
| 986 | } executed 91 times by 1 test: end of blockExecuted by:
| 91 | ||||||||||||||||||||||||
| 987 | - | |||||||||||||||||||||||||
| 988 | // found something else | - | ||||||||||||||||||||||||
| 989 | // don't call setError needlessly: | - | ||||||||||||||||||||||||
| 990 | // if we've been called from parse(), it will try to recover | - | ||||||||||||||||||||||||
| 991 | if (doSetError)
| 55-74 | ||||||||||||||||||||||||
| 992 | setError(InvalidSchemeError, value, i); executed 74 times by 1 test: setError(InvalidSchemeError, value, i);Executed by:
| 74 | ||||||||||||||||||||||||
| 993 | return false; executed 129 times by 2 tests: return false;Executed by:
| 129 | ||||||||||||||||||||||||
| 994 | } | - | ||||||||||||||||||||||||
| 995 | - | |||||||||||||||||||||||||
| 996 | scheme = value.left(len); | - | ||||||||||||||||||||||||
| 997 | - | |||||||||||||||||||||||||
| 998 | if (needsLowercasing != -1) {
| 33-11877 | ||||||||||||||||||||||||
| 999 | // schemes are ASCII only, so we don't need the full Unicode toLower | - | ||||||||||||||||||||||||
| 1000 | QChar *schemeData = scheme.data(); // force detaching here | - | ||||||||||||||||||||||||
| 1001 | for (int i = needsLowercasing; i >= 0; --i) {
| 33-192 | ||||||||||||||||||||||||
| 1002 | ushort c = schemeData[i].unicode(); | - | ||||||||||||||||||||||||
| 1003 | if (c >= 'A' && c <= 'Z')
| 2-180 | ||||||||||||||||||||||||
| 1004 | schemeData[i] = c + 0x20; executed 178 times by 1 test: schemeData[i] = c + 0x20;Executed by:
| 178 | ||||||||||||||||||||||||
| 1005 | } executed 192 times by 1 test: end of blockExecuted by:
| 192 | ||||||||||||||||||||||||
| 1006 | } executed 33 times by 1 test: end of blockExecuted by:
| 33 | ||||||||||||||||||||||||
| 1007 | - | |||||||||||||||||||||||||
| 1008 | // did we set to the file protocol? | - | ||||||||||||||||||||||||
| 1009 | if (scheme == fileScheme()
| 5555-6355 | ||||||||||||||||||||||||
| 1010 | #ifdef Q_OS_WIN | - | ||||||||||||||||||||||||
| 1011 | || scheme == webDavScheme() | - | ||||||||||||||||||||||||
| 1012 | #endif | - | ||||||||||||||||||||||||
| 1013 | ) { | - | ||||||||||||||||||||||||
| 1014 | flags |= IsLocalFile; | - | ||||||||||||||||||||||||
| 1015 | } else { executed 6355 times by 15 tests: end of blockExecuted by:
| 6355 | ||||||||||||||||||||||||
| 1016 | flags &= ~IsLocalFile; | - | ||||||||||||||||||||||||
| 1017 | } executed 5555 times by 23 tests: end of blockExecuted by:
| 5555 | ||||||||||||||||||||||||
| 1018 | return true; executed 11910 times by 34 tests: return true;Executed by:
| 11910 | ||||||||||||||||||||||||
| 1019 | } | - | ||||||||||||||||||||||||
| 1020 | - | |||||||||||||||||||||||||
| 1021 | inline void QUrlPrivate::setAuthority(const QString &auth, int from, int end, QUrl::ParsingMode mode) | - | ||||||||||||||||||||||||
| 1022 | { | - | ||||||||||||||||||||||||
| 1023 | sectionIsPresent &= ~Authority; | - | ||||||||||||||||||||||||
| 1024 | sectionIsPresent |= Host; | - | ||||||||||||||||||||||||
| 1025 | - | |||||||||||||||||||||||||
| 1026 | // we never actually _loop_ | - | ||||||||||||||||||||||||
| 1027 | while (from != end) {
| 618-4907 | ||||||||||||||||||||||||
| 1028 | int userInfoIndex = auth.indexOf(QLatin1Char('@'), from); | - | ||||||||||||||||||||||||
| 1029 | if (uint(userInfoIndex) < uint(end)) {
| 166-4741 | ||||||||||||||||||||||||
| 1030 | setUserInfo(auth, from, userInfoIndex); | - | ||||||||||||||||||||||||
| 1031 | if (mode == QUrl::StrictMode && !validateComponent(UserInfo, auth, from, userInfoIndex))
| 1-158 | ||||||||||||||||||||||||
| 1032 | break; executed 7 times by 1 test: break;Executed by:
| 7 | ||||||||||||||||||||||||
| 1033 | from = userInfoIndex + 1; | - | ||||||||||||||||||||||||
| 1034 | } executed 159 times by 4 tests: end of blockExecuted by:
| 159 | ||||||||||||||||||||||||
| 1035 | - | |||||||||||||||||||||||||
| 1036 | int colonIndex = auth.lastIndexOf(QLatin1Char(':'), end - 1); | - | ||||||||||||||||||||||||
| 1037 | if (colonIndex < from)
| 840-4060 | ||||||||||||||||||||||||
| 1038 | colonIndex = -1; executed 4060 times by 20 tests: colonIndex = -1;Executed by:
| 4060 | ||||||||||||||||||||||||
| 1039 | - | |||||||||||||||||||||||||
| 1040 | if (uint(colonIndex) < uint(end)) {
| 840-4060 | ||||||||||||||||||||||||
| 1041 | if (auth.at(from).unicode() == '[') {
| 65-775 | ||||||||||||||||||||||||
| 1042 | // check if colonIndex isn't inside the "[...]" part | - | ||||||||||||||||||||||||
| 1043 | int closingBracket = auth.indexOf(QLatin1Char(']'), from); | - | ||||||||||||||||||||||||
| 1044 | if (uint(closingBracket) > uint(colonIndex))
| 6-59 | ||||||||||||||||||||||||
| 1045 | colonIndex = -1; executed 59 times by 4 tests: colonIndex = -1;Executed by:
| 59 | ||||||||||||||||||||||||
| 1046 | } executed 65 times by 4 tests: end of blockExecuted by:
| 65 | ||||||||||||||||||||||||
| 1047 | } executed 840 times by 7 tests: end of blockExecuted by:
| 840 | ||||||||||||||||||||||||
| 1048 | - | |||||||||||||||||||||||||
| 1049 | if (colonIndex == end - 1) {
| 12-4888 | ||||||||||||||||||||||||
| 1050 | // found a colon but no digits after it | - | ||||||||||||||||||||||||
| 1051 | port = -1; | - | ||||||||||||||||||||||||
| 1052 | } else if (uint(colonIndex) < uint(end)) { executed 12 times by 2 tests: end of blockExecuted by:
| 12-4119 | ||||||||||||||||||||||||
| 1053 | unsigned long x = 0; | - | ||||||||||||||||||||||||
| 1054 | for (int i = colonIndex + 1; i < end; ++i) {
| 762-3045 | ||||||||||||||||||||||||
| 1055 | ushort c = auth.at(i).unicode(); | - | ||||||||||||||||||||||||
| 1056 | if (c >= '0' && c <= '9') {
| 1-3044 | ||||||||||||||||||||||||
| 1057 | x *= 10; | - | ||||||||||||||||||||||||
| 1058 | x += c - '0'; | - | ||||||||||||||||||||||||
| 1059 | } else { executed 3038 times by 7 tests: end of blockExecuted by:
| 3038 | ||||||||||||||||||||||||
| 1060 | x = ulong(-1); // x != ushort(x) | - | ||||||||||||||||||||||||
| 1061 | break; executed 7 times by 1 test: break;Executed by:
| 7 | ||||||||||||||||||||||||
| 1062 | } | - | ||||||||||||||||||||||||
| 1063 | } | - | ||||||||||||||||||||||||
| 1064 | if (x == ushort(x)) {
| 10-759 | ||||||||||||||||||||||||
| 1065 | port = ushort(x); | - | ||||||||||||||||||||||||
| 1066 | } else { executed 759 times by 7 tests: end of blockExecuted by:
| 759 | ||||||||||||||||||||||||
| 1067 | setError(InvalidPortError, auth, colonIndex + 1); | - | ||||||||||||||||||||||||
| 1068 | if (mode == QUrl::StrictMode)
| 4-6 | ||||||||||||||||||||||||
| 1069 | break; executed 4 times by 1 test: break;Executed by:
| 4 | ||||||||||||||||||||||||
| 1070 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||||||||
| 1071 | } else { | - | ||||||||||||||||||||||||
| 1072 | port = -1; | - | ||||||||||||||||||||||||
| 1073 | } executed 4119 times by 20 tests: end of blockExecuted by:
| 4119 | ||||||||||||||||||||||||
| 1074 | - | |||||||||||||||||||||||||
| 1075 | setHost(auth, from, qMin<uint>(end, colonIndex), mode); | - | ||||||||||||||||||||||||
| 1076 | if (mode == QUrl::StrictMode && !validateComponent(Host, auth, from, qMin<uint>(end, colonIndex))) {
| 6-4810 | ||||||||||||||||||||||||
| 1077 | // clear host too | - | ||||||||||||||||||||||||
| 1078 | sectionIsPresent &= ~Authority; | - | ||||||||||||||||||||||||
| 1079 | break; executed 6 times by 1 test: break;Executed by:
| 6 | ||||||||||||||||||||||||
| 1080 | } | - | ||||||||||||||||||||||||
| 1081 | - | |||||||||||||||||||||||||
| 1082 | // success | - | ||||||||||||||||||||||||
| 1083 | return; executed 4890 times by 23 tests: return;Executed by:
| 4890 | ||||||||||||||||||||||||
| 1084 | } | - | ||||||||||||||||||||||||
| 1085 | // clear all sections but host | - | ||||||||||||||||||||||||
| 1086 | sectionIsPresent &= ~Authority | Host; | - | ||||||||||||||||||||||||
| 1087 | userName.clear(); | - | ||||||||||||||||||||||||
| 1088 | password.clear(); | - | ||||||||||||||||||||||||
| 1089 | host.clear(); | - | ||||||||||||||||||||||||
| 1090 | port = -1; | - | ||||||||||||||||||||||||
| 1091 | } executed 635 times by 9 tests: end of blockExecuted by:
| 635 | ||||||||||||||||||||||||
| 1092 | - | |||||||||||||||||||||||||
| 1093 | inline void QUrlPrivate::setUserInfo(const QString &userInfo, int from, int end) | - | ||||||||||||||||||||||||
| 1094 | { | - | ||||||||||||||||||||||||
| 1095 | int delimIndex = userInfo.indexOf(QLatin1Char(':'), from); | - | ||||||||||||||||||||||||
| 1096 | setUserName(userInfo, from, qMin<uint>(delimIndex, end)); | - | ||||||||||||||||||||||||
| 1097 | - | |||||||||||||||||||||||||
| 1098 | if (uint(delimIndex) >= uint(end)) {
| 87-130 | ||||||||||||||||||||||||
| 1099 | password.clear(); | - | ||||||||||||||||||||||||
| 1100 | sectionIsPresent &= ~Password; | - | ||||||||||||||||||||||||
| 1101 | } else { executed 87 times by 4 tests: end of blockExecuted by:
| 87 | ||||||||||||||||||||||||
| 1102 | setPassword(userInfo, delimIndex + 1, end); | - | ||||||||||||||||||||||||
| 1103 | } executed 130 times by 4 tests: end of blockExecuted by:
| 130 | ||||||||||||||||||||||||
| 1104 | } | - | ||||||||||||||||||||||||
| 1105 | - | |||||||||||||||||||||||||
| 1106 | inline void QUrlPrivate::setUserName(const QString &value, int from, int end) | - | ||||||||||||||||||||||||
| 1107 | { | - | ||||||||||||||||||||||||
| 1108 | sectionIsPresent |= UserName; | - | ||||||||||||||||||||||||
| 1109 | userName = recodeFromUser(value, userNameInIsolation, from, end); | - | ||||||||||||||||||||||||
| 1110 | } executed 2114 times by 5 tests: end of blockExecuted by:
| 2114 | ||||||||||||||||||||||||
| 1111 | - | |||||||||||||||||||||||||
| 1112 | inline void QUrlPrivate::setPassword(const QString &value, int from, int end) | - | ||||||||||||||||||||||||
| 1113 | { | - | ||||||||||||||||||||||||
| 1114 | sectionIsPresent |= Password; | - | ||||||||||||||||||||||||
| 1115 | password = recodeFromUser(value, passwordInIsolation, from, end); | - | ||||||||||||||||||||||||
| 1116 | } executed 583 times by 5 tests: end of blockExecuted by:
| 583 | ||||||||||||||||||||||||
| 1117 | - | |||||||||||||||||||||||||
| 1118 | inline void QUrlPrivate::setPath(const QString &value, int from, int end) | - | ||||||||||||||||||||||||
| 1119 | { | - | ||||||||||||||||||||||||
| 1120 | // sectionIsPresent |= Path; // not used, save some cycles | - | ||||||||||||||||||||||||
| 1121 | path = recodeFromUser(value, pathInIsolation, from, end); | - | ||||||||||||||||||||||||
| 1122 | } executed 14848 times by 36 tests: end of blockExecuted by:
| 14848 | ||||||||||||||||||||||||
| 1123 | - | |||||||||||||||||||||||||
| 1124 | inline void QUrlPrivate::setFragment(const QString &value, int from, int end) | - | ||||||||||||||||||||||||
| 1125 | { | - | ||||||||||||||||||||||||
| 1126 | sectionIsPresent |= Fragment; | - | ||||||||||||||||||||||||
| 1127 | fragment = recodeFromUser(value, fragmentInIsolation, from, end); | - | ||||||||||||||||||||||||
| 1128 | } executed 1832 times by 8 tests: end of blockExecuted by:
| 1832 | ||||||||||||||||||||||||
| 1129 | - | |||||||||||||||||||||||||
| 1130 | inline void QUrlPrivate::setQuery(const QString &value, int from, int iend) | - | ||||||||||||||||||||||||
| 1131 | { | - | ||||||||||||||||||||||||
| 1132 | sectionIsPresent |= Query; | - | ||||||||||||||||||||||||
| 1133 | query = recodeFromUser(value, queryInIsolation, from, iend); | - | ||||||||||||||||||||||||
| 1134 | } executed 504 times by 5 tests: end of blockExecuted by:
| 504 | ||||||||||||||||||||||||
| 1135 | - | |||||||||||||||||||||||||
| 1136 | // Host handling | - | ||||||||||||||||||||||||
| 1137 | // The RFC says the host is: | - | ||||||||||||||||||||||||
| 1138 | // host = IP-literal / IPv4address / reg-name | - | ||||||||||||||||||||||||
| 1139 | // IP-literal = "[" ( IPv6address / IPvFuture ) "]" | - | ||||||||||||||||||||||||
| 1140 | // IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" ) | - | ||||||||||||||||||||||||
| 1141 | // [a strict definition of IPv6Address and IPv4Address] | - | ||||||||||||||||||||||||
| 1142 | // reg-name = *( unreserved / pct-encoded / sub-delims ) | - | ||||||||||||||||||||||||
| 1143 | // | - | ||||||||||||||||||||||||
| 1144 | // We deviate from the standard in all but IPvFuture. For IPvFuture we accept | - | ||||||||||||||||||||||||
| 1145 | // and store only exactly what the RFC says we should. No percent-encoding is | - | ||||||||||||||||||||||||
| 1146 | // permitted in this field, so Unicode characters and space aren't either. | - | ||||||||||||||||||||||||
| 1147 | // | - | ||||||||||||||||||||||||
| 1148 | // For IPv4 addresses, we accept broken addresses like inet_aton does (that is, | - | ||||||||||||||||||||||||
| 1149 | // less than three dots). However, we correct the address to the proper form | - | ||||||||||||||||||||||||
| 1150 | // and store the corrected address. After correction, we comply to the RFC and | - | ||||||||||||||||||||||||
| 1151 | // it's exclusively composed of unreserved characters. | - | ||||||||||||||||||||||||
| 1152 | // | - | ||||||||||||||||||||||||
| 1153 | // For IPv6 addresses, we accept addresses including trailing (embedded) IPv4 | - | ||||||||||||||||||||||||
| 1154 | // addresses, the so-called v4-compat and v4-mapped addresses. We also store | - | ||||||||||||||||||||||||
| 1155 | // those addresses like that in the hostname field, which violates the spec. | - | ||||||||||||||||||||||||
| 1156 | // IPv6 hosts are stored with the square brackets in the QString. It also | - | ||||||||||||||||||||||||
| 1157 | // requires no transformation in any way. | - | ||||||||||||||||||||||||
| 1158 | // | - | ||||||||||||||||||||||||
| 1159 | // As for registered names, it's the other way around: we accept only valid | - | ||||||||||||||||||||||||
| 1160 | // hostnames as specified by STD 3 and IDNA. That means everything we accept is | - | ||||||||||||||||||||||||
| 1161 | // valid in the RFC definition above, but there are many valid reg-names | - | ||||||||||||||||||||||||
| 1162 | // according to the RFC that we do not accept in the name of security. Since we | - | ||||||||||||||||||||||||
| 1163 | // do accept IDNA, reg-names are subject to ACE encoding and decoding, which is | - | ||||||||||||||||||||||||
| 1164 | // specified by the DecodeUnicode flag. The hostname is stored in its Unicode form. | - | ||||||||||||||||||||||||
| 1165 | - | |||||||||||||||||||||||||
| 1166 | inline void QUrlPrivate::appendHost(QString &appendTo, QUrl::FormattingOptions options) const | - | ||||||||||||||||||||||||
| 1167 | { | - | ||||||||||||||||||||||||
| 1168 | // EncodeUnicode is the only flag that matters | - | ||||||||||||||||||||||||
| 1169 | if ((options & QUrl::FullyDecoded) == QUrl::FullyDecoded)
| 5748-10043 | ||||||||||||||||||||||||
| 1170 | options = 0; executed 10043 times by 34 tests: options = 0;Executed by:
| 10043 | ||||||||||||||||||||||||
| 1171 | else | - | ||||||||||||||||||||||||
| 1172 | options &= QUrl::EncodeUnicode; executed 5748 times by 21 tests: options &= QUrl::EncodeUnicode;Executed by:
| 5748 | ||||||||||||||||||||||||
| 1173 | if (host.isEmpty())
| 1225-14566 | ||||||||||||||||||||||||
| 1174 | return; executed 1225 times by 21 tests: return;Executed by:
| 1225 | ||||||||||||||||||||||||
| 1175 | if (host.at(0).unicode() == '[') {
| 187-14379 | ||||||||||||||||||||||||
| 1176 | // IPv6Address and IPvFuture address never require any transformation | - | ||||||||||||||||||||||||
| 1177 | appendTo += host; | - | ||||||||||||||||||||||||
| 1178 | } else { executed 187 times by 7 tests: end of blockExecuted by:
| 187 | ||||||||||||||||||||||||
| 1179 | // this is either an IPv4Address or a reg-name | - | ||||||||||||||||||||||||
| 1180 | // if it is a reg-name, it is already stored in Unicode form | - | ||||||||||||||||||||||||
| 1181 | if (options & QUrl::EncodeUnicode && !(options & 0x4000000))
| 0-3865 | ||||||||||||||||||||||||
| 1182 | appendTo += qt_ACE_do(host, ToAceOnly, AllowLeadingDot); executed 3865 times by 18 tests: appendTo += qt_ACE_do(host, ToAceOnly, AllowLeadingDot);Executed by:
| 3865 | ||||||||||||||||||||||||
| 1183 | else | - | ||||||||||||||||||||||||
| 1184 | appendTo += host; executed 10514 times by 37 tests: appendTo += host;Executed by:
| 10514 | ||||||||||||||||||||||||
| 1185 | } | - | ||||||||||||||||||||||||
| 1186 | } | - | ||||||||||||||||||||||||
| 1187 | - | |||||||||||||||||||||||||
| 1188 | // the whole IPvFuture is passed and parsed here, including brackets; | - | ||||||||||||||||||||||||
| 1189 | // returns null if the parsing was successful, or the QChar of the first failure | - | ||||||||||||||||||||||||
| 1190 | static const QChar *parseIpFuture(QString &host, const QChar *begin, const QChar *end, QUrl::ParsingMode mode) | - | ||||||||||||||||||||||||
| 1191 | { | - | ||||||||||||||||||||||||
| 1192 | // IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" ) | - | ||||||||||||||||||||||||
| 1193 | static const char acceptable[] = | - | ||||||||||||||||||||||||
| 1194 | "!$&'()*+,;=" // sub-delims | - | ||||||||||||||||||||||||
| 1195 | ":" // ":" | - | ||||||||||||||||||||||||
| 1196 | "-._~"; // unreserved | - | ||||||||||||||||||||||||
| 1197 | - | |||||||||||||||||||||||||
| 1198 | // the brackets and the "v" have been checked | - | ||||||||||||||||||||||||
| 1199 | const QChar *const origBegin = begin; | - | ||||||||||||||||||||||||
| 1200 | if (begin[3].unicode() != '.')
| 3-28 | ||||||||||||||||||||||||
| 1201 | return &begin[3]; executed 3 times by 1 test: return &begin[3];Executed by:
| 3 | ||||||||||||||||||||||||
| 1202 | if ((begin[2].unicode() >= 'A' && begin[2].unicode() <= 'F') ||
| 2-23 | ||||||||||||||||||||||||
| 1203 | (begin[2].unicode() >= 'a' && begin[2].unicode() <= 'f') ||
| 1-23 | ||||||||||||||||||||||||
| 1204 | (begin[2].unicode() >= '0' && begin[2].unicode() <= '9')) {
| 0-24 | ||||||||||||||||||||||||
| 1205 | // this is so unlikely that we'll just go down the slow path | - | ||||||||||||||||||||||||
| 1206 | // decode the whole string, skipping the "[vH." and "]" which we already know to be there | - | ||||||||||||||||||||||||
| 1207 | host += QString::fromRawData(begin, 4); | - | ||||||||||||||||||||||||
| 1208 | - | |||||||||||||||||||||||||
| 1209 | // uppercase the version, if necessary | - | ||||||||||||||||||||||||
| 1210 | if (begin[2].unicode() >= 'a')
| 1-26 | ||||||||||||||||||||||||
| 1211 | host[host.length() - 2] = begin[2].unicode() - 0x20; executed 1 time by 1 test: host[host.length() - 2] = begin[2].unicode() - 0x20;Executed by:
| 1 | ||||||||||||||||||||||||
| 1212 | - | |||||||||||||||||||||||||
| 1213 | begin += 4; | - | ||||||||||||||||||||||||
| 1214 | --end; | - | ||||||||||||||||||||||||
| 1215 | - | |||||||||||||||||||||||||
| 1216 | QString decoded; | - | ||||||||||||||||||||||||
| 1217 | if (mode == QUrl::TolerantMode && qt_urlRecode(decoded, begin, end, QUrl::FullyDecoded, 0)) {
| 2-25 | ||||||||||||||||||||||||
| 1218 | begin = decoded.constBegin(); | - | ||||||||||||||||||||||||
| 1219 | end = decoded.constEnd(); | - | ||||||||||||||||||||||||
| 1220 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||||||||
| 1221 | - | |||||||||||||||||||||||||
| 1222 | for ( ; begin != end; ++begin) {
| 18-123 | ||||||||||||||||||||||||
| 1223 | if (begin->unicode() >= 'A' && begin->unicode() <= 'Z')
| 12-83 | ||||||||||||||||||||||||
| 1224 | host += *begin; executed 12 times by 1 test: host += *begin;Executed by:
| 12 | ||||||||||||||||||||||||
| 1225 | else if (begin->unicode() >= 'a' && begin->unicode() <= 'z')
| 7-88 | ||||||||||||||||||||||||
| 1226 | host += *begin; executed 16 times by 1 test: host += *begin;Executed by:
| 16 | ||||||||||||||||||||||||
| 1227 | else if (begin->unicode() >= '0' && begin->unicode() <= '9')
| 22-48 | ||||||||||||||||||||||||
| 1228 | host += *begin; executed 22 times by 1 test: host += *begin;Executed by:
| 22 | ||||||||||||||||||||||||
| 1229 | else if (begin->unicode() < 0x80 && strchr(acceptable, begin->unicode()) != 0)
| 1-72 | ||||||||||||||||||||||||
| 1230 | host += *begin; executed 64 times by 1 test: host += *begin;Executed by:
| 64 | ||||||||||||||||||||||||
| 1231 | else | - | ||||||||||||||||||||||||
| 1232 | return decoded.isEmpty() ? begin : &origBegin[2]; executed 9 times by 1 test: return decoded.isEmpty() ? begin : &origBegin[2];Executed by:
| 3-9 | ||||||||||||||||||||||||
| 1233 | } | - | ||||||||||||||||||||||||
| 1234 | host += QLatin1Char(']'); | - | ||||||||||||||||||||||||
| 1235 | return 0; executed 18 times by 1 test: return 0;Executed by:
| 18 | ||||||||||||||||||||||||
| 1236 | } | - | ||||||||||||||||||||||||
| 1237 | return &origBegin[2]; executed 1 time by 1 test: return &origBegin[2];Executed by:
| 1 | ||||||||||||||||||||||||
| 1238 | } | - | ||||||||||||||||||||||||
| 1239 | - | |||||||||||||||||||||||||
| 1240 | // ONLY the IPv6 address is parsed here, WITHOUT the brackets | - | ||||||||||||||||||||||||
| 1241 | static const QChar *parseIp6(QString &host, const QChar *begin, const QChar *end, QUrl::ParsingMode mode) | - | ||||||||||||||||||||||||
| 1242 | { | - | ||||||||||||||||||||||||
| 1243 | QIPAddressUtils::IPv6Address address; | - | ||||||||||||||||||||||||
| 1244 | const QChar *ret = QIPAddressUtils::parseIp6(address, begin, end); | - | ||||||||||||||||||||||||
| 1245 | if (ret) {
| 44-112 | ||||||||||||||||||||||||
| 1246 | // this struct is kept in automatic storage because it's only 4 bytes | - | ||||||||||||||||||||||||
| 1247 | const ushort decodeColon[] = { decode(':'), 0 }; | - | ||||||||||||||||||||||||
| 1248 | - | |||||||||||||||||||||||||
| 1249 | // IPv6 failed parsing, check if it was a percent-encoded character in | - | ||||||||||||||||||||||||
| 1250 | // the middle and try again | - | ||||||||||||||||||||||||
| 1251 | QString decoded; | - | ||||||||||||||||||||||||
| 1252 | if (mode == QUrl::TolerantMode && qt_urlRecode(decoded, begin, end, 0, decodeColon)) {
| 4-36 | ||||||||||||||||||||||||
| 1253 | // recurse | - | ||||||||||||||||||||||||
| 1254 | // if the parsing fails again, the qt_urlRecode above will return 0 | - | ||||||||||||||||||||||||
| 1255 | ret = parseIp6(host, decoded.constBegin(), decoded.constEnd(), mode); | - | ||||||||||||||||||||||||
| 1256 | - | |||||||||||||||||||||||||
| 1257 | // we can't return ret, otherwise it would be dangling | - | ||||||||||||||||||||||||
| 1258 | return ret ? end : 0; executed 4 times by 2 tests: return ret ? end : 0;Executed by:
| 2-4 | ||||||||||||||||||||||||
| 1259 | } | - | ||||||||||||||||||||||||
| 1260 | - | |||||||||||||||||||||||||
| 1261 | // no transformation, nothing to re-parse | - | ||||||||||||||||||||||||
| 1262 | return ret; executed 40 times by 5 tests: return ret;Executed by:
| 40 | ||||||||||||||||||||||||
| 1263 | } | - | ||||||||||||||||||||||||
| 1264 | - | |||||||||||||||||||||||||
| 1265 | host.reserve(host.size() + (end - begin)); | - | ||||||||||||||||||||||||
| 1266 | host += QLatin1Char('['); | - | ||||||||||||||||||||||||
| 1267 | QIPAddressUtils::toString(host, address); | - | ||||||||||||||||||||||||
| 1268 | host += QLatin1Char(']'); | - | ||||||||||||||||||||||||
| 1269 | return 0; executed 112 times by 7 tests: return 0;Executed by:
| 112 | ||||||||||||||||||||||||
| 1270 | } | - | ||||||||||||||||||||||||
| 1271 | - | |||||||||||||||||||||||||
| 1272 | inline bool QUrlPrivate::setHost(const QString &value, int from, int iend, QUrl::ParsingMode mode) | - | ||||||||||||||||||||||||
| 1273 | { | - | ||||||||||||||||||||||||
| 1274 | const QChar *begin = value.constData() + from; | - | ||||||||||||||||||||||||
| 1275 | const QChar *end = value.constData() + iend; | - | ||||||||||||||||||||||||
| 1276 | - | |||||||||||||||||||||||||
| 1277 | const int len = end - begin; | - | ||||||||||||||||||||||||
| 1278 | host.clear(); | - | ||||||||||||||||||||||||
| 1279 | sectionIsPresent |= Host; | - | ||||||||||||||||||||||||
| 1280 | if (len == 0)
| 184-11809 | ||||||||||||||||||||||||
| 1281 | return true; executed 184 times by 7 tests: return true;Executed by:
| 184 | ||||||||||||||||||||||||
| 1282 | - | |||||||||||||||||||||||||
| 1283 | if (begin[0].unicode() == '[') {
| 184-11625 | ||||||||||||||||||||||||
| 1284 | // IPv6Address or IPvFuture | - | ||||||||||||||||||||||||
| 1285 | // smallest IPv6 address is "[::]" (len = 4) | - | ||||||||||||||||||||||||
| 1286 | // smallest IPvFuture address is "[v7.X]" (len = 6) | - | ||||||||||||||||||||||||
| 1287 | if (end[-1].unicode() != ']') {
| 1-183 | ||||||||||||||||||||||||
| 1288 | setError(HostMissingEndBracket, value); | - | ||||||||||||||||||||||||
| 1289 | return false; executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||||||||||||||
| 1290 | } | - | ||||||||||||||||||||||||
| 1291 | - | |||||||||||||||||||||||||
| 1292 | if (len > 5 && begin[1].unicode() == 'v') {
| 31-126 | ||||||||||||||||||||||||
| 1293 | const QChar *c = parseIpFuture(host, begin, end, mode); | - | ||||||||||||||||||||||||
| 1294 | if (c)
| 13-18 | ||||||||||||||||||||||||
| 1295 | setError(InvalidIPvFutureError, value, c - value.constData()); executed 13 times by 1 test: setError(InvalidIPvFutureError, value, c - value.constData());Executed by:
| 13 | ||||||||||||||||||||||||
| 1296 | return !c; executed 31 times by 1 test: return !c;Executed by:
| 31 | ||||||||||||||||||||||||
| 1297 | } else if (begin[1].unicode() == 'v') {
| 6-146 | ||||||||||||||||||||||||
| 1298 | setError(InvalidIPvFutureError, value, from); | - | ||||||||||||||||||||||||
| 1299 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||||||||
| 1300 | - | |||||||||||||||||||||||||
| 1301 | const QChar *c = parseIp6(host, begin + 1, end - 1, mode); | - | ||||||||||||||||||||||||
| 1302 | if (!c)
| 40-112 | ||||||||||||||||||||||||
| 1303 | return true; executed 112 times by 7 tests: return true;Executed by:
| 112 | ||||||||||||||||||||||||
| 1304 | - | |||||||||||||||||||||||||
| 1305 | if (c == end - 1)
| 12-28 | ||||||||||||||||||||||||
| 1306 | setError(InvalidIPv6AddressError, value, from); executed 28 times by 3 tests: setError(InvalidIPv6AddressError, value, from);Executed by:
| 28 | ||||||||||||||||||||||||
| 1307 | else | - | ||||||||||||||||||||||||
| 1308 | setError(InvalidCharacterInIPv6Error, value, c - value.constData()); executed 12 times by 4 tests: setError(InvalidCharacterInIPv6Error, value, c - value.constData());Executed by:
| 12 | ||||||||||||||||||||||||
| 1309 | return false; executed 40 times by 5 tests: return false;Executed by:
| 40 | ||||||||||||||||||||||||
| 1310 | } | - | ||||||||||||||||||||||||
| 1311 | - | |||||||||||||||||||||||||
| 1312 | // check if it's an IPv4 address | - | ||||||||||||||||||||||||
| 1313 | QIPAddressUtils::IPv4Address ip4; | - | ||||||||||||||||||||||||
| 1314 | if (QIPAddressUtils::parseIp4(ip4, begin, end)) {
| 1228-10397 | ||||||||||||||||||||||||
| 1315 | // yes, it was | - | ||||||||||||||||||||||||
| 1316 | QIPAddressUtils::toString(host, ip4); | - | ||||||||||||||||||||||||
| 1317 | return true; executed 1228 times by 20 tests: return true;Executed by:
| 1228 | ||||||||||||||||||||||||
| 1318 | } | - | ||||||||||||||||||||||||
| 1319 | - | |||||||||||||||||||||||||
| 1320 | // This is probably a reg-name. | - | ||||||||||||||||||||||||
| 1321 | // But it can also be an encoded string that, when decoded becomes one | - | ||||||||||||||||||||||||
| 1322 | // of the types above. | - | ||||||||||||||||||||||||
| 1323 | // | - | ||||||||||||||||||||||||
| 1324 | // Two types of encoding are possible: | - | ||||||||||||||||||||||||
| 1325 | // percent encoding (e.g., "%31%30%2E%30%2E%30%2E%31" -> "10.0.0.1") | - | ||||||||||||||||||||||||
| 1326 | // Unicode encoding (some non-ASCII characters case-fold to digits | - | ||||||||||||||||||||||||
| 1327 | // when nameprepping is done) | - | ||||||||||||||||||||||||
| 1328 | // | - | ||||||||||||||||||||||||
| 1329 | // The qt_ACE_do function below applies nameprepping and the STD3 check. | - | ||||||||||||||||||||||||
| 1330 | // That means a Unicode string may become an IPv4 address, but it cannot | - | ||||||||||||||||||||||||
| 1331 | // produce a '[' or a '%'. | - | ||||||||||||||||||||||||
| 1332 | - | |||||||||||||||||||||||||
| 1333 | // check for percent-encoding first | - | ||||||||||||||||||||||||
| 1334 | QString s; | - | ||||||||||||||||||||||||
| 1335 | if (mode == QUrl::TolerantMode && qt_urlRecode(s, begin, end, 0, 0)) {
| 54-10269 | ||||||||||||||||||||||||
| 1336 | // something was decoded | - | ||||||||||||||||||||||||
| 1337 | // anything encoded left? | - | ||||||||||||||||||||||||
| 1338 | int pos = s.indexOf(QChar(0x25)); // '%' | - | ||||||||||||||||||||||||
| 1339 | if (pos != -1) {
| 4-50 | ||||||||||||||||||||||||
| 1340 | setError(InvalidRegNameError, s, pos); | - | ||||||||||||||||||||||||
| 1341 | return false; executed 4 times by 1 test: return false;Executed by:
| 4 | ||||||||||||||||||||||||
| 1342 | } | - | ||||||||||||||||||||||||
| 1343 | - | |||||||||||||||||||||||||
| 1344 | // recurse | - | ||||||||||||||||||||||||
| 1345 | return setHost(s, 0, s.length(), QUrl::StrictMode); executed 50 times by 1 test: return setHost(s, 0, s.length(), QUrl::StrictMode);Executed by:
| 50 | ||||||||||||||||||||||||
| 1346 | } | - | ||||||||||||||||||||||||
| 1347 | - | |||||||||||||||||||||||||
| 1348 | s = qt_ACE_do(QString::fromRawData(begin, len), NormalizeAce, ForbidLeadingDot); | - | ||||||||||||||||||||||||
| 1349 | if (s.isEmpty()) {
| 114-10229 | ||||||||||||||||||||||||
| 1350 | setError(InvalidRegNameError, value); | - | ||||||||||||||||||||||||
| 1351 | return false; executed 114 times by 7 tests: return false;Executed by:
| 114 | ||||||||||||||||||||||||
| 1352 | } | - | ||||||||||||||||||||||||
| 1353 | - | |||||||||||||||||||||||||
| 1354 | // check IPv4 again | - | ||||||||||||||||||||||||
| 1355 | if (QIPAddressUtils::parseIp4(ip4, s.constBegin(), s.constEnd())) {
| 0-10229 | ||||||||||||||||||||||||
| 1356 | QIPAddressUtils::toString(host, ip4); | - | ||||||||||||||||||||||||
| 1357 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1358 | host = s; | - | ||||||||||||||||||||||||
| 1359 | } executed 10229 times by 38 tests: end of blockExecuted by:
| 10229 | ||||||||||||||||||||||||
| 1360 | return true; executed 10229 times by 38 tests: return true;Executed by:
| 10229 | ||||||||||||||||||||||||
| 1361 | } | - | ||||||||||||||||||||||||
| 1362 | - | |||||||||||||||||||||||||
| 1363 | inline void QUrlPrivate::parse(const QString &url, QUrl::ParsingMode parsingMode) | - | ||||||||||||||||||||||||
| 1364 | { | - | ||||||||||||||||||||||||
| 1365 | // URI-reference = URI / relative-ref | - | ||||||||||||||||||||||||
| 1366 | // URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] | - | ||||||||||||||||||||||||
| 1367 | // relative-ref = relative-part [ "?" query ] [ "#" fragment ] | - | ||||||||||||||||||||||||
| 1368 | // hier-part = "//" authority path-abempty | - | ||||||||||||||||||||||||
| 1369 | // / other path types | - | ||||||||||||||||||||||||
| 1370 | // relative-part = "//" authority path-abempty | - | ||||||||||||||||||||||||
| 1371 | // / other path types here | - | ||||||||||||||||||||||||
| 1372 | - | |||||||||||||||||||||||||
| 1373 | sectionIsPresent = 0; | - | ||||||||||||||||||||||||
| 1374 | flags = 0; | - | ||||||||||||||||||||||||
| 1375 | clearError(); | - | ||||||||||||||||||||||||
| 1376 | - | |||||||||||||||||||||||||
| 1377 | // find the important delimiters | - | ||||||||||||||||||||||||
| 1378 | int colon = -1; | - | ||||||||||||||||||||||||
| 1379 | int question = -1; | - | ||||||||||||||||||||||||
| 1380 | int hash = -1; | - | ||||||||||||||||||||||||
| 1381 | const int len = url.length(); | - | ||||||||||||||||||||||||
| 1382 | const QChar *const begin = url.constData(); | - | ||||||||||||||||||||||||
| 1383 | const ushort *const data = reinterpret_cast<const ushort *>(begin); | - | ||||||||||||||||||||||||
| 1384 | - | |||||||||||||||||||||||||
| 1385 | for (int i = 0; i < len; ++i) {
| 9829-249781 | ||||||||||||||||||||||||
| 1386 | uint uc = data[i]; | - | ||||||||||||||||||||||||
| 1387 | if (uc == '#' && hash == -1) {
| 0-249645 | ||||||||||||||||||||||||
| 1388 | hash = i; | - | ||||||||||||||||||||||||
| 1389 | - | |||||||||||||||||||||||||
| 1390 | // nothing more to be found | - | ||||||||||||||||||||||||
| 1391 | break; executed 136 times by 4 tests: break;Executed by:
| 136 | ||||||||||||||||||||||||
| 1392 | } | - | ||||||||||||||||||||||||
| 1393 | - | |||||||||||||||||||||||||
| 1394 | if (question == -1) {
| 3328-246317 | ||||||||||||||||||||||||
| 1395 | if (uc == ':' && colon == -1)
| 1147-238989 | ||||||||||||||||||||||||
| 1396 | colon = i; executed 6181 times by 31 tests: colon = i;Executed by:
| 6181 | ||||||||||||||||||||||||
| 1397 | else if (uc == '?')
| 345-239791 | ||||||||||||||||||||||||
| 1398 | question = i; executed 345 times by 5 tests: question = i;Executed by:
| 345 | ||||||||||||||||||||||||
| 1399 | } executed 246317 times by 35 tests: end of blockExecuted by:
| 246317 | ||||||||||||||||||||||||
| 1400 | } executed 249645 times by 35 tests: end of blockExecuted by:
| 249645 | ||||||||||||||||||||||||
| 1401 | - | |||||||||||||||||||||||||
| 1402 | // check if we have a scheme | - | ||||||||||||||||||||||||
| 1403 | int hierStart; | - | ||||||||||||||||||||||||
| 1404 | if (colon != -1 && setScheme(url, colon, /* don't set error */ false)) {
| 61-6181 | ||||||||||||||||||||||||
| 1405 | hierStart = colon + 1; | - | ||||||||||||||||||||||||
| 1406 | } else { executed 6120 times by 29 tests: end of blockExecuted by:
| 6120 | ||||||||||||||||||||||||
| 1407 | // recover from a failed scheme: it might not have been a scheme at all | - | ||||||||||||||||||||||||
| 1408 | scheme.clear(); | - | ||||||||||||||||||||||||
| 1409 | sectionIsPresent = 0; | - | ||||||||||||||||||||||||
| 1410 | hierStart = 0; | - | ||||||||||||||||||||||||
| 1411 | } executed 3845 times by 16 tests: end of blockExecuted by:
| 3845 | ||||||||||||||||||||||||
| 1412 | - | |||||||||||||||||||||||||
| 1413 | int pathStart; | - | ||||||||||||||||||||||||
| 1414 | int hierEnd = qMin<uint>(qMin<uint>(question, hash), len); | - | ||||||||||||||||||||||||
| 1415 | if (hierEnd - hierStart >= 2 && data[hierStart] == '/' && data[hierStart + 1] == '/') {
| 114-9293 | ||||||||||||||||||||||||
| 1416 | // we have an authority, it ends at the first slash after these | - | ||||||||||||||||||||||||
| 1417 | int authorityEnd = hierEnd; | - | ||||||||||||||||||||||||
| 1418 | for (int i = hierStart + 2; i < authorityEnd ; ++i) {
| 2853-86403 | ||||||||||||||||||||||||
| 1419 | if (data[i] == '/') {
| 2641-83762 | ||||||||||||||||||||||||
| 1420 | authorityEnd = i; | - | ||||||||||||||||||||||||
| 1421 | break; executed 2641 times by 22 tests: break;Executed by:
| 2641 | ||||||||||||||||||||||||
| 1422 | } | - | ||||||||||||||||||||||||
| 1423 | } executed 83762 times by 23 tests: end of blockExecuted by:
| 83762 | ||||||||||||||||||||||||
| 1424 | - | |||||||||||||||||||||||||
| 1425 | setAuthority(url, hierStart + 2, authorityEnd, parsingMode); | - | ||||||||||||||||||||||||
| 1426 | - | |||||||||||||||||||||||||
| 1427 | // even if we failed to set the authority properly, let's try to recover | - | ||||||||||||||||||||||||
| 1428 | pathStart = authorityEnd; | - | ||||||||||||||||||||||||
| 1429 | setPath(url, pathStart, hierEnd); | - | ||||||||||||||||||||||||
| 1430 | } else { executed 5494 times by 29 tests: end of blockExecuted by:
| 5494 | ||||||||||||||||||||||||
| 1431 | userName.clear(); | - | ||||||||||||||||||||||||
| 1432 | password.clear(); | - | ||||||||||||||||||||||||
| 1433 | host.clear(); | - | ||||||||||||||||||||||||
| 1434 | port = -1; | - | ||||||||||||||||||||||||
| 1435 | pathStart = hierStart; | - | ||||||||||||||||||||||||
| 1436 | - | |||||||||||||||||||||||||
| 1437 | if (hierStart < hierEnd)
| 641-3830 | ||||||||||||||||||||||||
| 1438 | setPath(url, hierStart, hierEnd); executed 3830 times by 16 tests: setPath(url, hierStart, hierEnd);Executed by:
| 3830 | ||||||||||||||||||||||||
| 1439 | else | - | ||||||||||||||||||||||||
| 1440 | path.clear(); executed 641 times by 13 tests: path.clear();Executed by:
| 641 | ||||||||||||||||||||||||
| 1441 | } | - | ||||||||||||||||||||||||
| 1442 | - | |||||||||||||||||||||||||
| 1443 | if (uint(question) < uint(hash))
| 345-9620 | ||||||||||||||||||||||||
| 1444 | setQuery(url, question + 1, qMin<uint>(hash, len)); executed 345 times by 5 tests: setQuery(url, question + 1, qMin<uint>(hash, len));Executed by:
| 345 | ||||||||||||||||||||||||
| 1445 | - | |||||||||||||||||||||||||
| 1446 | if (hash != -1)
| 136-9829 | ||||||||||||||||||||||||
| 1447 | setFragment(url, hash + 1, len); executed 136 times by 4 tests: setFragment(url, hash + 1, len);Executed by:
| 136 | ||||||||||||||||||||||||
| 1448 | - | |||||||||||||||||||||||||
| 1449 | if (error || parsingMode == QUrl::TolerantMode)
| 69-9894 | ||||||||||||||||||||||||
| 1450 | return; executed 9896 times by 35 tests: return;Executed by:
| 9896 | ||||||||||||||||||||||||
| 1451 | - | |||||||||||||||||||||||||
| 1452 | // The parsing so far was partially tolerant of errors, except for the | - | ||||||||||||||||||||||||
| 1453 | // scheme parser (which is always strict) and the authority (which was | - | ||||||||||||||||||||||||
| 1454 | // executed in strict mode). | - | ||||||||||||||||||||||||
| 1455 | // If we haven't found any errors so far, continue the strict-mode parsing | - | ||||||||||||||||||||||||
| 1456 | // from the path component onwards. | - | ||||||||||||||||||||||||
| 1457 | - | |||||||||||||||||||||||||
| 1458 | if (!validateComponent(Path, url, pathStart, hierEnd))
| 5-64 | ||||||||||||||||||||||||
| 1459 | return; executed 5 times by 2 tests: return;Executed by:
| 5 | ||||||||||||||||||||||||
| 1460 | if (uint(question) < uint(hash) && !validateComponent(Query, url, question + 1, qMin<uint>(hash, len)))
| 0-63 | ||||||||||||||||||||||||
| 1461 | return; executed 1 time by 1 test: return;Executed by:
| 1 | ||||||||||||||||||||||||
| 1462 | if (hash != -1)
| 1-62 | ||||||||||||||||||||||||
| 1463 | validateComponent(Fragment, url, hash + 1, len); executed 1 time by 1 test: validateComponent(Fragment, url, hash + 1, len);Executed by:
| 1 | ||||||||||||||||||||||||
| 1464 | } executed 63 times by 4 tests: end of blockExecuted by:
| 63 | ||||||||||||||||||||||||
| 1465 | - | |||||||||||||||||||||||||
| 1466 | QString QUrlPrivate::toLocalFile(QUrl::FormattingOptions options) const | - | ||||||||||||||||||||||||
| 1467 | { | - | ||||||||||||||||||||||||
| 1468 | QString tmp; | - | ||||||||||||||||||||||||
| 1469 | QString ourPath; | - | ||||||||||||||||||||||||
| 1470 | appendPath(ourPath, options, QUrlPrivate::Path); | - | ||||||||||||||||||||||||
| 1471 | - | |||||||||||||||||||||||||
| 1472 | // magic for shared drive on windows | - | ||||||||||||||||||||||||
| 1473 | if (!host.isEmpty()) {
| 4-10434 | ||||||||||||||||||||||||
| 1474 | tmp = QStringLiteral("//") + host; executed 4 times by 1 test: return qstring_literal_temp;Executed by:
| 4 | ||||||||||||||||||||||||
| 1475 | #ifdef Q_OS_WIN // QTBUG-42346, WebDAV is visible as local file on Windows only. | - | ||||||||||||||||||||||||
| 1476 | if (scheme == webDavScheme()) | - | ||||||||||||||||||||||||
| 1477 | tmp += webDavSslTag(); | - | ||||||||||||||||||||||||
| 1478 | #endif | - | ||||||||||||||||||||||||
| 1479 | if (!ourPath.isEmpty() && !ourPath.startsWith(QLatin1Char('/')))
| 1-3 | ||||||||||||||||||||||||
| 1480 | tmp += QLatin1Char('/'); executed 1 time by 1 test: tmp += QLatin1Char('/');Executed by:
| 1 | ||||||||||||||||||||||||
| 1481 | tmp += ourPath; | - | ||||||||||||||||||||||||
| 1482 | } else { executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 1483 | tmp = ourPath; | - | ||||||||||||||||||||||||
| 1484 | #ifdef Q_OS_WIN | - | ||||||||||||||||||||||||
| 1485 | // magic for drives on windows | - | ||||||||||||||||||||||||
| 1486 | if (ourPath.length() > 2 && ourPath.at(0) == QLatin1Char('/') && ourPath.at(2) == QLatin1Char(':')) | - | ||||||||||||||||||||||||
| 1487 | tmp.remove(0, 1); | - | ||||||||||||||||||||||||
| 1488 | #endif | - | ||||||||||||||||||||||||
| 1489 | } executed 10434 times by 15 tests: end of blockExecuted by:
| 10434 | ||||||||||||||||||||||||
| 1490 | return tmp; executed 10438 times by 15 tests: return tmp;Executed by:
| 10438 | ||||||||||||||||||||||||
| 1491 | } | - | ||||||||||||||||||||||||
| 1492 | - | |||||||||||||||||||||||||
| 1493 | /* | - | ||||||||||||||||||||||||
| 1494 | From http://www.ietf.org/rfc/rfc3986.txt, 5.2.3: Merge paths | - | ||||||||||||||||||||||||
| 1495 | - | |||||||||||||||||||||||||
| 1496 | Returns a merge of the current path with the relative path passed | - | ||||||||||||||||||||||||
| 1497 | as argument. | - | ||||||||||||||||||||||||
| 1498 | - | |||||||||||||||||||||||||
| 1499 | Note: \a relativePath is relative (does not start with '/'). | - | ||||||||||||||||||||||||
| 1500 | */ | - | ||||||||||||||||||||||||
| 1501 | inline QString QUrlPrivate::mergePaths(const QString &relativePath) const | - | ||||||||||||||||||||||||
| 1502 | { | - | ||||||||||||||||||||||||
| 1503 | // If the base URI has a defined authority component and an empty | - | ||||||||||||||||||||||||
| 1504 | // path, then return a string consisting of "/" concatenated with | - | ||||||||||||||||||||||||
| 1505 | // the reference's path; otherwise, | - | ||||||||||||||||||||||||
| 1506 | if (!host.isEmpty() && path.isEmpty())
| 43-2346 | ||||||||||||||||||||||||
| 1507 | return QLatin1Char('/') + relativePath; executed 1000 times by 1 test: return QLatin1Char('/') + relativePath;Executed by:
| 1000 | ||||||||||||||||||||||||
| 1508 | - | |||||||||||||||||||||||||
| 1509 | // Return a string consisting of the reference's path component | - | ||||||||||||||||||||||||
| 1510 | // appended to all but the last segment of the base URI's path | - | ||||||||||||||||||||||||
| 1511 | // (i.e., excluding any characters after the right-most "/" in the | - | ||||||||||||||||||||||||
| 1512 | // base URI path, or excluding the entire base URI path if it does | - | ||||||||||||||||||||||||
| 1513 | // not contain any "/" characters). | - | ||||||||||||||||||||||||
| 1514 | QString newPath; | - | ||||||||||||||||||||||||
| 1515 | if (!path.contains(QLatin1Char('/')))
| 19-2370 | ||||||||||||||||||||||||
| 1516 | newPath = relativePath; executed 19 times by 2 tests: newPath = relativePath;Executed by:
| 19 | ||||||||||||||||||||||||
| 1517 | else | - | ||||||||||||||||||||||||
| 1518 | newPath = path.leftRef(path.lastIndexOf(QLatin1Char('/')) + 1) + relativePath; executed 2370 times by 4 tests: newPath = path.leftRef(path.lastIndexOf(QLatin1Char('/')) + 1) + relativePath;Executed by:
| 2370 | ||||||||||||||||||||||||
| 1519 | - | |||||||||||||||||||||||||
| 1520 | return newPath; executed 2389 times by 4 tests: return newPath;Executed by:
| 2389 | ||||||||||||||||||||||||
| 1521 | } | - | ||||||||||||||||||||||||
| 1522 | - | |||||||||||||||||||||||||
| 1523 | /* | - | ||||||||||||||||||||||||
| 1524 | From http://www.ietf.org/rfc/rfc3986.txt, 5.2.4: Remove dot segments | - | ||||||||||||||||||||||||
| 1525 | - | |||||||||||||||||||||||||
| 1526 | Removes unnecessary ../ and ./ from the path. Used for normalizing | - | ||||||||||||||||||||||||
| 1527 | the URL. | - | ||||||||||||||||||||||||
| 1528 | */ | - | ||||||||||||||||||||||||
| 1529 | static void removeDotsFromPath(QString *path) | - | ||||||||||||||||||||||||
| 1530 | { | - | ||||||||||||||||||||||||
| 1531 | // The input buffer is initialized with the now-appended path | - | ||||||||||||||||||||||||
| 1532 | // components and the output buffer is initialized to the empty | - | ||||||||||||||||||||||||
| 1533 | // string. | - | ||||||||||||||||||||||||
| 1534 | QChar *out = path->data(); | - | ||||||||||||||||||||||||
| 1535 | const QChar *in = out; | - | ||||||||||||||||||||||||
| 1536 | const QChar *end = out + path->size(); | - | ||||||||||||||||||||||||
| 1537 | - | |||||||||||||||||||||||||
| 1538 | // If the input buffer consists only of | - | ||||||||||||||||||||||||
| 1539 | // "." or "..", then remove that from the input | - | ||||||||||||||||||||||||
| 1540 | // buffer; | - | ||||||||||||||||||||||||
| 1541 | if (path->size() == 1 && in[0].unicode() == '.')
| 0-4482 | ||||||||||||||||||||||||
| 1542 | ++in; never executed: ++in; | 0 | ||||||||||||||||||||||||
| 1543 | else if (path->size() == 2 && in[0].unicode() == '.' && in[1].unicode() == '.')
| 0-4483 | ||||||||||||||||||||||||
| 1544 | in += 2; never executed: in += 2; | 0 | ||||||||||||||||||||||||
| 1545 | // While the input buffer is not empty, loop: | - | ||||||||||||||||||||||||
| 1546 | while (in < end) {
| 4482-37799 | ||||||||||||||||||||||||
| 1547 | - | |||||||||||||||||||||||||
| 1548 | // otherwise, if the input buffer begins with a prefix of "../" or "./", | - | ||||||||||||||||||||||||
| 1549 | // then remove that prefix from the input buffer; | - | ||||||||||||||||||||||||
| 1550 | if (path->size() >= 2 && in[0].unicode() == '.' && in[1].unicode() == '/')
| 0-37795 | ||||||||||||||||||||||||
| 1551 | in += 2; never executed: in += 2; | 0 | ||||||||||||||||||||||||
| 1552 | else if (path->size() >= 3 && in[0].unicode() == '.'
| 1-37792 | ||||||||||||||||||||||||
| 1553 | && in[1].unicode() == '.' && in[2].unicode() == '/')
| 0-1 | ||||||||||||||||||||||||
| 1554 | in += 3; executed 1 time by 1 test: in += 3;Executed by:
| 1 | ||||||||||||||||||||||||
| 1555 | - | |||||||||||||||||||||||||
| 1556 | // otherwise, if the input buffer begins with a prefix of | - | ||||||||||||||||||||||||
| 1557 | // "/./" or "/.", where "." is a complete path segment, | - | ||||||||||||||||||||||||
| 1558 | // then replace that prefix with "/" in the input buffer; | - | ||||||||||||||||||||||||
| 1559 | if (in <= end - 3 && in[0].unicode() == '/' && in[1].unicode() == '.'
| 31-37746 | ||||||||||||||||||||||||
| 1560 | && in[2].unicode() == '/') {
| 7-39 | ||||||||||||||||||||||||
| 1561 | in += 2; | - | ||||||||||||||||||||||||
| 1562 | continue; executed 7 times by 1 test: continue;Executed by:
| 7 | ||||||||||||||||||||||||
| 1563 | } else if (in == end - 2 && in[0].unicode() == '/' && in[1].unicode() == '.') {
| 0-37763 | ||||||||||||||||||||||||
| 1564 | *out++ = QLatin1Char('/'); | - | ||||||||||||||||||||||||
| 1565 | in += 2; | - | ||||||||||||||||||||||||
| 1566 | break; executed 2 times by 1 test: break;Executed by:
| 2 | ||||||||||||||||||||||||
| 1567 | } | - | ||||||||||||||||||||||||
| 1568 | - | |||||||||||||||||||||||||
| 1569 | // otherwise, if the input buffer begins with a prefix | - | ||||||||||||||||||||||||
| 1570 | // of "/../" or "/..", where ".." is a complete path | - | ||||||||||||||||||||||||
| 1571 | // segment, then replace that prefix with "/" in the | - | ||||||||||||||||||||||||
| 1572 | // input buffer and remove the last //segment and its | - | ||||||||||||||||||||||||
| 1573 | // preceding "/" (if any) from the output buffer; | - | ||||||||||||||||||||||||
| 1574 | if (in <= end - 4 && in[0].unicode() == '/' && in[1].unicode() == '.'
| 31-37733 | ||||||||||||||||||||||||
| 1575 | && in[2].unicode() == '.' && in[3].unicode() == '/') {
| 0-36 | ||||||||||||||||||||||||
| 1576 | while (out > path->constData() && (--out)->unicode() != '/')
| 8-111 | ||||||||||||||||||||||||
| 1577 | ; executed 84 times by 3 tests: ;Executed by:
| 84 | ||||||||||||||||||||||||
| 1578 | if (out == path->constData() && out->unicode() != '/')
| 3-21 | ||||||||||||||||||||||||
| 1579 | ++in; executed 3 times by 2 tests: ++in;Executed by:
| 3 | ||||||||||||||||||||||||
| 1580 | in += 3; | - | ||||||||||||||||||||||||
| 1581 | continue; executed 35 times by 3 tests: continue;Executed by:
| 35 | ||||||||||||||||||||||||
| 1582 | } else if (in == end - 3 && in[0].unicode() == '/' && in[1].unicode() == '.'
| 0-37749 | ||||||||||||||||||||||||
| 1583 | && in[2].unicode() == '.') {
| 1-2 | ||||||||||||||||||||||||
| 1584 | while (out > path->constData() && (--out)->unicode() != '/')
| 0-4 | ||||||||||||||||||||||||
| 1585 | ; executed 2 times by 1 test: ;Executed by:
| 2 | ||||||||||||||||||||||||
| 1586 | if (out->unicode() == '/')
| 0-2 | ||||||||||||||||||||||||
| 1587 | ++out; executed 2 times by 1 test: ++out;Executed by:
| 2 | ||||||||||||||||||||||||
| 1588 | in += 3; | - | ||||||||||||||||||||||||
| 1589 | break; executed 2 times by 1 test: break;Executed by:
| 2 | ||||||||||||||||||||||||
| 1590 | } | - | ||||||||||||||||||||||||
| 1591 | - | |||||||||||||||||||||||||
| 1592 | // otherwise move the first path segment in | - | ||||||||||||||||||||||||
| 1593 | // the input buffer to the end of the output | - | ||||||||||||||||||||||||
| 1594 | // buffer, including the initial "/" character | - | ||||||||||||||||||||||||
| 1595 | // (if any) and any subsequent characters up | - | ||||||||||||||||||||||||
| 1596 | // to, but not including, the next "/" | - | ||||||||||||||||||||||||
| 1597 | // character or the end of the input buffer. | - | ||||||||||||||||||||||||
| 1598 | *out++ = *in++; | - | ||||||||||||||||||||||||
| 1599 | while (in < end && in->unicode() != '/')
| 3480-267871 | ||||||||||||||||||||||||
| 1600 | *out++ = *in++; executed 233598 times by 5 tests: *out++ = *in++;Executed by:
| 233598 | ||||||||||||||||||||||||
| 1601 | } executed 37753 times by 5 tests: end of blockExecuted by:
| 37753 | ||||||||||||||||||||||||
| 1602 | path->truncate(out - path->constData()); | - | ||||||||||||||||||||||||
| 1603 | } executed 4486 times by 5 tests: end of blockExecuted by:
| 4486 | ||||||||||||||||||||||||
| 1604 | - | |||||||||||||||||||||||||
| 1605 | inline QUrlPrivate::ErrorCode QUrlPrivate::validityError(QString *source, int *position) const | - | ||||||||||||||||||||||||
| 1606 | { | - | ||||||||||||||||||||||||
| 1607 | Q_ASSERT(!source == !position); | - | ||||||||||||||||||||||||
| 1608 | if (error) {
| 464-15863 | ||||||||||||||||||||||||
| 1609 | if (source) {
| 195-269 | ||||||||||||||||||||||||
| 1610 | *source = error->source; | - | ||||||||||||||||||||||||
| 1611 | *position = error->position; | - | ||||||||||||||||||||||||
| 1612 | } executed 195 times by 1 test: end of blockExecuted by:
| 195 | ||||||||||||||||||||||||
| 1613 | return error->code; executed 464 times by 3 tests: return error->code;Executed by:
| 464 | ||||||||||||||||||||||||
| 1614 | } | - | ||||||||||||||||||||||||
| 1615 | - | |||||||||||||||||||||||||
| 1616 | // There are two more cases of invalid URLs that QUrl recognizes and they | - | ||||||||||||||||||||||||
| 1617 | // are only possible with constructed URLs (setXXX methods), not with | - | ||||||||||||||||||||||||
| 1618 | // parsing. Therefore, they are tested here. | - | ||||||||||||||||||||||||
| 1619 | // | - | ||||||||||||||||||||||||
| 1620 | // The two cases are a non-empty path that doesn't start with a slash and: | - | ||||||||||||||||||||||||
| 1621 | // - with an authority | - | ||||||||||||||||||||||||
| 1622 | // - without an authority, without scheme but the path with a colon before | - | ||||||||||||||||||||||||
| 1623 | // the first slash | - | ||||||||||||||||||||||||
| 1624 | // Those cases are considered invalid because toString() would produce a URL | - | ||||||||||||||||||||||||
| 1625 | // that wouldn't be parsed back to the same QUrl. | - | ||||||||||||||||||||||||
| 1626 | - | |||||||||||||||||||||||||
| 1627 | if (path.isEmpty() || path.at(0) == QLatin1Char('/'))
| 705-11301 | ||||||||||||||||||||||||
| 1628 | return NoError; executed 15158 times by 28 tests: return NoError;Executed by:
| 15158 | ||||||||||||||||||||||||
| 1629 | if (sectionIsPresent & QUrlPrivate::Host) {
| 6-699 | ||||||||||||||||||||||||
| 1630 | if (source) {
| 1-5 | ||||||||||||||||||||||||
| 1631 | *source = path; | - | ||||||||||||||||||||||||
| 1632 | *position = 0; | - | ||||||||||||||||||||||||
| 1633 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||
| 1634 | return AuthorityPresentAndPathIsRelative; executed 6 times by 1 test: return AuthorityPresentAndPathIsRelative;Executed by:
| 6 | ||||||||||||||||||||||||
| 1635 | } | - | ||||||||||||||||||||||||
| 1636 | if (sectionIsPresent & QUrlPrivate::Scheme)
| 339-360 | ||||||||||||||||||||||||
| 1637 | return NoError; executed 360 times by 6 tests: return NoError;Executed by:
| 360 | ||||||||||||||||||||||||
| 1638 | - | |||||||||||||||||||||||||
| 1639 | // check for a path of "text:text/" | - | ||||||||||||||||||||||||
| 1640 | for (int i = 0; i < path.length(); ++i) {
| 194-3961 | ||||||||||||||||||||||||
| 1641 | ushort c = path.at(i).unicode(); | - | ||||||||||||||||||||||||
| 1642 | if (c == '/') {
| 68-3893 | ||||||||||||||||||||||||
| 1643 | // found the slash before the colon | - | ||||||||||||||||||||||||
| 1644 | return NoError; executed 68 times by 4 tests: return NoError;Executed by:
| 68 | ||||||||||||||||||||||||
| 1645 | } | - | ||||||||||||||||||||||||
| 1646 | if (c == ':') {
| 77-3816 | ||||||||||||||||||||||||
| 1647 | // found the colon before the slash, it's invalid | - | ||||||||||||||||||||||||
| 1648 | if (source) {
| 6-71 | ||||||||||||||||||||||||
| 1649 | *source = path; | - | ||||||||||||||||||||||||
| 1650 | *position = i; | - | ||||||||||||||||||||||||
| 1651 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||||||||
| 1652 | return RelativeUrlPathContainsColonBeforeSlash; executed 77 times by 2 tests: return RelativeUrlPathContainsColonBeforeSlash;Executed by:
| 77 | ||||||||||||||||||||||||
| 1653 | } | - | ||||||||||||||||||||||||
| 1654 | } executed 3816 times by 9 tests: end of blockExecuted by:
| 3816 | ||||||||||||||||||||||||
| 1655 | return NoError; executed 194 times by 7 tests: return NoError;Executed by:
| 194 | ||||||||||||||||||||||||
| 1656 | } | - | ||||||||||||||||||||||||
| 1657 | - | |||||||||||||||||||||||||
| 1658 | bool QUrlPrivate::validateComponent(QUrlPrivate::Section section, const QString &input, | - | ||||||||||||||||||||||||
| 1659 | int begin, int end) | - | ||||||||||||||||||||||||
| 1660 | { | - | ||||||||||||||||||||||||
| 1661 | // What we need to look out for, that the regular parser tolerates: | - | ||||||||||||||||||||||||
| 1662 | // - percent signs not followed by two hex digits | - | ||||||||||||||||||||||||
| 1663 | // - forbidden characters, which should always appear encoded | - | ||||||||||||||||||||||||
| 1664 | // '"' / '<' / '>' / '\' / '^' / '`' / '{' / '|' / '}' / BKSP | - | ||||||||||||||||||||||||
| 1665 | // control characters | - | ||||||||||||||||||||||||
| 1666 | // - delimiters not allowed in certain positions | - | ||||||||||||||||||||||||
| 1667 | // . scheme: parser is already strict | - | ||||||||||||||||||||||||
| 1668 | // . user info: gen-delims except ":" disallowed ("/" / "?" / "#" / "[" / "]" / "@") | - | ||||||||||||||||||||||||
| 1669 | // . host: parser is stricter than the standard | - | ||||||||||||||||||||||||
| 1670 | // . port: parser is stricter than the standard | - | ||||||||||||||||||||||||
| 1671 | // . path: all delimiters allowed | - | ||||||||||||||||||||||||
| 1672 | // . fragment: all delimiters allowed | - | ||||||||||||||||||||||||
| 1673 | // . query: all delimiters allowed | - | ||||||||||||||||||||||||
| 1674 | static const char forbidden[] = "\"<>\\^`{|}\x7F"; | - | ||||||||||||||||||||||||
| 1675 | static const char forbiddenUserInfo[] = ":/?#[]@"; | - | ||||||||||||||||||||||||
| 1676 | - | |||||||||||||||||||||||||
| 1677 | Q_ASSERT(section != Authority && section != Hierarchy && section != FullUrl); | - | ||||||||||||||||||||||||
| 1678 | - | |||||||||||||||||||||||||
| 1679 | const ushort *const data = reinterpret_cast<const ushort *>(input.constData()); | - | ||||||||||||||||||||||||
| 1680 | for (uint i = uint(begin); i < uint(end); ++i) {
| 147-3566 | ||||||||||||||||||||||||
| 1681 | uint uc = data[i]; | - | ||||||||||||||||||||||||
| 1682 | if (uc >= 0x80)
| 11-3555 | ||||||||||||||||||||||||
| 1683 | continue; executed 11 times by 1 test: continue;Executed by:
| 11 | ||||||||||||||||||||||||
| 1684 | - | |||||||||||||||||||||||||
| 1685 | bool error = false; | - | ||||||||||||||||||||||||
| 1686 | if ((uc == '%' && (uint(end) < i + 2 || !isHex(data[i + 1]) || !isHex(data[i + 2])))
| 1-3522 | ||||||||||||||||||||||||
| 1687 | || uc <= 0x20 || strchr(forbidden, uc)) {
| 4-3535 | ||||||||||||||||||||||||
| 1688 | // found an error | - | ||||||||||||||||||||||||
| 1689 | error = true; | - | ||||||||||||||||||||||||
| 1690 | } else if (section & UserInfo) { executed 34 times by 2 tests: end of blockExecuted by:
| 34-3446 | ||||||||||||||||||||||||
| 1691 | if (section == UserInfo && strchr(forbiddenUserInfo + 1, uc))
| 1-53 | ||||||||||||||||||||||||
| 1692 | error = true; executed 1 time by 1 test: error = true;Executed by:
| 1 | ||||||||||||||||||||||||
| 1693 | else if (section != UserInfo && strchr(forbiddenUserInfo, uc))
| 4-52 | ||||||||||||||||||||||||
| 1694 | error = true; executed 4 times by 1 test: error = true;Executed by:
| 4 | ||||||||||||||||||||||||
| 1695 | } executed 75 times by 1 test: end of blockExecuted by:
| 75 | ||||||||||||||||||||||||
| 1696 | - | |||||||||||||||||||||||||
| 1697 | if (!error)
| 39-3516 | ||||||||||||||||||||||||
| 1698 | continue; executed 3516 times by 4 tests: continue;Executed by:
| 3516 | ||||||||||||||||||||||||
| 1699 | - | |||||||||||||||||||||||||
| 1700 | ErrorCode errorCode = ErrorCode(int(section) << 8); | - | ||||||||||||||||||||||||
| 1701 | if (section == UserInfo) {
| 12-27 | ||||||||||||||||||||||||
| 1702 | // is it the user name or the password? | - | ||||||||||||||||||||||||
| 1703 | errorCode = InvalidUserNameError; | - | ||||||||||||||||||||||||
| 1704 | for (uint j = uint(begin); j < i; ++j)
| 9-41 | ||||||||||||||||||||||||
| 1705 | if (data[j] == ':') {
| 3-38 | ||||||||||||||||||||||||
| 1706 | errorCode = InvalidPasswordError; | - | ||||||||||||||||||||||||
| 1707 | break; executed 3 times by 1 test: break;Executed by:
| 3 | ||||||||||||||||||||||||
| 1708 | } | - | ||||||||||||||||||||||||
| 1709 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||||||||||||||
| 1710 | - | |||||||||||||||||||||||||
| 1711 | setError(errorCode, input, i); | - | ||||||||||||||||||||||||
| 1712 | return false; executed 39 times by 2 tests: return false;Executed by:
| 39 | ||||||||||||||||||||||||
| 1713 | } | - | ||||||||||||||||||||||||
| 1714 | - | |||||||||||||||||||||||||
| 1715 | // no errors | - | ||||||||||||||||||||||||
| 1716 | return true; executed 147 times by 4 tests: return true;Executed by:
| 147 | ||||||||||||||||||||||||
| 1717 | } | - | ||||||||||||||||||||||||
| 1718 | - | |||||||||||||||||||||||||
| 1719 | #if 0 | - | ||||||||||||||||||||||||
| 1720 | inline void QUrlPrivate::validate() const | - | ||||||||||||||||||||||||
| 1721 | { | - | ||||||||||||||||||||||||
| 1722 | QUrlPrivate *that = (QUrlPrivate *)this; | - | ||||||||||||||||||||||||
| 1723 | that->encodedOriginal = that->toEncoded(); // may detach | - | ||||||||||||||||||||||||
| 1724 | parse(ParseOnly); | - | ||||||||||||||||||||||||
| 1725 | - | |||||||||||||||||||||||||
| 1726 | QURL_SETFLAG(that->stateFlags, Validated); | - | ||||||||||||||||||||||||
| 1727 | - | |||||||||||||||||||||||||
| 1728 | if (!isValid) | - | ||||||||||||||||||||||||
| 1729 | return; | - | ||||||||||||||||||||||||
| 1730 | - | |||||||||||||||||||||||||
| 1731 | QString auth = authority(); // causes the non-encoded forms to be valid | - | ||||||||||||||||||||||||
| 1732 | - | |||||||||||||||||||||||||
| 1733 | // authority() calls canonicalHost() which sets this | - | ||||||||||||||||||||||||
| 1734 | if (!isHostValid) | - | ||||||||||||||||||||||||
| 1735 | return; | - | ||||||||||||||||||||||||
| 1736 | - | |||||||||||||||||||||||||
| 1737 | if (scheme == QLatin1String("mailto")) { | - | ||||||||||||||||||||||||
| 1738 | if (!host.isEmpty() || port != -1 || !userName.isEmpty() || !password.isEmpty()) { | - | ||||||||||||||||||||||||
| 1739 | that->isValid = false; | - | ||||||||||||||||||||||||
| 1740 | that->errorInfo.setParams(0, QT_TRANSLATE_NOOP(QUrl, "expected empty host, username," | - | ||||||||||||||||||||||||
| 1741 | "port and password"), | - | ||||||||||||||||||||||||
| 1742 | 0, 0); | - | ||||||||||||||||||||||||
| 1743 | } | - | ||||||||||||||||||||||||
| 1744 | } else if (scheme == ftpScheme() || scheme == httpScheme()) { | - | ||||||||||||||||||||||||
| 1745 | if (host.isEmpty() && !(path.isEmpty() && encodedPath.isEmpty())) { | - | ||||||||||||||||||||||||
| 1746 | that->isValid = false; | - | ||||||||||||||||||||||||
| 1747 | that->errorInfo.setParams(0, QT_TRANSLATE_NOOP(QUrl, "the host is empty, but not the path"), | - | ||||||||||||||||||||||||
| 1748 | 0, 0); | - | ||||||||||||||||||||||||
| 1749 | } | - | ||||||||||||||||||||||||
| 1750 | } | - | ||||||||||||||||||||||||
| 1751 | } | - | ||||||||||||||||||||||||
| 1752 | #endif | - | ||||||||||||||||||||||||
| 1753 | - | |||||||||||||||||||||||||
| 1754 | /*! | - | ||||||||||||||||||||||||
| 1755 | \macro QT_NO_URL_CAST_FROM_STRING | - | ||||||||||||||||||||||||
| 1756 | \relates QUrl | - | ||||||||||||||||||||||||
| 1757 | - | |||||||||||||||||||||||||
| 1758 | Disables automatic conversions from QString (or char *) to QUrl. | - | ||||||||||||||||||||||||
| 1759 | - | |||||||||||||||||||||||||
| 1760 | Compiling your code with this define is useful when you have a lot of | - | ||||||||||||||||||||||||
| 1761 | code that uses QString for file names and you wish to convert it to | - | ||||||||||||||||||||||||
| 1762 | use QUrl for network transparency. In any code that uses QUrl, it can | - | ||||||||||||||||||||||||
| 1763 | help avoid missing QUrl::resolved() calls, and other misuses of | - | ||||||||||||||||||||||||
| 1764 | QString to QUrl conversions. | - | ||||||||||||||||||||||||
| 1765 | - | |||||||||||||||||||||||||
| 1766 | \oldcode | - | ||||||||||||||||||||||||
| 1767 | url = filename; // probably not what you want | - | ||||||||||||||||||||||||
| 1768 | \newcode | - | ||||||||||||||||||||||||
| 1769 | url = QUrl::fromLocalFile(filename); | - | ||||||||||||||||||||||||
| 1770 | url = baseurl.resolved(QUrl(filename)); | - | ||||||||||||||||||||||||
| 1771 | \endcode | - | ||||||||||||||||||||||||
| 1772 | - | |||||||||||||||||||||||||
| 1773 | \sa QT_NO_CAST_FROM_ASCII | - | ||||||||||||||||||||||||
| 1774 | */ | - | ||||||||||||||||||||||||
| 1775 | - | |||||||||||||||||||||||||
| 1776 | - | |||||||||||||||||||||||||
| 1777 | /*! | - | ||||||||||||||||||||||||
| 1778 | Constructs a URL by parsing \a url. QUrl will automatically percent encode | - | ||||||||||||||||||||||||
| 1779 | all characters that are not allowed in a URL and decode the percent-encoded | - | ||||||||||||||||||||||||
| 1780 | sequences that represent an unreserved character (letters, digits, hyphens, | - | ||||||||||||||||||||||||
| 1781 | undercores, dots and tildes). All other characters are left in their | - | ||||||||||||||||||||||||
| 1782 | original forms. | - | ||||||||||||||||||||||||
| 1783 | - | |||||||||||||||||||||||||
| 1784 | Parses the \a url using the parser mode \a parsingMode. In TolerantMode | - | ||||||||||||||||||||||||
| 1785 | (the default), QUrl will correct certain mistakes, notably the presence of | - | ||||||||||||||||||||||||
| 1786 | a percent character ('%') not followed by two hexadecimal digits, and it | - | ||||||||||||||||||||||||
| 1787 | will accept any character in any position. In StrictMode, encoding mistakes | - | ||||||||||||||||||||||||
| 1788 | will not be tolerated and QUrl will also check that certain forbidden | - | ||||||||||||||||||||||||
| 1789 | characters are not present in unencoded form. If an error is detected in | - | ||||||||||||||||||||||||
| 1790 | StrictMode, isValid() will return false. The parsing mode DecodedMode is not | - | ||||||||||||||||||||||||
| 1791 | permitted in this context. | - | ||||||||||||||||||||||||
| 1792 | - | |||||||||||||||||||||||||
| 1793 | Example: | - | ||||||||||||||||||||||||
| 1794 | - | |||||||||||||||||||||||||
| 1795 | \snippet code/src_corelib_io_qurl.cpp 0 | - | ||||||||||||||||||||||||
| 1796 | - | |||||||||||||||||||||||||
| 1797 | To construct a URL from an encoded string, you can also use fromEncoded(): | - | ||||||||||||||||||||||||
| 1798 | - | |||||||||||||||||||||||||
| 1799 | \snippet code/src_corelib_io_qurl.cpp 1 | - | ||||||||||||||||||||||||
| 1800 | - | |||||||||||||||||||||||||
| 1801 | Both functions are equivalent and, in Qt 5, both functions accept encoded | - | ||||||||||||||||||||||||
| 1802 | data. Usually, the choice of the QUrl constructor or setUrl() versus | - | ||||||||||||||||||||||||
| 1803 | fromEncoded() will depend on the source data: the constructor and setUrl() | - | ||||||||||||||||||||||||
| 1804 | take a QString, whereas fromEncoded takes a QByteArray. | - | ||||||||||||||||||||||||
| 1805 | - | |||||||||||||||||||||||||
| 1806 | \sa setUrl(), fromEncoded(), TolerantMode | - | ||||||||||||||||||||||||
| 1807 | */ | - | ||||||||||||||||||||||||
| 1808 | QUrl::QUrl(const QString &url, ParsingMode parsingMode) : d(0) | - | ||||||||||||||||||||||||
| 1809 | { | - | ||||||||||||||||||||||||
| 1810 | setUrl(url, parsingMode); | - | ||||||||||||||||||||||||
| 1811 | } executed 8701 times by 35 tests: end of blockExecuted by:
| 8701 | ||||||||||||||||||||||||
| 1812 | - | |||||||||||||||||||||||||
| 1813 | /*! | - | ||||||||||||||||||||||||
| 1814 | Constructs an empty QUrl object. | - | ||||||||||||||||||||||||
| 1815 | */ | - | ||||||||||||||||||||||||
| 1816 | QUrl::QUrl() : d(0) | - | ||||||||||||||||||||||||
| 1817 | { | - | ||||||||||||||||||||||||
| 1818 | } executed 45628 times by 87 tests: end of blockExecuted by:
| 45628 | ||||||||||||||||||||||||
| 1819 | - | |||||||||||||||||||||||||
| 1820 | /*! | - | ||||||||||||||||||||||||
| 1821 | Constructs a copy of \a other. | - | ||||||||||||||||||||||||
| 1822 | */ | - | ||||||||||||||||||||||||
| 1823 | QUrl::QUrl(const QUrl &other) : d(other.d) | - | ||||||||||||||||||||||||
| 1824 | { | - | ||||||||||||||||||||||||
| 1825 | if (d)
| 10150-63712 | ||||||||||||||||||||||||
| 1826 | d->ref.ref(); executed 63712 times by 51 tests: d->ref.ref();Executed by:
| 63712 | ||||||||||||||||||||||||
| 1827 | } executed 73862 times by 53 tests: end of blockExecuted by:
| 73862 | ||||||||||||||||||||||||
| 1828 | - | |||||||||||||||||||||||||
| 1829 | /*! | - | ||||||||||||||||||||||||
| 1830 | Destructor; called immediately before the object is deleted. | - | ||||||||||||||||||||||||
| 1831 | */ | - | ||||||||||||||||||||||||
| 1832 | QUrl::~QUrl() | - | ||||||||||||||||||||||||
| 1833 | { | - | ||||||||||||||||||||||||
| 1834 | if (d && !d->ref.deref())
| 32476-94783 | ||||||||||||||||||||||||
| 1835 | delete d; executed 32476 times by 63 tests: delete d;Executed by:
| 32476 | ||||||||||||||||||||||||
| 1836 | } executed 132452 times by 100 tests: end of blockExecuted by:
| 132452 | ||||||||||||||||||||||||
| 1837 | - | |||||||||||||||||||||||||
| 1838 | /*! | - | ||||||||||||||||||||||||
| 1839 | Returns \c true if the URL is non-empty and valid; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 1840 | - | |||||||||||||||||||||||||
| 1841 | The URL is run through a conformance test. Every part of the URL | - | ||||||||||||||||||||||||
| 1842 | must conform to the standard encoding rules of the URI standard | - | ||||||||||||||||||||||||
| 1843 | for the URL to be reported as valid. | - | ||||||||||||||||||||||||
| 1844 | - | |||||||||||||||||||||||||
| 1845 | \snippet code/src_corelib_io_qurl.cpp 2 | - | ||||||||||||||||||||||||
| 1846 | */ | - | ||||||||||||||||||||||||
| 1847 | bool QUrl::isValid() const | - | ||||||||||||||||||||||||
| 1848 | { | - | ||||||||||||||||||||||||
| 1849 | if (isEmpty()) {
| 299-16114 | ||||||||||||||||||||||||
| 1850 | // also catches d == 0 | - | ||||||||||||||||||||||||
| 1851 | return false; executed 299 times by 15 tests: return false;Executed by:
| 299 | ||||||||||||||||||||||||
| 1852 | } | - | ||||||||||||||||||||||||
| 1853 | return d->validityError() == QUrlPrivate::NoError; executed 16114 times by 32 tests: return d->validityError() == QUrlPrivate::NoError;Executed by:
| 16114 | ||||||||||||||||||||||||
| 1854 | } | - | ||||||||||||||||||||||||
| 1855 | - | |||||||||||||||||||||||||
| 1856 | /*! | - | ||||||||||||||||||||||||
| 1857 | Returns \c true if the URL has no data; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 1858 | - | |||||||||||||||||||||||||
| 1859 | \sa clear() | - | ||||||||||||||||||||||||
| 1860 | */ | - | ||||||||||||||||||||||||
| 1861 | bool QUrl::isEmpty() const | - | ||||||||||||||||||||||||
| 1862 | { | - | ||||||||||||||||||||||||
| 1863 | if (!d) return true; executed 893 times by 17 tests: return true;Executed by:
| 893-16759 | ||||||||||||||||||||||||
| 1864 | return d->isEmpty(); executed 16759 times by 33 tests: return d->isEmpty();Executed by:
| 16759 | ||||||||||||||||||||||||
| 1865 | } | - | ||||||||||||||||||||||||
| 1866 | - | |||||||||||||||||||||||||
| 1867 | /*! | - | ||||||||||||||||||||||||
| 1868 | Resets the content of the QUrl. After calling this function, the | - | ||||||||||||||||||||||||
| 1869 | QUrl is equal to one that has been constructed with the default | - | ||||||||||||||||||||||||
| 1870 | empty constructor. | - | ||||||||||||||||||||||||
| 1871 | - | |||||||||||||||||||||||||
| 1872 | \sa isEmpty() | - | ||||||||||||||||||||||||
| 1873 | */ | - | ||||||||||||||||||||||||
| 1874 | void QUrl::clear() | - | ||||||||||||||||||||||||
| 1875 | { | - | ||||||||||||||||||||||||
| 1876 | if (d && !d->ref.deref())
| 0-108 | ||||||||||||||||||||||||
| 1877 | delete d; executed 108 times by 3 tests: delete d;Executed by:
| 108 | ||||||||||||||||||||||||
| 1878 | d = 0; | - | ||||||||||||||||||||||||
| 1879 | } executed 108 times by 3 tests: end of blockExecuted by:
| 108 | ||||||||||||||||||||||||
| 1880 | - | |||||||||||||||||||||||||
| 1881 | /*! | - | ||||||||||||||||||||||||
| 1882 | Parses \a url and sets this object to that value. QUrl will automatically | - | ||||||||||||||||||||||||
| 1883 | percent encode all characters that are not allowed in a URL and decode the | - | ||||||||||||||||||||||||
| 1884 | percent-encoded sequences that represent an unreserved character (letters, | - | ||||||||||||||||||||||||
| 1885 | digits, hyphens, undercores, dots and tildes). All other characters are | - | ||||||||||||||||||||||||
| 1886 | left in their original forms. | - | ||||||||||||||||||||||||
| 1887 | - | |||||||||||||||||||||||||
| 1888 | Parses the \a url using the parser mode \a parsingMode. In TolerantMode | - | ||||||||||||||||||||||||
| 1889 | (the default), QUrl will correct certain mistakes, notably the presence of | - | ||||||||||||||||||||||||
| 1890 | a percent character ('%') not followed by two hexadecimal digits, and it | - | ||||||||||||||||||||||||
| 1891 | will accept any character in any position. In StrictMode, encoding mistakes | - | ||||||||||||||||||||||||
| 1892 | will not be tolerated and QUrl will also check that certain forbidden | - | ||||||||||||||||||||||||
| 1893 | characters are not present in unencoded form. If an error is detected in | - | ||||||||||||||||||||||||
| 1894 | StrictMode, isValid() will return false. The parsing mode DecodedMode is | - | ||||||||||||||||||||||||
| 1895 | not permitted in this context and will produce a run-time warning. | - | ||||||||||||||||||||||||
| 1896 | - | |||||||||||||||||||||||||
| 1897 | \sa url(), toString() | - | ||||||||||||||||||||||||
| 1898 | */ | - | ||||||||||||||||||||||||
| 1899 | void QUrl::setUrl(const QString &url, ParsingMode parsingMode) | - | ||||||||||||||||||||||||
| 1900 | { | - | ||||||||||||||||||||||||
| 1901 | if (parsingMode == DecodedMode) {
| 0-9955 | ||||||||||||||||||||||||
| 1902 | qWarning("QUrl: QUrl::DecodedMode is not permitted when parsing a full URL"); | - | ||||||||||||||||||||||||
| 1903 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1904 | detach(); | - | ||||||||||||||||||||||||
| 1905 | d->parse(url, parsingMode); | - | ||||||||||||||||||||||||
| 1906 | } executed 9955 times by 35 tests: end of blockExecuted by:
| 9955 | ||||||||||||||||||||||||
| 1907 | } | - | ||||||||||||||||||||||||
| 1908 | - | |||||||||||||||||||||||||
| 1909 | /*! | - | ||||||||||||||||||||||||
| 1910 | \fn void QUrl::setEncodedUrl(const QByteArray &encodedUrl, ParsingMode parsingMode) | - | ||||||||||||||||||||||||
| 1911 | \deprecated | - | ||||||||||||||||||||||||
| 1912 | Constructs a URL by parsing the contents of \a encodedUrl. | - | ||||||||||||||||||||||||
| 1913 | - | |||||||||||||||||||||||||
| 1914 | \a encodedUrl is assumed to be a URL string in percent encoded | - | ||||||||||||||||||||||||
| 1915 | form, containing only ASCII characters. | - | ||||||||||||||||||||||||
| 1916 | - | |||||||||||||||||||||||||
| 1917 | The parsing mode \a parsingMode is used for parsing \a encodedUrl. | - | ||||||||||||||||||||||||
| 1918 | - | |||||||||||||||||||||||||
| 1919 | \obsolete Use setUrl(QString::fromUtf8(encodedUrl), parsingMode) | - | ||||||||||||||||||||||||
| 1920 | - | |||||||||||||||||||||||||
| 1921 | \sa setUrl() | - | ||||||||||||||||||||||||
| 1922 | */ | - | ||||||||||||||||||||||||
| 1923 | - | |||||||||||||||||||||||||
| 1924 | /*! | - | ||||||||||||||||||||||||
| 1925 | Sets the scheme of the URL to \a scheme. As a scheme can only | - | ||||||||||||||||||||||||
| 1926 | contain ASCII characters, no conversion or decoding is done on the | - | ||||||||||||||||||||||||
| 1927 | input. It must also start with an ASCII letter. | - | ||||||||||||||||||||||||
| 1928 | - | |||||||||||||||||||||||||
| 1929 | The scheme describes the type (or protocol) of the URL. It's | - | ||||||||||||||||||||||||
| 1930 | represented by one or more ASCII characters at the start the URL. | - | ||||||||||||||||||||||||
| 1931 | - | |||||||||||||||||||||||||
| 1932 | A scheme is strictly \l {http://www.ietf.org/rfc/rfc3986.txt} {RFC 3986}-compliant: | - | ||||||||||||||||||||||||
| 1933 | \tt {scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )} | - | ||||||||||||||||||||||||
| 1934 | - | |||||||||||||||||||||||||
| 1935 | The following example shows a URL where the scheme is "ftp": | - | ||||||||||||||||||||||||
| 1936 | - | |||||||||||||||||||||||||
| 1937 | \image qurl-authority2.png | - | ||||||||||||||||||||||||
| 1938 | - | |||||||||||||||||||||||||
| 1939 | To set the scheme, the following call is used: | - | ||||||||||||||||||||||||
| 1940 | \code | - | ||||||||||||||||||||||||
| 1941 | QUrl url; | - | ||||||||||||||||||||||||
| 1942 | url.setScheme("ftp"); | - | ||||||||||||||||||||||||
| 1943 | \endcode | - | ||||||||||||||||||||||||
| 1944 | - | |||||||||||||||||||||||||
| 1945 | The scheme can also be empty, in which case the URL is interpreted | - | ||||||||||||||||||||||||
| 1946 | as relative. | - | ||||||||||||||||||||||||
| 1947 | - | |||||||||||||||||||||||||
| 1948 | \sa scheme(), isRelative() | - | ||||||||||||||||||||||||
| 1949 | */ | - | ||||||||||||||||||||||||
| 1950 | void QUrl::setScheme(const QString &scheme) | - | ||||||||||||||||||||||||
| 1951 | { | - | ||||||||||||||||||||||||
| 1952 | detach(); | - | ||||||||||||||||||||||||
| 1953 | d->clearError(); | - | ||||||||||||||||||||||||
| 1954 | if (scheme.isEmpty()) {
| 5864-6194 | ||||||||||||||||||||||||
| 1955 | // schemes are not allowed to be empty | - | ||||||||||||||||||||||||
| 1956 | d->sectionIsPresent &= ~QUrlPrivate::Scheme; | - | ||||||||||||||||||||||||
| 1957 | d->flags &= ~QUrlPrivate::IsLocalFile; | - | ||||||||||||||||||||||||
| 1958 | d->scheme.clear(); | - | ||||||||||||||||||||||||
| 1959 | } else { executed 6194 times by 26 tests: end of blockExecuted by:
| 6194 | ||||||||||||||||||||||||
| 1960 | d->setScheme(scheme, scheme.length(), /* do set error */ true); | - | ||||||||||||||||||||||||
| 1961 | } executed 5864 times by 18 tests: end of blockExecuted by:
| 5864 | ||||||||||||||||||||||||
| 1962 | } | - | ||||||||||||||||||||||||
| 1963 | - | |||||||||||||||||||||||||
| 1964 | /*! | - | ||||||||||||||||||||||||
| 1965 | Returns the scheme of the URL. If an empty string is returned, | - | ||||||||||||||||||||||||
| 1966 | this means the scheme is undefined and the URL is then relative. | - | ||||||||||||||||||||||||
| 1967 | - | |||||||||||||||||||||||||
| 1968 | The scheme can only contain US-ASCII letters or digits, which means it | - | ||||||||||||||||||||||||
| 1969 | cannot contain any character that would otherwise require encoding. | - | ||||||||||||||||||||||||
| 1970 | Additionally, schemes are always returned in lowercase form. | - | ||||||||||||||||||||||||
| 1971 | - | |||||||||||||||||||||||||
| 1972 | \sa setScheme(), isRelative() | - | ||||||||||||||||||||||||
| 1973 | */ | - | ||||||||||||||||||||||||
| 1974 | QString QUrl::scheme() const | - | ||||||||||||||||||||||||
| 1975 | { | - | ||||||||||||||||||||||||
| 1976 | if (!d) return QString(); executed 560 times by 10 tests: return QString();Executed by:
| 560-11019 | ||||||||||||||||||||||||
| 1977 | - | |||||||||||||||||||||||||
| 1978 | return d->scheme; executed 11019 times by 28 tests: return d->scheme;Executed by:
| 11019 | ||||||||||||||||||||||||
| 1979 | } | - | ||||||||||||||||||||||||
| 1980 | - | |||||||||||||||||||||||||
| 1981 | /*! | - | ||||||||||||||||||||||||
| 1982 | Sets the authority of the URL to \a authority. | - | ||||||||||||||||||||||||
| 1983 | - | |||||||||||||||||||||||||
| 1984 | The authority of a URL is the combination of user info, a host | - | ||||||||||||||||||||||||
| 1985 | name and a port. All of these elements are optional; an empty | - | ||||||||||||||||||||||||
| 1986 | authority is therefore valid. | - | ||||||||||||||||||||||||
| 1987 | - | |||||||||||||||||||||||||
| 1988 | The user info and host are separated by a '@', and the host and | - | ||||||||||||||||||||||||
| 1989 | port are separated by a ':'. If the user info is empty, the '@' | - | ||||||||||||||||||||||||
| 1990 | must be omitted; although a stray ':' is permitted if the port is | - | ||||||||||||||||||||||||
| 1991 | empty. | - | ||||||||||||||||||||||||
| 1992 | - | |||||||||||||||||||||||||
| 1993 | The following example shows a valid authority string: | - | ||||||||||||||||||||||||
| 1994 | - | |||||||||||||||||||||||||
| 1995 | \image qurl-authority.png | - | ||||||||||||||||||||||||
| 1996 | - | |||||||||||||||||||||||||
| 1997 | The \a authority data is interpreted according to \a mode: in StrictMode, | - | ||||||||||||||||||||||||
| 1998 | any '%' characters must be followed by exactly two hexadecimal characters | - | ||||||||||||||||||||||||
| 1999 | and some characters (including space) are not allowed in undecoded form. In | - | ||||||||||||||||||||||||
| 2000 | TolerantMode (the default), all characters are accepted in undecoded form | - | ||||||||||||||||||||||||
| 2001 | and the tolerant parser will correct stray '%' not followed by two hex | - | ||||||||||||||||||||||||
| 2002 | characters. | - | ||||||||||||||||||||||||
| 2003 | - | |||||||||||||||||||||||||
| 2004 | This function does not allow \a mode to be QUrl::DecodedMode. To set fully | - | ||||||||||||||||||||||||
| 2005 | decoded data, call setUserName(), setPassword(), setHost() and setPort() | - | ||||||||||||||||||||||||
| 2006 | individually. | - | ||||||||||||||||||||||||
| 2007 | - | |||||||||||||||||||||||||
| 2008 | \sa setUserInfo(), setHost(), setPort() | - | ||||||||||||||||||||||||
| 2009 | */ | - | ||||||||||||||||||||||||
| 2010 | void QUrl::setAuthority(const QString &authority, ParsingMode mode) | - | ||||||||||||||||||||||||
| 2011 | { | - | ||||||||||||||||||||||||
| 2012 | detach(); | - | ||||||||||||||||||||||||
| 2013 | d->clearError(); | - | ||||||||||||||||||||||||
| 2014 | - | |||||||||||||||||||||||||
| 2015 | if (mode == DecodedMode) {
| 0-31 | ||||||||||||||||||||||||
| 2016 | qWarning("QUrl::setAuthority(): QUrl::DecodedMode is not permitted in this function"); | - | ||||||||||||||||||||||||
| 2017 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 2018 | } | - | ||||||||||||||||||||||||
| 2019 | - | |||||||||||||||||||||||||
| 2020 | d->setAuthority(authority, 0, authority.length(), mode); | - | ||||||||||||||||||||||||
| 2021 | if (authority.isNull()) {
| 13-18 | ||||||||||||||||||||||||
| 2022 | // QUrlPrivate::setAuthority cleared almost everything | - | ||||||||||||||||||||||||
| 2023 | // but it leaves the Host bit set | - | ||||||||||||||||||||||||
| 2024 | d->sectionIsPresent &= ~QUrlPrivate::Authority; | - | ||||||||||||||||||||||||
| 2025 | } executed 13 times by 1 test: end of blockExecuted by:
| 13 | ||||||||||||||||||||||||
| 2026 | } executed 31 times by 1 test: end of blockExecuted by:
| 31 | ||||||||||||||||||||||||
| 2027 | - | |||||||||||||||||||||||||
| 2028 | /*! | - | ||||||||||||||||||||||||
| 2029 | Returns the authority of the URL if it is defined; otherwise | - | ||||||||||||||||||||||||
| 2030 | an empty string is returned. | - | ||||||||||||||||||||||||
| 2031 | - | |||||||||||||||||||||||||
| 2032 | This function returns an unambiguous value, which may contain that | - | ||||||||||||||||||||||||
| 2033 | characters still percent-encoded, plus some control sequences not | - | ||||||||||||||||||||||||
| 2034 | representable in decoded form in QString. | - | ||||||||||||||||||||||||
| 2035 | - | |||||||||||||||||||||||||
| 2036 | The \a options argument controls how to format the user info component. The | - | ||||||||||||||||||||||||
| 2037 | value of QUrl::FullyDecoded is not permitted in this function. If you need | - | ||||||||||||||||||||||||
| 2038 | to obtain fully decoded data, call userName(), password(), host() and | - | ||||||||||||||||||||||||
| 2039 | port() individually. | - | ||||||||||||||||||||||||
| 2040 | - | |||||||||||||||||||||||||
| 2041 | \sa setAuthority(), userInfo(), userName(), password(), host(), port() | - | ||||||||||||||||||||||||
| 2042 | */ | - | ||||||||||||||||||||||||
| 2043 | QString QUrl::authority(ComponentFormattingOptions options) const | - | ||||||||||||||||||||||||
| 2044 | { | - | ||||||||||||||||||||||||
| 2045 | if (!d) return QString(); executed 1 time by 1 test: return QString();Executed by:
| 1-177 | ||||||||||||||||||||||||
| 2046 | - | |||||||||||||||||||||||||
| 2047 | if (options == QUrl::FullyDecoded) {
| 0-177 | ||||||||||||||||||||||||
| 2048 | qWarning("QUrl::authority(): QUrl::FullyDecoded is not permitted in this function"); | - | ||||||||||||||||||||||||
| 2049 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||||||||
| 2050 | } | - | ||||||||||||||||||||||||
| 2051 | - | |||||||||||||||||||||||||
| 2052 | QString result; | - | ||||||||||||||||||||||||
| 2053 | d->appendAuthority(result, options, QUrlPrivate::Authority); | - | ||||||||||||||||||||||||
| 2054 | return result; executed 177 times by 3 tests: return result;Executed by:
| 177 | ||||||||||||||||||||||||
| 2055 | } | - | ||||||||||||||||||||||||
| 2056 | - | |||||||||||||||||||||||||
| 2057 | /*! | - | ||||||||||||||||||||||||
| 2058 | Sets the user info of the URL to \a userInfo. The user info is an | - | ||||||||||||||||||||||||
| 2059 | optional part of the authority of the URL, as described in | - | ||||||||||||||||||||||||
| 2060 | setAuthority(). | - | ||||||||||||||||||||||||
| 2061 | - | |||||||||||||||||||||||||
| 2062 | The user info consists of a user name and optionally a password, | - | ||||||||||||||||||||||||
| 2063 | separated by a ':'. If the password is empty, the colon must be | - | ||||||||||||||||||||||||
| 2064 | omitted. The following example shows a valid user info string: | - | ||||||||||||||||||||||||
| 2065 | - | |||||||||||||||||||||||||
| 2066 | \image qurl-authority3.png | - | ||||||||||||||||||||||||
| 2067 | - | |||||||||||||||||||||||||
| 2068 | The \a userInfo data is interpreted according to \a mode: in StrictMode, | - | ||||||||||||||||||||||||
| 2069 | any '%' characters must be followed by exactly two hexadecimal characters | - | ||||||||||||||||||||||||
| 2070 | and some characters (including space) are not allowed in undecoded form. In | - | ||||||||||||||||||||||||
| 2071 | TolerantMode (the default), all characters are accepted in undecoded form | - | ||||||||||||||||||||||||
| 2072 | and the tolerant parser will correct stray '%' not followed by two hex | - | ||||||||||||||||||||||||
| 2073 | characters. | - | ||||||||||||||||||||||||
| 2074 | - | |||||||||||||||||||||||||
| 2075 | This function does not allow \a mode to be QUrl::DecodedMode. To set fully | - | ||||||||||||||||||||||||
| 2076 | decoded data, call setUserName() and setPassword() individually. | - | ||||||||||||||||||||||||
| 2077 | - | |||||||||||||||||||||||||
| 2078 | \sa userInfo(), setUserName(), setPassword(), setAuthority() | - | ||||||||||||||||||||||||
| 2079 | */ | - | ||||||||||||||||||||||||
| 2080 | void QUrl::setUserInfo(const QString &userInfo, ParsingMode mode) | - | ||||||||||||||||||||||||
| 2081 | { | - | ||||||||||||||||||||||||
| 2082 | detach(); | - | ||||||||||||||||||||||||
| 2083 | d->clearError(); | - | ||||||||||||||||||||||||
| 2084 | QString trimmed = userInfo.trimmed(); | - | ||||||||||||||||||||||||
| 2085 | if (mode == DecodedMode) {
| 0-51 | ||||||||||||||||||||||||
| 2086 | qWarning("QUrl::setUserInfo(): QUrl::DecodedMode is not permitted in this function"); | - | ||||||||||||||||||||||||
| 2087 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 2088 | } | - | ||||||||||||||||||||||||
| 2089 | - | |||||||||||||||||||||||||
| 2090 | d->setUserInfo(trimmed, 0, trimmed.length()); | - | ||||||||||||||||||||||||
| 2091 | if (userInfo.isNull()) {
| 10-41 | ||||||||||||||||||||||||
| 2092 | // QUrlPrivate::setUserInfo cleared almost everything | - | ||||||||||||||||||||||||
| 2093 | // but it leaves the UserName bit set | - | ||||||||||||||||||||||||
| 2094 | d->sectionIsPresent &= ~QUrlPrivate::UserInfo; | - | ||||||||||||||||||||||||
| 2095 | } else if (mode == StrictMode && !d->validateComponent(QUrlPrivate::UserInfo, userInfo)) { executed 41 times by 2 tests: end of blockExecuted by:
| 0-41 | ||||||||||||||||||||||||
| 2096 | d->sectionIsPresent &= ~QUrlPrivate::UserInfo; | - | ||||||||||||||||||||||||
| 2097 | d->userName.clear(); | - | ||||||||||||||||||||||||
| 2098 | d->password.clear(); | - | ||||||||||||||||||||||||
| 2099 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||||||||
| 2100 | } executed 51 times by 2 tests: end of blockExecuted by:
| 51 | ||||||||||||||||||||||||
| 2101 | - | |||||||||||||||||||||||||
| 2102 | /*! | - | ||||||||||||||||||||||||
| 2103 | Returns the user info of the URL, or an empty string if the user | - | ||||||||||||||||||||||||
| 2104 | info is undefined. | - | ||||||||||||||||||||||||
| 2105 | - | |||||||||||||||||||||||||
| 2106 | This function returns an unambiguous value, which may contain that | - | ||||||||||||||||||||||||
| 2107 | characters still percent-encoded, plus some control sequences not | - | ||||||||||||||||||||||||
| 2108 | representable in decoded form in QString. | - | ||||||||||||||||||||||||
| 2109 | - | |||||||||||||||||||||||||
| 2110 | The \a options argument controls how to format the user info component. The | - | ||||||||||||||||||||||||
| 2111 | value of QUrl::FullyDecoded is not permitted in this function. If you need | - | ||||||||||||||||||||||||
| 2112 | to obtain fully decoded data, call userName() and password() individually. | - | ||||||||||||||||||||||||
| 2113 | - | |||||||||||||||||||||||||
| 2114 | \sa setUserInfo(), userName(), password(), authority() | - | ||||||||||||||||||||||||
| 2115 | */ | - | ||||||||||||||||||||||||
| 2116 | QString QUrl::userInfo(ComponentFormattingOptions options) const | - | ||||||||||||||||||||||||
| 2117 | { | - | ||||||||||||||||||||||||
| 2118 | if (!d) return QString(); executed 1 time by 1 test: return QString();Executed by:
| 1-2514 | ||||||||||||||||||||||||
| 2119 | - | |||||||||||||||||||||||||
| 2120 | if (options == QUrl::FullyDecoded) {
| 0-2514 | ||||||||||||||||||||||||
| 2121 | qWarning("QUrl::userInfo(): QUrl::FullyDecoded is not permitted in this function"); | - | ||||||||||||||||||||||||
| 2122 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||||||||
| 2123 | } | - | ||||||||||||||||||||||||
| 2124 | - | |||||||||||||||||||||||||
| 2125 | QString result; | - | ||||||||||||||||||||||||
| 2126 | d->appendUserInfo(result, options, QUrlPrivate::UserInfo); | - | ||||||||||||||||||||||||
| 2127 | return result; executed 2514 times by 10 tests: return result;Executed by:
| 2514 | ||||||||||||||||||||||||
| 2128 | } | - | ||||||||||||||||||||||||
| 2129 | - | |||||||||||||||||||||||||
| 2130 | /*! | - | ||||||||||||||||||||||||
| 2131 | Sets the URL's user name to \a userName. The \a userName is part | - | ||||||||||||||||||||||||
| 2132 | of the user info element in the authority of the URL, as described | - | ||||||||||||||||||||||||
| 2133 | in setUserInfo(). | - | ||||||||||||||||||||||||
| 2134 | - | |||||||||||||||||||||||||
| 2135 | The \a userName data is interpreted according to \a mode: in StrictMode, | - | ||||||||||||||||||||||||
| 2136 | any '%' characters must be followed by exactly two hexadecimal characters | - | ||||||||||||||||||||||||
| 2137 | and some characters (including space) are not allowed in undecoded form. In | - | ||||||||||||||||||||||||
| 2138 | TolerantMode (the default), all characters are accepted in undecoded form | - | ||||||||||||||||||||||||
| 2139 | and the tolerant parser will correct stray '%' not followed by two hex | - | ||||||||||||||||||||||||
| 2140 | characters. In DecodedMode, '%' stand for themselves and encoded characters | - | ||||||||||||||||||||||||
| 2141 | are not possible. | - | ||||||||||||||||||||||||
| 2142 | - | |||||||||||||||||||||||||
| 2143 | QUrl::DecodedMode should be used when setting the user name from a data | - | ||||||||||||||||||||||||
| 2144 | source which is not a URL, such as a password dialog shown to the user or | - | ||||||||||||||||||||||||
| 2145 | with a user name obtained by calling userName() with the QUrl::FullyDecoded | - | ||||||||||||||||||||||||
| 2146 | formatting option. | - | ||||||||||||||||||||||||
| 2147 | - | |||||||||||||||||||||||||
| 2148 | \sa userName(), setUserInfo() | - | ||||||||||||||||||||||||
| 2149 | */ | - | ||||||||||||||||||||||||
| 2150 | void QUrl::setUserName(const QString &userName, ParsingMode mode) | - | ||||||||||||||||||||||||
| 2151 | { | - | ||||||||||||||||||||||||
| 2152 | detach(); | - | ||||||||||||||||||||||||
| 2153 | d->clearError(); | - | ||||||||||||||||||||||||
| 2154 | - | |||||||||||||||||||||||||
| 2155 | QString data = userName; | - | ||||||||||||||||||||||||
| 2156 | if (mode == DecodedMode) {
| 9-1888 | ||||||||||||||||||||||||
| 2157 | parseDecodedComponent(data); | - | ||||||||||||||||||||||||
| 2158 | mode = TolerantMode; | - | ||||||||||||||||||||||||
| 2159 | } executed 1888 times by 3 tests: end of blockExecuted by:
| 1888 | ||||||||||||||||||||||||
| 2160 | - | |||||||||||||||||||||||||
| 2161 | d->setUserName(data, 0, data.length()); | - | ||||||||||||||||||||||||
| 2162 | if (userName.isNull())
| 532-1365 | ||||||||||||||||||||||||
| 2163 | d->sectionIsPresent &= ~QUrlPrivate::UserName; executed 532 times by 3 tests: d->sectionIsPresent &= ~QUrlPrivate::UserName;Executed by:
| 532 | ||||||||||||||||||||||||
| 2164 | else if (mode == StrictMode && !d->validateComponent(QUrlPrivate::UserName, userName))
| 0-1361 | ||||||||||||||||||||||||
| 2165 | d->userName.clear(); executed 4 times by 1 test: d->userName.clear();Executed by:
| 4 | ||||||||||||||||||||||||
| 2166 | } executed 1897 times by 3 tests: end of blockExecuted by:
| 1897 | ||||||||||||||||||||||||
| 2167 | - | |||||||||||||||||||||||||
| 2168 | /*! | - | ||||||||||||||||||||||||
| 2169 | Returns the user name of the URL if it is defined; otherwise | - | ||||||||||||||||||||||||
| 2170 | an empty string is returned. | - | ||||||||||||||||||||||||
| 2171 | - | |||||||||||||||||||||||||
| 2172 | The \a options argument controls how to format the user name component. All | - | ||||||||||||||||||||||||
| 2173 | values produce an unambiguous result. With QUrl::FullyDecoded, all | - | ||||||||||||||||||||||||
| 2174 | percent-encoded sequences are decoded; otherwise, the returned value may | - | ||||||||||||||||||||||||
| 2175 | contain some percent-encoded sequences for some control sequences not | - | ||||||||||||||||||||||||
| 2176 | representable in decoded form in QString. | - | ||||||||||||||||||||||||
| 2177 | - | |||||||||||||||||||||||||
| 2178 | Note that QUrl::FullyDecoded may cause data loss if those non-representable | - | ||||||||||||||||||||||||
| 2179 | sequences are present. It is recommended to use that value when the result | - | ||||||||||||||||||||||||
| 2180 | will be used in a non-URL context, such as setting in QAuthenticator or | - | ||||||||||||||||||||||||
| 2181 | negotiating a login. | - | ||||||||||||||||||||||||
| 2182 | - | |||||||||||||||||||||||||
| 2183 | \sa setUserName(), userInfo() | - | ||||||||||||||||||||||||
| 2184 | */ | - | ||||||||||||||||||||||||
| 2185 | QString QUrl::userName(ComponentFormattingOptions options) const | - | ||||||||||||||||||||||||
| 2186 | { | - | ||||||||||||||||||||||||
| 2187 | if (!d) return QString(); executed 2 times by 1 test: return QString();Executed by:
| 2-783 | ||||||||||||||||||||||||
| 2188 | - | |||||||||||||||||||||||||
| 2189 | QString result; | - | ||||||||||||||||||||||||
| 2190 | d->appendUserName(result, options); | - | ||||||||||||||||||||||||
| 2191 | return result; executed 783 times by 3 tests: return result;Executed by:
| 783 | ||||||||||||||||||||||||
| 2192 | } | - | ||||||||||||||||||||||||
| 2193 | - | |||||||||||||||||||||||||
| 2194 | /*! | - | ||||||||||||||||||||||||
| 2195 | \fn void QUrl::setEncodedUserName(const QByteArray &userName) | - | ||||||||||||||||||||||||
| 2196 | \deprecated | - | ||||||||||||||||||||||||
| 2197 | \since 4.4 | - | ||||||||||||||||||||||||
| 2198 | - | |||||||||||||||||||||||||
| 2199 | Sets the URL's user name to the percent-encoded \a userName. The \a | - | ||||||||||||||||||||||||
| 2200 | userName is part of the user info element in the authority of the | - | ||||||||||||||||||||||||
| 2201 | URL, as described in setUserInfo(). | - | ||||||||||||||||||||||||
| 2202 | - | |||||||||||||||||||||||||
| 2203 | \obsolete Use setUserName(QString::fromUtf8(userName)) | - | ||||||||||||||||||||||||
| 2204 | - | |||||||||||||||||||||||||
| 2205 | \sa setUserName(), encodedUserName(), setUserInfo() | - | ||||||||||||||||||||||||
| 2206 | */ | - | ||||||||||||||||||||||||
| 2207 | - | |||||||||||||||||||||||||
| 2208 | /*! | - | ||||||||||||||||||||||||
| 2209 | \fn QByteArray QUrl::encodedUserName() const | - | ||||||||||||||||||||||||
| 2210 | \deprecated | - | ||||||||||||||||||||||||
| 2211 | \since 4.4 | - | ||||||||||||||||||||||||
| 2212 | - | |||||||||||||||||||||||||
| 2213 | Returns the user name of the URL if it is defined; otherwise | - | ||||||||||||||||||||||||
| 2214 | an empty string is returned. The returned value will have its | - | ||||||||||||||||||||||||
| 2215 | non-ASCII and other control characters percent-encoded, as in | - | ||||||||||||||||||||||||
| 2216 | toEncoded(). | - | ||||||||||||||||||||||||
| 2217 | - | |||||||||||||||||||||||||
| 2218 | \obsolete Use userName(QUrl::FullyEncoded).toLatin1() | - | ||||||||||||||||||||||||
| 2219 | - | |||||||||||||||||||||||||
| 2220 | \sa setEncodedUserName() | - | ||||||||||||||||||||||||
| 2221 | */ | - | ||||||||||||||||||||||||
| 2222 | - | |||||||||||||||||||||||||
| 2223 | /*! | - | ||||||||||||||||||||||||
| 2224 | Sets the URL's password to \a password. The \a password is part of | - | ||||||||||||||||||||||||
| 2225 | the user info element in the authority of the URL, as described in | - | ||||||||||||||||||||||||
| 2226 | setUserInfo(). | - | ||||||||||||||||||||||||
| 2227 | - | |||||||||||||||||||||||||
| 2228 | The \a password data is interpreted according to \a mode: in StrictMode, | - | ||||||||||||||||||||||||
| 2229 | any '%' characters must be followed by exactly two hexadecimal characters | - | ||||||||||||||||||||||||
| 2230 | and some characters (including space) are not allowed in undecoded form. In | - | ||||||||||||||||||||||||
| 2231 | TolerantMode, all characters are accepted in undecoded form and the | - | ||||||||||||||||||||||||
| 2232 | tolerant parser will correct stray '%' not followed by two hex characters. | - | ||||||||||||||||||||||||
| 2233 | In DecodedMode, '%' stand for themselves and encoded characters are not | - | ||||||||||||||||||||||||
| 2234 | possible. | - | ||||||||||||||||||||||||
| 2235 | - | |||||||||||||||||||||||||
| 2236 | QUrl::DecodedMode should be used when setting the password from a data | - | ||||||||||||||||||||||||
| 2237 | source which is not a URL, such as a password dialog shown to the user or | - | ||||||||||||||||||||||||
| 2238 | with a password obtained by calling password() with the QUrl::FullyDecoded | - | ||||||||||||||||||||||||
| 2239 | formatting option. | - | ||||||||||||||||||||||||
| 2240 | - | |||||||||||||||||||||||||
| 2241 | \sa password(), setUserInfo() | - | ||||||||||||||||||||||||
| 2242 | */ | - | ||||||||||||||||||||||||
| 2243 | void QUrl::setPassword(const QString &password, ParsingMode mode) | - | ||||||||||||||||||||||||
| 2244 | { | - | ||||||||||||||||||||||||
| 2245 | detach(); | - | ||||||||||||||||||||||||
| 2246 | d->clearError(); | - | ||||||||||||||||||||||||
| 2247 | - | |||||||||||||||||||||||||
| 2248 | QString data = password; | - | ||||||||||||||||||||||||
| 2249 | if (mode == DecodedMode) {
| 7-446 | ||||||||||||||||||||||||
| 2250 | parseDecodedComponent(data); | - | ||||||||||||||||||||||||
| 2251 | mode = TolerantMode; | - | ||||||||||||||||||||||||
| 2252 | } executed 446 times by 5 tests: end of blockExecuted by:
| 446 | ||||||||||||||||||||||||
| 2253 | - | |||||||||||||||||||||||||
| 2254 | d->setPassword(data, 0, data.length()); | - | ||||||||||||||||||||||||
| 2255 | if (password.isNull())
| 16-437 | ||||||||||||||||||||||||
| 2256 | d->sectionIsPresent &= ~QUrlPrivate::Password; executed 437 times by 5 tests: d->sectionIsPresent &= ~QUrlPrivate::Password;Executed by:
| 437 | ||||||||||||||||||||||||
| 2257 | else if (mode == StrictMode && !d->validateComponent(QUrlPrivate::Password, password))
| 0-12 | ||||||||||||||||||||||||
| 2258 | d->password.clear(); executed 4 times by 1 test: d->password.clear();Executed by:
| 4 | ||||||||||||||||||||||||
| 2259 | } executed 453 times by 5 tests: end of blockExecuted by:
| 453 | ||||||||||||||||||||||||
| 2260 | - | |||||||||||||||||||||||||
| 2261 | /*! | - | ||||||||||||||||||||||||
| 2262 | Returns the password of the URL if it is defined; otherwise | - | ||||||||||||||||||||||||
| 2263 | an empty string is returned. | - | ||||||||||||||||||||||||
| 2264 | - | |||||||||||||||||||||||||
| 2265 | The \a options argument controls how to format the user name component. All | - | ||||||||||||||||||||||||
| 2266 | values produce an unambiguous result. With QUrl::FullyDecoded, all | - | ||||||||||||||||||||||||
| 2267 | percent-encoded sequences are decoded; otherwise, the returned value may | - | ||||||||||||||||||||||||
| 2268 | contain some percent-encoded sequences for some control sequences not | - | ||||||||||||||||||||||||
| 2269 | representable in decoded form in QString. | - | ||||||||||||||||||||||||
| 2270 | - | |||||||||||||||||||||||||
| 2271 | Note that QUrl::FullyDecoded may cause data loss if those non-representable | - | ||||||||||||||||||||||||
| 2272 | sequences are present. It is recommended to use that value when the result | - | ||||||||||||||||||||||||
| 2273 | will be used in a non-URL context, such as setting in QAuthenticator or | - | ||||||||||||||||||||||||
| 2274 | negotiating a login. | - | ||||||||||||||||||||||||
| 2275 | - | |||||||||||||||||||||||||
| 2276 | \sa setPassword() | - | ||||||||||||||||||||||||
| 2277 | */ | - | ||||||||||||||||||||||||
| 2278 | QString QUrl::password(ComponentFormattingOptions options) const | - | ||||||||||||||||||||||||
| 2279 | { | - | ||||||||||||||||||||||||
| 2280 | if (!d) return QString(); executed 2 times by 1 test: return QString();Executed by:
| 2-577 | ||||||||||||||||||||||||
| 2281 | - | |||||||||||||||||||||||||
| 2282 | QString result; | - | ||||||||||||||||||||||||
| 2283 | d->appendPassword(result, options); | - | ||||||||||||||||||||||||
| 2284 | return result; executed 577 times by 6 tests: return result;Executed by:
| 577 | ||||||||||||||||||||||||
| 2285 | } | - | ||||||||||||||||||||||||
| 2286 | - | |||||||||||||||||||||||||
| 2287 | /*! | - | ||||||||||||||||||||||||
| 2288 | \fn void QUrl::setEncodedPassword(const QByteArray &password) | - | ||||||||||||||||||||||||
| 2289 | \deprecated | - | ||||||||||||||||||||||||
| 2290 | \since 4.4 | - | ||||||||||||||||||||||||
| 2291 | - | |||||||||||||||||||||||||
| 2292 | Sets the URL's password to the percent-encoded \a password. The \a | - | ||||||||||||||||||||||||
| 2293 | password is part of the user info element in the authority of the | - | ||||||||||||||||||||||||
| 2294 | URL, as described in setUserInfo(). | - | ||||||||||||||||||||||||
| 2295 | - | |||||||||||||||||||||||||
| 2296 | \obsolete Use setPassword(QString::fromUtf8(password)); | - | ||||||||||||||||||||||||
| 2297 | - | |||||||||||||||||||||||||
| 2298 | \sa setPassword(), encodedPassword(), setUserInfo() | - | ||||||||||||||||||||||||
| 2299 | */ | - | ||||||||||||||||||||||||
| 2300 | - | |||||||||||||||||||||||||
| 2301 | /*! | - | ||||||||||||||||||||||||
| 2302 | \fn QByteArray QUrl::encodedPassword() const | - | ||||||||||||||||||||||||
| 2303 | \deprecated | - | ||||||||||||||||||||||||
| 2304 | \since 4.4 | - | ||||||||||||||||||||||||
| 2305 | - | |||||||||||||||||||||||||
| 2306 | Returns the password of the URL if it is defined; otherwise an | - | ||||||||||||||||||||||||
| 2307 | empty string is returned. The returned value will have its | - | ||||||||||||||||||||||||
| 2308 | non-ASCII and other control characters percent-encoded, as in | - | ||||||||||||||||||||||||
| 2309 | toEncoded(). | - | ||||||||||||||||||||||||
| 2310 | - | |||||||||||||||||||||||||
| 2311 | \obsolete Use password(QUrl::FullyEncoded).toLatin1() | - | ||||||||||||||||||||||||
| 2312 | - | |||||||||||||||||||||||||
| 2313 | \sa setEncodedPassword(), toEncoded() | - | ||||||||||||||||||||||||
| 2314 | */ | - | ||||||||||||||||||||||||
| 2315 | - | |||||||||||||||||||||||||
| 2316 | /*! | - | ||||||||||||||||||||||||
| 2317 | Sets the host of the URL to \a host. The host is part of the | - | ||||||||||||||||||||||||
| 2318 | authority. | - | ||||||||||||||||||||||||
| 2319 | - | |||||||||||||||||||||||||
| 2320 | The \a host data is interpreted according to \a mode: in StrictMode, | - | ||||||||||||||||||||||||
| 2321 | any '%' characters must be followed by exactly two hexadecimal characters | - | ||||||||||||||||||||||||
| 2322 | and some characters (including space) are not allowed in undecoded form. In | - | ||||||||||||||||||||||||
| 2323 | TolerantMode, all characters are accepted in undecoded form and the | - | ||||||||||||||||||||||||
| 2324 | tolerant parser will correct stray '%' not followed by two hex characters. | - | ||||||||||||||||||||||||
| 2325 | In DecodedMode, '%' stand for themselves and encoded characters are not | - | ||||||||||||||||||||||||
| 2326 | possible. | - | ||||||||||||||||||||||||
| 2327 | - | |||||||||||||||||||||||||
| 2328 | Note that, in all cases, the result of the parsing must be a valid hostname | - | ||||||||||||||||||||||||
| 2329 | according to STD 3 rules, as modified by the Internationalized Resource | - | ||||||||||||||||||||||||
| 2330 | Identifiers specification (RFC 3987). Invalid hostnames are not permitted | - | ||||||||||||||||||||||||
| 2331 | and will cause isValid() to become false. | - | ||||||||||||||||||||||||
| 2332 | - | |||||||||||||||||||||||||
| 2333 | \sa host(), setAuthority() | - | ||||||||||||||||||||||||
| 2334 | */ | - | ||||||||||||||||||||||||
| 2335 | void QUrl::setHost(const QString &host, ParsingMode mode) | - | ||||||||||||||||||||||||
| 2336 | { | - | ||||||||||||||||||||||||
| 2337 | detach(); | - | ||||||||||||||||||||||||
| 2338 | d->clearError(); | - | ||||||||||||||||||||||||
| 2339 | - | |||||||||||||||||||||||||
| 2340 | QString data = host; | - | ||||||||||||||||||||||||
| 2341 | if (mode == DecodedMode) {
| 5-6961 | ||||||||||||||||||||||||
| 2342 | parseDecodedComponent(data); | - | ||||||||||||||||||||||||
| 2343 | mode = TolerantMode; | - | ||||||||||||||||||||||||
| 2344 | } executed 6961 times by 27 tests: end of blockExecuted by:
| 6961 | ||||||||||||||||||||||||
| 2345 | - | |||||||||||||||||||||||||
| 2346 | if (d->setHost(data, 0, data.length(), mode)) {
| 81-6885 | ||||||||||||||||||||||||
| 2347 | if (host.isNull())
| 181-6704 | ||||||||||||||||||||||||
| 2348 | d->sectionIsPresent &= ~QUrlPrivate::Host; executed 181 times by 7 tests: d->sectionIsPresent &= ~QUrlPrivate::Host;Executed by:
| 181 | ||||||||||||||||||||||||
| 2349 | } else if (!data.startsWith(QLatin1Char('['))) { executed 6885 times by 27 tests: end of blockExecuted by:
| 0-6885 | ||||||||||||||||||||||||
| 2350 | // setHost failed, it might be IPv6 or IPvFuture in need of bracketing | - | ||||||||||||||||||||||||
| 2351 | Q_ASSERT(d->error); | - | ||||||||||||||||||||||||
| 2352 | - | |||||||||||||||||||||||||
| 2353 | data.prepend(QLatin1Char('[')); | - | ||||||||||||||||||||||||
| 2354 | data.append(QLatin1Char(']')); | - | ||||||||||||||||||||||||
| 2355 | if (!d->setHost(data, 0, data.length(), mode)) {
| 27-54 | ||||||||||||||||||||||||
| 2356 | // failed again | - | ||||||||||||||||||||||||
| 2357 | if (data.contains(QLatin1Char(':'))) {
| 8-19 | ||||||||||||||||||||||||
| 2358 | // source data contains ':', so it's an IPv6 error | - | ||||||||||||||||||||||||
| 2359 | d->error->code = QUrlPrivate::InvalidIPv6AddressError; | - | ||||||||||||||||||||||||
| 2360 | } executed 8 times by 4 tests: end of blockExecuted by:
| 8 | ||||||||||||||||||||||||
| 2361 | } else { executed 27 times by 5 tests: end of blockExecuted by:
| 27 | ||||||||||||||||||||||||
| 2362 | // succeeded | - | ||||||||||||||||||||||||
| 2363 | d->clearError(); | - | ||||||||||||||||||||||||
| 2364 | } executed 54 times by 5 tests: end of blockExecuted by:
| 54 | ||||||||||||||||||||||||
| 2365 | } | - | ||||||||||||||||||||||||
| 2366 | } executed 6966 times by 27 tests: end of blockExecuted by:
| 6966 | ||||||||||||||||||||||||
| 2367 | - | |||||||||||||||||||||||||
| 2368 | /*! | - | ||||||||||||||||||||||||
| 2369 | Returns the host of the URL if it is defined; otherwise | - | ||||||||||||||||||||||||
| 2370 | an empty string is returned. | - | ||||||||||||||||||||||||
| 2371 | - | |||||||||||||||||||||||||
| 2372 | The \a options argument controls how the hostname will be formatted. The | - | ||||||||||||||||||||||||
| 2373 | QUrl::EncodeUnicode option will cause this function to return the hostname | - | ||||||||||||||||||||||||
| 2374 | in the ASCII-Compatible Encoding (ACE) form, which is suitable for use in | - | ||||||||||||||||||||||||
| 2375 | channels that are not 8-bit clean or that require the legacy hostname (such | - | ||||||||||||||||||||||||
| 2376 | as DNS requests or in HTTP request headers). If that flag is not present, | - | ||||||||||||||||||||||||
| 2377 | this function returns the International Domain Name (IDN) in Unicode form, | - | ||||||||||||||||||||||||
| 2378 | according to the list of permissible top-level domains (see | - | ||||||||||||||||||||||||
| 2379 | idnWhitelist()). | - | ||||||||||||||||||||||||
| 2380 | - | |||||||||||||||||||||||||
| 2381 | All other flags are ignored. Host names cannot contain control or percent | - | ||||||||||||||||||||||||
| 2382 | characters, so the returned value can be considered fully decoded. | - | ||||||||||||||||||||||||
| 2383 | - | |||||||||||||||||||||||||
| 2384 | \sa setHost(), idnWhitelist(), setIdnWhitelist(), authority() | - | ||||||||||||||||||||||||
| 2385 | */ | - | ||||||||||||||||||||||||
| 2386 | QString QUrl::host(ComponentFormattingOptions options) const | - | ||||||||||||||||||||||||
| 2387 | { | - | ||||||||||||||||||||||||
| 2388 | if (!d) return QString(); executed 2576 times by 20 tests: return QString();Executed by:
| 2576-10126 | ||||||||||||||||||||||||
| 2389 | - | |||||||||||||||||||||||||
| 2390 | QString result; | - | ||||||||||||||||||||||||
| 2391 | d->appendHost(result, options); | - | ||||||||||||||||||||||||
| 2392 | if (result.startsWith(QLatin1Char('[')))
| 53-10073 | ||||||||||||||||||||||||
| 2393 | return result.mid(1, result.length() - 2); executed 53 times by 7 tests: return result.mid(1, result.length() - 2);Executed by:
| 53 | ||||||||||||||||||||||||
| 2394 | return result; executed 10073 times by 34 tests: return result;Executed by:
| 10073 | ||||||||||||||||||||||||
| 2395 | } | - | ||||||||||||||||||||||||
| 2396 | - | |||||||||||||||||||||||||
| 2397 | /*! | - | ||||||||||||||||||||||||
| 2398 | \fn void QUrl::setEncodedHost(const QByteArray &host) | - | ||||||||||||||||||||||||
| 2399 | \deprecated | - | ||||||||||||||||||||||||
| 2400 | \since 4.4 | - | ||||||||||||||||||||||||
| 2401 | - | |||||||||||||||||||||||||
| 2402 | Sets the URL's host to the ACE- or percent-encoded \a host. The \a | - | ||||||||||||||||||||||||
| 2403 | host is part of the user info element in the authority of the | - | ||||||||||||||||||||||||
| 2404 | URL, as described in setAuthority(). | - | ||||||||||||||||||||||||
| 2405 | - | |||||||||||||||||||||||||
| 2406 | \obsolete Use setHost(QString::fromUtf8(host)). | - | ||||||||||||||||||||||||
| 2407 | - | |||||||||||||||||||||||||
| 2408 | \sa setHost(), encodedHost(), setAuthority(), fromAce() | - | ||||||||||||||||||||||||
| 2409 | */ | - | ||||||||||||||||||||||||
| 2410 | - | |||||||||||||||||||||||||
| 2411 | /*! | - | ||||||||||||||||||||||||
| 2412 | \fn QByteArray QUrl::encodedHost() const | - | ||||||||||||||||||||||||
| 2413 | \deprecated | - | ||||||||||||||||||||||||
| 2414 | \since 4.4 | - | ||||||||||||||||||||||||
| 2415 | - | |||||||||||||||||||||||||
| 2416 | Returns the host part of the URL if it is defined; otherwise | - | ||||||||||||||||||||||||
| 2417 | an empty string is returned. | - | ||||||||||||||||||||||||
| 2418 | - | |||||||||||||||||||||||||
| 2419 | Note: encodedHost() does not return percent-encoded hostnames. Instead, | - | ||||||||||||||||||||||||
| 2420 | the ACE-encoded (bare ASCII in Punycode encoding) form will be | - | ||||||||||||||||||||||||
| 2421 | returned for any non-ASCII hostname. | - | ||||||||||||||||||||||||
| 2422 | - | |||||||||||||||||||||||||
| 2423 | This function is equivalent to calling QUrl::toAce() on the return | - | ||||||||||||||||||||||||
| 2424 | value of host(). | - | ||||||||||||||||||||||||
| 2425 | - | |||||||||||||||||||||||||
| 2426 | \obsolete Use host(QUrl::FullyEncoded).toLatin1() or toAce(host()). | - | ||||||||||||||||||||||||
| 2427 | - | |||||||||||||||||||||||||
| 2428 | \sa setEncodedHost() | - | ||||||||||||||||||||||||
| 2429 | */ | - | ||||||||||||||||||||||||
| 2430 | - | |||||||||||||||||||||||||
| 2431 | /*! | - | ||||||||||||||||||||||||
| 2432 | Sets the port of the URL to \a port. The port is part of the | - | ||||||||||||||||||||||||
| 2433 | authority of the URL, as described in setAuthority(). | - | ||||||||||||||||||||||||
| 2434 | - | |||||||||||||||||||||||||
| 2435 | \a port must be between 0 and 65535 inclusive. Setting the | - | ||||||||||||||||||||||||
| 2436 | port to -1 indicates that the port is unspecified. | - | ||||||||||||||||||||||||
| 2437 | */ | - | ||||||||||||||||||||||||
| 2438 | void QUrl::setPort(int port) | - | ||||||||||||||||||||||||
| 2439 | { | - | ||||||||||||||||||||||||
| 2440 | detach(); | - | ||||||||||||||||||||||||
| 2441 | d->clearError(); | - | ||||||||||||||||||||||||
| 2442 | - | |||||||||||||||||||||||||
| 2443 | if (port < -1 || port > 65535) {
| 1-7715 | ||||||||||||||||||||||||
| 2444 | d->setError(QUrlPrivate::InvalidPortError, QString::number(port), 0); | - | ||||||||||||||||||||||||
| 2445 | port = -1; | - | ||||||||||||||||||||||||
| 2446 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||||||||
| 2447 | - | |||||||||||||||||||||||||
| 2448 | d->port = port; | - | ||||||||||||||||||||||||
| 2449 | } executed 7716 times by 30 tests: end of blockExecuted by:
| 7716 | ||||||||||||||||||||||||
| 2450 | - | |||||||||||||||||||||||||
| 2451 | /*! | - | ||||||||||||||||||||||||
| 2452 | \since 4.1 | - | ||||||||||||||||||||||||
| 2453 | - | |||||||||||||||||||||||||
| 2454 | Returns the port of the URL, or \a defaultPort if the port is | - | ||||||||||||||||||||||||
| 2455 | unspecified. | - | ||||||||||||||||||||||||
| 2456 | - | |||||||||||||||||||||||||
| 2457 | Example: | - | ||||||||||||||||||||||||
| 2458 | - | |||||||||||||||||||||||||
| 2459 | \snippet code/src_corelib_io_qurl.cpp 3 | - | ||||||||||||||||||||||||
| 2460 | */ | - | ||||||||||||||||||||||||
| 2461 | int QUrl::port(int defaultPort) const | - | ||||||||||||||||||||||||
| 2462 | { | - | ||||||||||||||||||||||||
| 2463 | if (!d) return defaultPort; executed 1 time by 1 test: return defaultPort;Executed by:
| 1-4126 | ||||||||||||||||||||||||
| 2464 | return d->port == -1 ? defaultPort : d->port; executed 4126 times by 10 tests: return d->port == -1 ? defaultPort : d->port;Executed by:
| 1803-4126 | ||||||||||||||||||||||||
| 2465 | } | - | ||||||||||||||||||||||||
| 2466 | - | |||||||||||||||||||||||||
| 2467 | /*! | - | ||||||||||||||||||||||||
| 2468 | Sets the path of the URL to \a path. The path is the part of the | - | ||||||||||||||||||||||||
| 2469 | URL that comes after the authority but before the query string. | - | ||||||||||||||||||||||||
| 2470 | - | |||||||||||||||||||||||||
| 2471 | \image qurl-ftppath.png | - | ||||||||||||||||||||||||
| 2472 | - | |||||||||||||||||||||||||
| 2473 | For non-hierarchical schemes, the path will be everything | - | ||||||||||||||||||||||||
| 2474 | following the scheme declaration, as in the following example: | - | ||||||||||||||||||||||||
| 2475 | - | |||||||||||||||||||||||||
| 2476 | \image qurl-mailtopath.png | - | ||||||||||||||||||||||||
| 2477 | - | |||||||||||||||||||||||||
| 2478 | The \a path data is interpreted according to \a mode: in StrictMode, | - | ||||||||||||||||||||||||
| 2479 | any '%' characters must be followed by exactly two hexadecimal characters | - | ||||||||||||||||||||||||
| 2480 | and some characters (including space) are not allowed in undecoded form. In | - | ||||||||||||||||||||||||
| 2481 | TolerantMode (the default), all characters are accepted in undecoded form and the | - | ||||||||||||||||||||||||
| 2482 | tolerant parser will correct stray '%' not followed by two hex characters. | - | ||||||||||||||||||||||||
| 2483 | In DecodedMode, '%' stand for themselves and encoded characters are not | - | ||||||||||||||||||||||||
| 2484 | possible. | - | ||||||||||||||||||||||||
| 2485 | - | |||||||||||||||||||||||||
| 2486 | QUrl::DecodedMode should be used when setting the path from a data source | - | ||||||||||||||||||||||||
| 2487 | which is not a URL, such as a dialog shown to the user or with a path | - | ||||||||||||||||||||||||
| 2488 | obtained by calling path() with the QUrl::FullyDecoded formatting option. | - | ||||||||||||||||||||||||
| 2489 | - | |||||||||||||||||||||||||
| 2490 | \sa path() | - | ||||||||||||||||||||||||
| 2491 | */ | - | ||||||||||||||||||||||||
| 2492 | void QUrl::setPath(const QString &path, ParsingMode mode) | - | ||||||||||||||||||||||||
| 2493 | { | - | ||||||||||||||||||||||||
| 2494 | detach(); | - | ||||||||||||||||||||||||
| 2495 | d->clearError(); | - | ||||||||||||||||||||||||
| 2496 | - | |||||||||||||||||||||||||
| 2497 | QString data = path; | - | ||||||||||||||||||||||||
| 2498 | if (mode == DecodedMode) {
| 12-5472 | ||||||||||||||||||||||||
| 2499 | parseDecodedComponent(data); | - | ||||||||||||||||||||||||
| 2500 | mode = TolerantMode; | - | ||||||||||||||||||||||||
| 2501 | } executed 5472 times by 17 tests: end of blockExecuted by:
| 5472 | ||||||||||||||||||||||||
| 2502 | - | |||||||||||||||||||||||||
| 2503 | int from = 0; | - | ||||||||||||||||||||||||
| 2504 | while (from < data.length() - 2 && data.midRef(from, 2) == QLatin1String("//"))
| 2-5148 | ||||||||||||||||||||||||
| 2505 | ++from; executed 2 times by 1 test: ++from;Executed by:
| 2 | ||||||||||||||||||||||||
| 2506 | d->setPath(data, from, data.length()); | - | ||||||||||||||||||||||||
| 2507 | - | |||||||||||||||||||||||||
| 2508 | // optimized out, since there is no path delimiter | - | ||||||||||||||||||||||||
| 2509 | // if (path.isNull()) | - | ||||||||||||||||||||||||
| 2510 | // d->sectionIsPresent &= ~QUrlPrivate::Path; | - | ||||||||||||||||||||||||
| 2511 | // else | - | ||||||||||||||||||||||||
| 2512 | if (mode == StrictMode && !d->validateComponent(QUrlPrivate::Path, path))
| 2-5480 | ||||||||||||||||||||||||
| 2513 | d->path.clear(); executed 2 times by 1 test: d->path.clear();Executed by:
| 2 | ||||||||||||||||||||||||
| 2514 | } executed 5484 times by 17 tests: end of blockExecuted by:
| 5484 | ||||||||||||||||||||||||
| 2515 | - | |||||||||||||||||||||||||
| 2516 | /*! | - | ||||||||||||||||||||||||
| 2517 | Returns the path of the URL. | - | ||||||||||||||||||||||||
| 2518 | - | |||||||||||||||||||||||||
| 2519 | The \a options argument controls how to format the path component. All | - | ||||||||||||||||||||||||
| 2520 | values produce an unambiguous result. With QUrl::FullyDecoded, all | - | ||||||||||||||||||||||||
| 2521 | percent-encoded sequences are decoded; otherwise, the returned value may | - | ||||||||||||||||||||||||
| 2522 | contain some percent-encoded sequences for some control sequences not | - | ||||||||||||||||||||||||
| 2523 | representable in decoded form in QString. | - | ||||||||||||||||||||||||
| 2524 | - | |||||||||||||||||||||||||
| 2525 | Note that QUrl::FullyDecoded may cause data loss if those non-representable | - | ||||||||||||||||||||||||
| 2526 | sequences are present. It is recommended to use that value when the result | - | ||||||||||||||||||||||||
| 2527 | will be used in a non-URL context, such as sending to an FTP server. | - | ||||||||||||||||||||||||
| 2528 | - | |||||||||||||||||||||||||
| 2529 | \sa setPath() | - | ||||||||||||||||||||||||
| 2530 | */ | - | ||||||||||||||||||||||||
| 2531 | QString QUrl::path(ComponentFormattingOptions options) const | - | ||||||||||||||||||||||||
| 2532 | { | - | ||||||||||||||||||||||||
| 2533 | if (!d) return QString(); executed 7 times by 3 tests: return QString();Executed by:
| 7-4804 | ||||||||||||||||||||||||
| 2534 | - | |||||||||||||||||||||||||
| 2535 | QString result; | - | ||||||||||||||||||||||||
| 2536 | d->appendPath(result, options, QUrlPrivate::Path); | - | ||||||||||||||||||||||||
| 2537 | return result; executed 4804 times by 20 tests: return result;Executed by:
| 4804 | ||||||||||||||||||||||||
| 2538 | } | - | ||||||||||||||||||||||||
| 2539 | - | |||||||||||||||||||||||||
| 2540 | /*! | - | ||||||||||||||||||||||||
| 2541 | \fn void QUrl::setEncodedPath(const QByteArray &path) | - | ||||||||||||||||||||||||
| 2542 | \deprecated | - | ||||||||||||||||||||||||
| 2543 | \since 4.4 | - | ||||||||||||||||||||||||
| 2544 | - | |||||||||||||||||||||||||
| 2545 | Sets the URL's path to the percent-encoded \a path. The path is | - | ||||||||||||||||||||||||
| 2546 | the part of the URL that comes after the authority but before the | - | ||||||||||||||||||||||||
| 2547 | query string. | - | ||||||||||||||||||||||||
| 2548 | - | |||||||||||||||||||||||||
| 2549 | \image qurl-ftppath.png | - | ||||||||||||||||||||||||
| 2550 | - | |||||||||||||||||||||||||
| 2551 | For non-hierarchical schemes, the path will be everything | - | ||||||||||||||||||||||||
| 2552 | following the scheme declaration, as in the following example: | - | ||||||||||||||||||||||||
| 2553 | - | |||||||||||||||||||||||||
| 2554 | \image qurl-mailtopath.png | - | ||||||||||||||||||||||||
| 2555 | - | |||||||||||||||||||||||||
| 2556 | \obsolete Use setPath(QString::fromUtf8(path)). | - | ||||||||||||||||||||||||
| 2557 | - | |||||||||||||||||||||||||
| 2558 | \sa setPath(), encodedPath(), setUserInfo() | - | ||||||||||||||||||||||||
| 2559 | */ | - | ||||||||||||||||||||||||
| 2560 | - | |||||||||||||||||||||||||
| 2561 | /*! | - | ||||||||||||||||||||||||
| 2562 | \fn QByteArray QUrl::encodedPath() const | - | ||||||||||||||||||||||||
| 2563 | \deprecated | - | ||||||||||||||||||||||||
| 2564 | \since 4.4 | - | ||||||||||||||||||||||||
| 2565 | - | |||||||||||||||||||||||||
| 2566 | Returns the path of the URL if it is defined; otherwise an | - | ||||||||||||||||||||||||
| 2567 | empty string is returned. The returned value will have its | - | ||||||||||||||||||||||||
| 2568 | non-ASCII and other control characters percent-encoded, as in | - | ||||||||||||||||||||||||
| 2569 | toEncoded(). | - | ||||||||||||||||||||||||
| 2570 | - | |||||||||||||||||||||||||
| 2571 | \obsolete Use path(QUrl::FullyEncoded).toLatin1(). | - | ||||||||||||||||||||||||
| 2572 | - | |||||||||||||||||||||||||
| 2573 | \sa setEncodedPath(), toEncoded() | - | ||||||||||||||||||||||||
| 2574 | */ | - | ||||||||||||||||||||||||
| 2575 | - | |||||||||||||||||||||||||
| 2576 | /*! | - | ||||||||||||||||||||||||
| 2577 | \since 5.2 | - | ||||||||||||||||||||||||
| 2578 | - | |||||||||||||||||||||||||
| 2579 | Returns the name of the file, excluding the directory path. | - | ||||||||||||||||||||||||
| 2580 | - | |||||||||||||||||||||||||
| 2581 | Note that, if this QUrl object is given a path ending in a slash, the name of the file is considered empty. | - | ||||||||||||||||||||||||
| 2582 | - | |||||||||||||||||||||||||
| 2583 | If the path doesn't contain any slash, it is fully returned as the fileName. | - | ||||||||||||||||||||||||
| 2584 | - | |||||||||||||||||||||||||
| 2585 | Example: | - | ||||||||||||||||||||||||
| 2586 | - | |||||||||||||||||||||||||
| 2587 | \snippet code/src_corelib_io_qurl.cpp 7 | - | ||||||||||||||||||||||||
| 2588 | - | |||||||||||||||||||||||||
| 2589 | The \a options argument controls how to format the file name component. All | - | ||||||||||||||||||||||||
| 2590 | values produce an unambiguous result. With QUrl::FullyDecoded, all | - | ||||||||||||||||||||||||
| 2591 | percent-encoded sequences are decoded; otherwise, the returned value may | - | ||||||||||||||||||||||||
| 2592 | contain some percent-encoded sequences for some control sequences not | - | ||||||||||||||||||||||||
| 2593 | representable in decoded form in QString. | - | ||||||||||||||||||||||||
| 2594 | - | |||||||||||||||||||||||||
| 2595 | \sa path() | - | ||||||||||||||||||||||||
| 2596 | */ | - | ||||||||||||||||||||||||
| 2597 | QString QUrl::fileName(ComponentFormattingOptions options) const | - | ||||||||||||||||||||||||
| 2598 | { | - | ||||||||||||||||||||||||
| 2599 | const QString ourPath = path(options); | - | ||||||||||||||||||||||||
| 2600 | const int slash = ourPath.lastIndexOf(QLatin1Char('/')); | - | ||||||||||||||||||||||||
| 2601 | if (slash == -1)
| 2-15 | ||||||||||||||||||||||||
| 2602 | return ourPath; executed 2 times by 1 test: return ourPath;Executed by:
| 2 | ||||||||||||||||||||||||
| 2603 | return ourPath.mid(slash + 1); executed 15 times by 1 test: return ourPath.mid(slash + 1);Executed by:
| 15 | ||||||||||||||||||||||||
| 2604 | } | - | ||||||||||||||||||||||||
| 2605 | - | |||||||||||||||||||||||||
| 2606 | /*! | - | ||||||||||||||||||||||||
| 2607 | \since 4.2 | - | ||||||||||||||||||||||||
| 2608 | - | |||||||||||||||||||||||||
| 2609 | Returns \c true if this URL contains a Query (i.e., if ? was seen on it). | - | ||||||||||||||||||||||||
| 2610 | - | |||||||||||||||||||||||||
| 2611 | \sa setQuery(), query(), hasFragment() | - | ||||||||||||||||||||||||
| 2612 | */ | - | ||||||||||||||||||||||||
| 2613 | bool QUrl::hasQuery() const | - | ||||||||||||||||||||||||
| 2614 | { | - | ||||||||||||||||||||||||
| 2615 | if (!d) return false; never executed: return false;
| 0-26 | ||||||||||||||||||||||||
| 2616 | return d->hasQuery(); executed 26 times by 2 tests: return d->hasQuery();Executed by:
| 26 | ||||||||||||||||||||||||
| 2617 | } | - | ||||||||||||||||||||||||
| 2618 | - | |||||||||||||||||||||||||
| 2619 | /*! | - | ||||||||||||||||||||||||
| 2620 | Sets the query string of the URL to \a query. | - | ||||||||||||||||||||||||
| 2621 | - | |||||||||||||||||||||||||
| 2622 | This function is useful if you need to pass a query string that | - | ||||||||||||||||||||||||
| 2623 | does not fit into the key-value pattern, or that uses a different | - | ||||||||||||||||||||||||
| 2624 | scheme for encoding special characters than what is suggested by | - | ||||||||||||||||||||||||
| 2625 | QUrl. | - | ||||||||||||||||||||||||
| 2626 | - | |||||||||||||||||||||||||
| 2627 | Passing a value of QString() to \a query (a null QString) unsets | - | ||||||||||||||||||||||||
| 2628 | the query completely. However, passing a value of QString("") | - | ||||||||||||||||||||||||
| 2629 | will set the query to an empty value, as if the original URL | - | ||||||||||||||||||||||||
| 2630 | had a lone "?". | - | ||||||||||||||||||||||||
| 2631 | - | |||||||||||||||||||||||||
| 2632 | The \a query data is interpreted according to \a mode: in StrictMode, | - | ||||||||||||||||||||||||
| 2633 | any '%' characters must be followed by exactly two hexadecimal characters | - | ||||||||||||||||||||||||
| 2634 | and some characters (including space) are not allowed in undecoded form. In | - | ||||||||||||||||||||||||
| 2635 | TolerantMode, all characters are accepted in undecoded form and the | - | ||||||||||||||||||||||||
| 2636 | tolerant parser will correct stray '%' not followed by two hex characters. | - | ||||||||||||||||||||||||
| 2637 | In DecodedMode, '%' stand for themselves and encoded characters are not | - | ||||||||||||||||||||||||
| 2638 | possible. | - | ||||||||||||||||||||||||
| 2639 | - | |||||||||||||||||||||||||
| 2640 | Query strings often contain percent-encoded sequences, so use of | - | ||||||||||||||||||||||||
| 2641 | DecodedMode is discouraged. One special sequence to be aware of is that of | - | ||||||||||||||||||||||||
| 2642 | the plus character ('+'). QUrl does not convert spaces to plus characters, | - | ||||||||||||||||||||||||
| 2643 | even though HTML forms posted by web browsers do. In order to represent an | - | ||||||||||||||||||||||||
| 2644 | actual plus character in a query, the sequence "%2B" is usually used. This | - | ||||||||||||||||||||||||
| 2645 | function will leave "%2B" sequences untouched in TolerantMode or | - | ||||||||||||||||||||||||
| 2646 | StrictMode. | - | ||||||||||||||||||||||||
| 2647 | - | |||||||||||||||||||||||||
| 2648 | \sa query(), hasQuery() | - | ||||||||||||||||||||||||
| 2649 | */ | - | ||||||||||||||||||||||||
| 2650 | void QUrl::setQuery(const QString &query, ParsingMode mode) | - | ||||||||||||||||||||||||
| 2651 | { | - | ||||||||||||||||||||||||
| 2652 | detach(); | - | ||||||||||||||||||||||||
| 2653 | d->clearError(); | - | ||||||||||||||||||||||||
| 2654 | - | |||||||||||||||||||||||||
| 2655 | QString data = query; | - | ||||||||||||||||||||||||
| 2656 | if (mode == DecodedMode) {
| 1-158 | ||||||||||||||||||||||||
| 2657 | parseDecodedComponent(data); | - | ||||||||||||||||||||||||
| 2658 | mode = TolerantMode; | - | ||||||||||||||||||||||||
| 2659 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||
| 2660 | - | |||||||||||||||||||||||||
| 2661 | d->setQuery(data, 0, data.length()); | - | ||||||||||||||||||||||||
| 2662 | if (query.isNull())
| 7-152 | ||||||||||||||||||||||||
| 2663 | d->sectionIsPresent &= ~QUrlPrivate::Query; executed 7 times by 1 test: d->sectionIsPresent &= ~QUrlPrivate::Query;Executed by:
| 7 | ||||||||||||||||||||||||
| 2664 | else if (mode == StrictMode && !d->validateComponent(QUrlPrivate::Query, query))
| 0-150 | ||||||||||||||||||||||||
| 2665 | d->query.clear(); executed 2 times by 1 test: d->query.clear();Executed by:
| 2 | ||||||||||||||||||||||||
| 2666 | } executed 159 times by 3 tests: end of blockExecuted by:
| 159 | ||||||||||||||||||||||||
| 2667 | - | |||||||||||||||||||||||||
| 2668 | /*! | - | ||||||||||||||||||||||||
| 2669 | \fn void QUrl::setEncodedQuery(const QByteArray &query) | - | ||||||||||||||||||||||||
| 2670 | \deprecated | - | ||||||||||||||||||||||||
| 2671 | - | |||||||||||||||||||||||||
| 2672 | Sets the query string of the URL to \a query. The string is | - | ||||||||||||||||||||||||
| 2673 | inserted as-is, and no further encoding is performed when calling | - | ||||||||||||||||||||||||
| 2674 | toEncoded(). | - | ||||||||||||||||||||||||
| 2675 | - | |||||||||||||||||||||||||
| 2676 | This function is useful if you need to pass a query string that | - | ||||||||||||||||||||||||
| 2677 | does not fit into the key-value pattern, or that uses a different | - | ||||||||||||||||||||||||
| 2678 | scheme for encoding special characters than what is suggested by | - | ||||||||||||||||||||||||
| 2679 | QUrl. | - | ||||||||||||||||||||||||
| 2680 | - | |||||||||||||||||||||||||
| 2681 | Passing a value of QByteArray() to \a query (a null QByteArray) unsets | - | ||||||||||||||||||||||||
| 2682 | the query completely. However, passing a value of QByteArray("") | - | ||||||||||||||||||||||||
| 2683 | will set the query to an empty value, as if the original URL | - | ||||||||||||||||||||||||
| 2684 | had a lone "?". | - | ||||||||||||||||||||||||
| 2685 | - | |||||||||||||||||||||||||
| 2686 | \obsolete Use setQuery, which has the same null / empty behavior. | - | ||||||||||||||||||||||||
| 2687 | - | |||||||||||||||||||||||||
| 2688 | \sa encodedQuery(), hasQuery() | - | ||||||||||||||||||||||||
| 2689 | */ | - | ||||||||||||||||||||||||
| 2690 | - | |||||||||||||||||||||||||
| 2691 | /*! | - | ||||||||||||||||||||||||
| 2692 | \overload | - | ||||||||||||||||||||||||
| 2693 | \since 5.0 | - | ||||||||||||||||||||||||
| 2694 | Sets the query string of the URL to \a query. | - | ||||||||||||||||||||||||
| 2695 | - | |||||||||||||||||||||||||
| 2696 | This function reconstructs the query string from the QUrlQuery object and | - | ||||||||||||||||||||||||
| 2697 | sets on this QUrl object. This function does not have parsing parameters | - | ||||||||||||||||||||||||
| 2698 | because the QUrlQuery contains data that is already parsed. | - | ||||||||||||||||||||||||
| 2699 | - | |||||||||||||||||||||||||
| 2700 | \sa query(), hasQuery() | - | ||||||||||||||||||||||||
| 2701 | */ | - | ||||||||||||||||||||||||
| 2702 | void QUrl::setQuery(const QUrlQuery &query) | - | ||||||||||||||||||||||||
| 2703 | { | - | ||||||||||||||||||||||||
| 2704 | detach(); | - | ||||||||||||||||||||||||
| 2705 | d->clearError(); | - | ||||||||||||||||||||||||
| 2706 | - | |||||||||||||||||||||||||
| 2707 | // we know the data is in the right format | - | ||||||||||||||||||||||||
| 2708 | d->query = query.toString(); | - | ||||||||||||||||||||||||
| 2709 | if (query.isEmpty())
| 0 | ||||||||||||||||||||||||
| 2710 | d->sectionIsPresent &= ~QUrlPrivate::Query; never executed: d->sectionIsPresent &= ~QUrlPrivate::Query; | 0 | ||||||||||||||||||||||||
| 2711 | else | - | ||||||||||||||||||||||||
| 2712 | d->sectionIsPresent |= QUrlPrivate::Query; never executed: d->sectionIsPresent |= QUrlPrivate::Query; | 0 | ||||||||||||||||||||||||
| 2713 | } | - | ||||||||||||||||||||||||
| 2714 | - | |||||||||||||||||||||||||
| 2715 | /*! | - | ||||||||||||||||||||||||
| 2716 | \fn void QUrl::setQueryItems(const QList<QPair<QString, QString> > &query) | - | ||||||||||||||||||||||||
| 2717 | \deprecated | - | ||||||||||||||||||||||||
| 2718 | - | |||||||||||||||||||||||||
| 2719 | Sets the query string of the URL to an encoded version of \a | - | ||||||||||||||||||||||||
| 2720 | query. The contents of \a query are converted to a string | - | ||||||||||||||||||||||||
| 2721 | internally, each pair delimited by the character returned by | - | ||||||||||||||||||||||||
| 2722 | \l {QUrlQuery::queryPairDelimiter()}{queryPairDelimiter()}, and the key and value are delimited by | - | ||||||||||||||||||||||||
| 2723 | \l {QUrlQuery::queryValueDelimiter()}{queryValueDelimiter()} | - | ||||||||||||||||||||||||
| 2724 | - | |||||||||||||||||||||||||
| 2725 | \note This method does not encode spaces (ASCII 0x20) as plus (+) signs, | - | ||||||||||||||||||||||||
| 2726 | like HTML forms do. If you need that kind of encoding, you must encode | - | ||||||||||||||||||||||||
| 2727 | the value yourself and use QUrl::setEncodedQueryItems. | - | ||||||||||||||||||||||||
| 2728 | - | |||||||||||||||||||||||||
| 2729 | \obsolete Use QUrlQuery and setQuery(). | - | ||||||||||||||||||||||||
| 2730 | - | |||||||||||||||||||||||||
| 2731 | \sa queryItems(), setEncodedQueryItems() | - | ||||||||||||||||||||||||
| 2732 | */ | - | ||||||||||||||||||||||||
| 2733 | - | |||||||||||||||||||||||||
| 2734 | /*! | - | ||||||||||||||||||||||||
| 2735 | \fn void QUrl::setEncodedQueryItems(const QList<QPair<QByteArray, QByteArray> > &query) | - | ||||||||||||||||||||||||
| 2736 | \deprecated | - | ||||||||||||||||||||||||
| 2737 | \since 4.4 | - | ||||||||||||||||||||||||
| 2738 | - | |||||||||||||||||||||||||
| 2739 | Sets the query string of the URL to the encoded version of \a | - | ||||||||||||||||||||||||
| 2740 | query. The contents of \a query are converted to a string | - | ||||||||||||||||||||||||
| 2741 | internally, each pair delimited by the character returned by | - | ||||||||||||||||||||||||
| 2742 | \l {QUrlQuery::queryPairDelimiter()}{queryPairDelimiter()}, and the key and value are delimited by | - | ||||||||||||||||||||||||
| 2743 | \l {QUrlQuery::queryValueDelimiter()}{queryValueDelimiter()}. | - | ||||||||||||||||||||||||
| 2744 | - | |||||||||||||||||||||||||
| 2745 | \obsolete Use QUrlQuery and setQuery(). | - | ||||||||||||||||||||||||
| 2746 | - | |||||||||||||||||||||||||
| 2747 | \sa encodedQueryItems(), setQueryItems() | - | ||||||||||||||||||||||||
| 2748 | */ | - | ||||||||||||||||||||||||
| 2749 | - | |||||||||||||||||||||||||
| 2750 | /*! | - | ||||||||||||||||||||||||
| 2751 | \fn void QUrl::addQueryItem(const QString &key, const QString &value) | - | ||||||||||||||||||||||||
| 2752 | \deprecated | - | ||||||||||||||||||||||||
| 2753 | - | |||||||||||||||||||||||||
| 2754 | Inserts the pair \a key = \a value into the query string of the | - | ||||||||||||||||||||||||
| 2755 | URL. | - | ||||||||||||||||||||||||
| 2756 | - | |||||||||||||||||||||||||
| 2757 | The key-value pair is encoded before it is added to the query. The | - | ||||||||||||||||||||||||
| 2758 | pair is converted into separate strings internally. The \a key and | - | ||||||||||||||||||||||||
| 2759 | \a value is first encoded into UTF-8 and then delimited by the | - | ||||||||||||||||||||||||
| 2760 | character returned by \l {QUrlQuery::queryValueDelimiter()}{queryValueDelimiter()}. | - | ||||||||||||||||||||||||
| 2761 | Each key-value pair is delimited by the character returned by | - | ||||||||||||||||||||||||
| 2762 | \l {QUrlQuery::queryPairDelimiter()}{queryPairDelimiter()} | - | ||||||||||||||||||||||||
| 2763 | - | |||||||||||||||||||||||||
| 2764 | \note This method does not encode spaces (ASCII 0x20) as plus (+) signs, | - | ||||||||||||||||||||||||
| 2765 | like HTML forms do. If you need that kind of encoding, you must encode | - | ||||||||||||||||||||||||
| 2766 | the value yourself and use QUrl::addEncodedQueryItem. | - | ||||||||||||||||||||||||
| 2767 | - | |||||||||||||||||||||||||
| 2768 | \obsolete Use QUrlQuery and setQuery(). | - | ||||||||||||||||||||||||
| 2769 | - | |||||||||||||||||||||||||
| 2770 | \sa addEncodedQueryItem() | - | ||||||||||||||||||||||||
| 2771 | */ | - | ||||||||||||||||||||||||
| 2772 | - | |||||||||||||||||||||||||
| 2773 | /*! | - | ||||||||||||||||||||||||
| 2774 | \fn void QUrl::addEncodedQueryItem(const QByteArray &key, const QByteArray &value) | - | ||||||||||||||||||||||||
| 2775 | \deprecated | - | ||||||||||||||||||||||||
| 2776 | \since 4.4 | - | ||||||||||||||||||||||||
| 2777 | - | |||||||||||||||||||||||||
| 2778 | Inserts the pair \a key = \a value into the query string of the | - | ||||||||||||||||||||||||
| 2779 | URL. | - | ||||||||||||||||||||||||
| 2780 | - | |||||||||||||||||||||||||
| 2781 | \obsolete Use QUrlQuery and setQuery(). | - | ||||||||||||||||||||||||
| 2782 | - | |||||||||||||||||||||||||
| 2783 | \sa addQueryItem() | - | ||||||||||||||||||||||||
| 2784 | */ | - | ||||||||||||||||||||||||
| 2785 | - | |||||||||||||||||||||||||
| 2786 | /*! | - | ||||||||||||||||||||||||
| 2787 | \fn QList<QPair<QString, QString> > QUrl::queryItems() const | - | ||||||||||||||||||||||||
| 2788 | \deprecated | - | ||||||||||||||||||||||||
| 2789 | - | |||||||||||||||||||||||||
| 2790 | Returns the query string of the URL, as a map of keys and values. | - | ||||||||||||||||||||||||
| 2791 | - | |||||||||||||||||||||||||
| 2792 | \note This method does not decode spaces plus (+) signs as spaces (ASCII | - | ||||||||||||||||||||||||
| 2793 | 0x20), like HTML forms do. If you need that kind of decoding, you must | - | ||||||||||||||||||||||||
| 2794 | use QUrl::encodedQueryItems and decode the data yourself. | - | ||||||||||||||||||||||||
| 2795 | - | |||||||||||||||||||||||||
| 2796 | \obsolete Use QUrlQuery. | - | ||||||||||||||||||||||||
| 2797 | - | |||||||||||||||||||||||||
| 2798 | \sa setQueryItems(), setEncodedQuery() | - | ||||||||||||||||||||||||
| 2799 | */ | - | ||||||||||||||||||||||||
| 2800 | - | |||||||||||||||||||||||||
| 2801 | /*! | - | ||||||||||||||||||||||||
| 2802 | \fn QList<QPair<QByteArray, QByteArray> > QUrl::encodedQueryItems() const | - | ||||||||||||||||||||||||
| 2803 | \deprecated | - | ||||||||||||||||||||||||
| 2804 | \since 4.4 | - | ||||||||||||||||||||||||
| 2805 | - | |||||||||||||||||||||||||
| 2806 | Returns the query string of the URL, as a map of encoded keys and values. | - | ||||||||||||||||||||||||
| 2807 | - | |||||||||||||||||||||||||
| 2808 | \obsolete Use QUrlQuery. | - | ||||||||||||||||||||||||
| 2809 | - | |||||||||||||||||||||||||
| 2810 | \sa setEncodedQueryItems(), setQueryItems(), setEncodedQuery() | - | ||||||||||||||||||||||||
| 2811 | */ | - | ||||||||||||||||||||||||
| 2812 | - | |||||||||||||||||||||||||
| 2813 | /*! | - | ||||||||||||||||||||||||
| 2814 | \fn bool QUrl::hasQueryItem(const QString &key) const | - | ||||||||||||||||||||||||
| 2815 | \deprecated | - | ||||||||||||||||||||||||
| 2816 | - | |||||||||||||||||||||||||
| 2817 | Returns \c true if there is a query string pair whose key is equal | - | ||||||||||||||||||||||||
| 2818 | to \a key from the URL. | - | ||||||||||||||||||||||||
| 2819 | - | |||||||||||||||||||||||||
| 2820 | \obsolete Use QUrlQuery. | - | ||||||||||||||||||||||||
| 2821 | - | |||||||||||||||||||||||||
| 2822 | \sa hasEncodedQueryItem() | - | ||||||||||||||||||||||||
| 2823 | */ | - | ||||||||||||||||||||||||
| 2824 | - | |||||||||||||||||||||||||
| 2825 | /*! | - | ||||||||||||||||||||||||
| 2826 | \fn bool QUrl::hasEncodedQueryItem(const QByteArray &key) const | - | ||||||||||||||||||||||||
| 2827 | \deprecated | - | ||||||||||||||||||||||||
| 2828 | \since 4.4 | - | ||||||||||||||||||||||||
| 2829 | - | |||||||||||||||||||||||||
| 2830 | Returns \c true if there is a query string pair whose key is equal | - | ||||||||||||||||||||||||
| 2831 | to \a key from the URL. | - | ||||||||||||||||||||||||
| 2832 | - | |||||||||||||||||||||||||
| 2833 | \obsolete Use QUrlQuery. | - | ||||||||||||||||||||||||
| 2834 | - | |||||||||||||||||||||||||
| 2835 | \sa hasQueryItem() | - | ||||||||||||||||||||||||
| 2836 | */ | - | ||||||||||||||||||||||||
| 2837 | - | |||||||||||||||||||||||||
| 2838 | /*! | - | ||||||||||||||||||||||||
| 2839 | \fn QString QUrl::queryItemValue(const QString &key) const | - | ||||||||||||||||||||||||
| 2840 | \deprecated | - | ||||||||||||||||||||||||
| 2841 | - | |||||||||||||||||||||||||
| 2842 | Returns the first query string value whose key is equal to \a key | - | ||||||||||||||||||||||||
| 2843 | from the URL. | - | ||||||||||||||||||||||||
| 2844 | - | |||||||||||||||||||||||||
| 2845 | \note This method does not decode spaces plus (+) signs as spaces (ASCII | - | ||||||||||||||||||||||||
| 2846 | 0x20), like HTML forms do. If you need that kind of decoding, you must | - | ||||||||||||||||||||||||
| 2847 | use QUrl::encodedQueryItemValue and decode the data yourself. | - | ||||||||||||||||||||||||
| 2848 | - | |||||||||||||||||||||||||
| 2849 | \obsolete Use QUrlQuery. | - | ||||||||||||||||||||||||
| 2850 | - | |||||||||||||||||||||||||
| 2851 | \sa allQueryItemValues() | - | ||||||||||||||||||||||||
| 2852 | */ | - | ||||||||||||||||||||||||
| 2853 | - | |||||||||||||||||||||||||
| 2854 | /*! | - | ||||||||||||||||||||||||
| 2855 | \fn QByteArray QUrl::encodedQueryItemValue(const QByteArray &key) const | - | ||||||||||||||||||||||||
| 2856 | \deprecated | - | ||||||||||||||||||||||||
| 2857 | \since 4.4 | - | ||||||||||||||||||||||||
| 2858 | - | |||||||||||||||||||||||||
| 2859 | Returns the first query string value whose key is equal to \a key | - | ||||||||||||||||||||||||
| 2860 | from the URL. | - | ||||||||||||||||||||||||
| 2861 | - | |||||||||||||||||||||||||
| 2862 | \obsolete Use QUrlQuery. | - | ||||||||||||||||||||||||
| 2863 | - | |||||||||||||||||||||||||
| 2864 | \sa queryItemValue(), allQueryItemValues() | - | ||||||||||||||||||||||||
| 2865 | */ | - | ||||||||||||||||||||||||
| 2866 | - | |||||||||||||||||||||||||
| 2867 | /*! | - | ||||||||||||||||||||||||
| 2868 | \fn QStringList QUrl::allQueryItemValues(const QString &key) const | - | ||||||||||||||||||||||||
| 2869 | \deprecated | - | ||||||||||||||||||||||||
| 2870 | - | |||||||||||||||||||||||||
| 2871 | Returns the a list of query string values whose key is equal to | - | ||||||||||||||||||||||||
| 2872 | \a key from the URL. | - | ||||||||||||||||||||||||
| 2873 | - | |||||||||||||||||||||||||
| 2874 | \note This method does not decode spaces plus (+) signs as spaces (ASCII | - | ||||||||||||||||||||||||
| 2875 | 0x20), like HTML forms do. If you need that kind of decoding, you must | - | ||||||||||||||||||||||||
| 2876 | use QUrl::allEncodedQueryItemValues and decode the data yourself. | - | ||||||||||||||||||||||||
| 2877 | - | |||||||||||||||||||||||||
| 2878 | \obsolete Use QUrlQuery. | - | ||||||||||||||||||||||||
| 2879 | - | |||||||||||||||||||||||||
| 2880 | \sa queryItemValue() | - | ||||||||||||||||||||||||
| 2881 | */ | - | ||||||||||||||||||||||||
| 2882 | - | |||||||||||||||||||||||||
| 2883 | /*! | - | ||||||||||||||||||||||||
| 2884 | \fn QList<QByteArray> QUrl::allEncodedQueryItemValues(const QByteArray &key) const | - | ||||||||||||||||||||||||
| 2885 | \deprecated | - | ||||||||||||||||||||||||
| 2886 | \since 4.4 | - | ||||||||||||||||||||||||
| 2887 | - | |||||||||||||||||||||||||
| 2888 | Returns the a list of query string values whose key is equal to | - | ||||||||||||||||||||||||
| 2889 | \a key from the URL. | - | ||||||||||||||||||||||||
| 2890 | - | |||||||||||||||||||||||||
| 2891 | \obsolete Use QUrlQuery. | - | ||||||||||||||||||||||||
| 2892 | - | |||||||||||||||||||||||||
| 2893 | \sa allQueryItemValues(), queryItemValue(), encodedQueryItemValue() | - | ||||||||||||||||||||||||
| 2894 | */ | - | ||||||||||||||||||||||||
| 2895 | - | |||||||||||||||||||||||||
| 2896 | /*! | - | ||||||||||||||||||||||||
| 2897 | \fn void QUrl::removeQueryItem(const QString &key) | - | ||||||||||||||||||||||||
| 2898 | \deprecated | - | ||||||||||||||||||||||||
| 2899 | - | |||||||||||||||||||||||||
| 2900 | Removes the first query string pair whose key is equal to \a key | - | ||||||||||||||||||||||||
| 2901 | from the URL. | - | ||||||||||||||||||||||||
| 2902 | - | |||||||||||||||||||||||||
| 2903 | \obsolete Use QUrlQuery. | - | ||||||||||||||||||||||||
| 2904 | - | |||||||||||||||||||||||||
| 2905 | \sa removeAllQueryItems() | - | ||||||||||||||||||||||||
| 2906 | */ | - | ||||||||||||||||||||||||
| 2907 | - | |||||||||||||||||||||||||
| 2908 | /*! | - | ||||||||||||||||||||||||
| 2909 | \fn void QUrl::removeEncodedQueryItem(const QByteArray &key) | - | ||||||||||||||||||||||||
| 2910 | \deprecated | - | ||||||||||||||||||||||||
| 2911 | \since 4.4 | - | ||||||||||||||||||||||||
| 2912 | - | |||||||||||||||||||||||||
| 2913 | Removes the first query string pair whose key is equal to \a key | - | ||||||||||||||||||||||||
| 2914 | from the URL. | - | ||||||||||||||||||||||||
| 2915 | - | |||||||||||||||||||||||||
| 2916 | \obsolete Use QUrlQuery. | - | ||||||||||||||||||||||||
| 2917 | - | |||||||||||||||||||||||||
| 2918 | \sa removeQueryItem(), removeAllQueryItems() | - | ||||||||||||||||||||||||
| 2919 | */ | - | ||||||||||||||||||||||||
| 2920 | - | |||||||||||||||||||||||||
| 2921 | /*! | - | ||||||||||||||||||||||||
| 2922 | \fn void QUrl::removeAllQueryItems(const QString &key) | - | ||||||||||||||||||||||||
| 2923 | \deprecated | - | ||||||||||||||||||||||||
| 2924 | - | |||||||||||||||||||||||||
| 2925 | Removes all the query string pairs whose key is equal to \a key | - | ||||||||||||||||||||||||
| 2926 | from the URL. | - | ||||||||||||||||||||||||
| 2927 | - | |||||||||||||||||||||||||
| 2928 | \obsolete Use QUrlQuery. | - | ||||||||||||||||||||||||
| 2929 | - | |||||||||||||||||||||||||
| 2930 | \sa removeQueryItem() | - | ||||||||||||||||||||||||
| 2931 | */ | - | ||||||||||||||||||||||||
| 2932 | - | |||||||||||||||||||||||||
| 2933 | /*! | - | ||||||||||||||||||||||||
| 2934 | \fn void QUrl::removeAllEncodedQueryItems(const QByteArray &key) | - | ||||||||||||||||||||||||
| 2935 | \deprecated | - | ||||||||||||||||||||||||
| 2936 | \since 4.4 | - | ||||||||||||||||||||||||
| 2937 | - | |||||||||||||||||||||||||
| 2938 | Removes all the query string pairs whose key is equal to \a key | - | ||||||||||||||||||||||||
| 2939 | from the URL. | - | ||||||||||||||||||||||||
| 2940 | - | |||||||||||||||||||||||||
| 2941 | \obsolete Use QUrlQuery. | - | ||||||||||||||||||||||||
| 2942 | - | |||||||||||||||||||||||||
| 2943 | \sa removeQueryItem() | - | ||||||||||||||||||||||||
| 2944 | */ | - | ||||||||||||||||||||||||
| 2945 | - | |||||||||||||||||||||||||
| 2946 | /*! | - | ||||||||||||||||||||||||
| 2947 | \fn QByteArray QUrl::encodedQuery() const | - | ||||||||||||||||||||||||
| 2948 | \deprecated | - | ||||||||||||||||||||||||
| 2949 | - | |||||||||||||||||||||||||
| 2950 | Returns the query string of the URL in percent encoded form. | - | ||||||||||||||||||||||||
| 2951 | - | |||||||||||||||||||||||||
| 2952 | \obsolete Use query(QUrl::FullyEncoded).toLatin1() | - | ||||||||||||||||||||||||
| 2953 | - | |||||||||||||||||||||||||
| 2954 | \sa setEncodedQuery(), query() | - | ||||||||||||||||||||||||
| 2955 | */ | - | ||||||||||||||||||||||||
| 2956 | - | |||||||||||||||||||||||||
| 2957 | /*! | - | ||||||||||||||||||||||||
| 2958 | Returns the query string of the URL if there's a query string, or an empty | - | ||||||||||||||||||||||||
| 2959 | result if not. To determine if the parsed URL contained a query string, use | - | ||||||||||||||||||||||||
| 2960 | hasQuery(). | - | ||||||||||||||||||||||||
| 2961 | - | |||||||||||||||||||||||||
| 2962 | The \a options argument controls how to format the query component. All | - | ||||||||||||||||||||||||
| 2963 | values produce an unambiguous result. With QUrl::FullyDecoded, all | - | ||||||||||||||||||||||||
| 2964 | percent-encoded sequences are decoded; otherwise, the returned value may | - | ||||||||||||||||||||||||
| 2965 | contain some percent-encoded sequences for some control sequences not | - | ||||||||||||||||||||||||
| 2966 | representable in decoded form in QString. | - | ||||||||||||||||||||||||
| 2967 | - | |||||||||||||||||||||||||
| 2968 | Note that use of QUrl::FullyDecoded in queries is discouraged, as queries | - | ||||||||||||||||||||||||
| 2969 | often contain data that is supposed to remain percent-encoded, including | - | ||||||||||||||||||||||||
| 2970 | the use of the "%2B" sequence to represent a plus character ('+'). | - | ||||||||||||||||||||||||
| 2971 | - | |||||||||||||||||||||||||
| 2972 | \sa setQuery(), hasQuery() | - | ||||||||||||||||||||||||
| 2973 | */ | - | ||||||||||||||||||||||||
| 2974 | QString QUrl::query(ComponentFormattingOptions options) const | - | ||||||||||||||||||||||||
| 2975 | { | - | ||||||||||||||||||||||||
| 2976 | if (!d) return QString(); executed 2 times by 1 test: return QString();Executed by:
| 2-189 | ||||||||||||||||||||||||
| 2977 | - | |||||||||||||||||||||||||
| 2978 | QString result; | - | ||||||||||||||||||||||||
| 2979 | d->appendQuery(result, options, QUrlPrivate::Query); | - | ||||||||||||||||||||||||
| 2980 | if (d->hasQuery() && result.isNull())
| 2-166 | ||||||||||||||||||||||||
| 2981 | result.detach(); executed 2 times by 1 test: result.detach();Executed by:
| 2 | ||||||||||||||||||||||||
| 2982 | return result; executed 189 times by 3 tests: return result;Executed by:
| 189 | ||||||||||||||||||||||||
| 2983 | } | - | ||||||||||||||||||||||||
| 2984 | - | |||||||||||||||||||||||||
| 2985 | /*! | - | ||||||||||||||||||||||||
| 2986 | Sets the fragment of the URL to \a fragment. The fragment is the | - | ||||||||||||||||||||||||
| 2987 | last part of the URL, represented by a '#' followed by a string of | - | ||||||||||||||||||||||||
| 2988 | characters. It is typically used in HTTP for referring to a | - | ||||||||||||||||||||||||
| 2989 | certain link or point on a page: | - | ||||||||||||||||||||||||
| 2990 | - | |||||||||||||||||||||||||
| 2991 | \image qurl-fragment.png | - | ||||||||||||||||||||||||
| 2992 | - | |||||||||||||||||||||||||
| 2993 | The fragment is sometimes also referred to as the URL "reference". | - | ||||||||||||||||||||||||
| 2994 | - | |||||||||||||||||||||||||
| 2995 | Passing an argument of QString() (a null QString) will unset the fragment. | - | ||||||||||||||||||||||||
| 2996 | Passing an argument of QString("") (an empty but not null QString) will set the | - | ||||||||||||||||||||||||
| 2997 | fragment to an empty string (as if the original URL had a lone "#"). | - | ||||||||||||||||||||||||
| 2998 | - | |||||||||||||||||||||||||
| 2999 | The \a fragment data is interpreted according to \a mode: in StrictMode, | - | ||||||||||||||||||||||||
| 3000 | any '%' characters must be followed by exactly two hexadecimal characters | - | ||||||||||||||||||||||||
| 3001 | and some characters (including space) are not allowed in undecoded form. In | - | ||||||||||||||||||||||||
| 3002 | TolerantMode, all characters are accepted in undecoded form and the | - | ||||||||||||||||||||||||
| 3003 | tolerant parser will correct stray '%' not followed by two hex characters. | - | ||||||||||||||||||||||||
| 3004 | In DecodedMode, '%' stand for themselves and encoded characters are not | - | ||||||||||||||||||||||||
| 3005 | possible. | - | ||||||||||||||||||||||||
| 3006 | - | |||||||||||||||||||||||||
| 3007 | QUrl::DecodedMode should be used when setting the fragment from a data | - | ||||||||||||||||||||||||
| 3008 | source which is not a URL or with a fragment obtained by calling | - | ||||||||||||||||||||||||
| 3009 | fragment() with the QUrl::FullyDecoded formatting option. | - | ||||||||||||||||||||||||
| 3010 | - | |||||||||||||||||||||||||
| 3011 | \sa fragment(), hasFragment() | - | ||||||||||||||||||||||||
| 3012 | */ | - | ||||||||||||||||||||||||
| 3013 | void QUrl::setFragment(const QString &fragment, ParsingMode mode) | - | ||||||||||||||||||||||||
| 3014 | { | - | ||||||||||||||||||||||||
| 3015 | detach(); | - | ||||||||||||||||||||||||
| 3016 | d->clearError(); | - | ||||||||||||||||||||||||
| 3017 | - | |||||||||||||||||||||||||
| 3018 | QString data = fragment; | - | ||||||||||||||||||||||||
| 3019 | if (mode == DecodedMode) {
| 1-1695 | ||||||||||||||||||||||||
| 3020 | parseDecodedComponent(data); | - | ||||||||||||||||||||||||
| 3021 | mode = TolerantMode; | - | ||||||||||||||||||||||||
| 3022 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||
| 3023 | - | |||||||||||||||||||||||||
| 3024 | d->setFragment(data, 0, data.length()); | - | ||||||||||||||||||||||||
| 3025 | if (fragment.isNull())
| 667-1029 | ||||||||||||||||||||||||
| 3026 | d->sectionIsPresent &= ~QUrlPrivate::Fragment; executed 1029 times by 8 tests: d->sectionIsPresent &= ~QUrlPrivate::Fragment;Executed by:
| 1029 | ||||||||||||||||||||||||
| 3027 | else if (mode == StrictMode && !d->validateComponent(QUrlPrivate::Fragment, fragment))
| 0-665 | ||||||||||||||||||||||||
| 3028 | d->fragment.clear(); executed 2 times by 1 test: d->fragment.clear();Executed by:
| 2 | ||||||||||||||||||||||||
| 3029 | } executed 1696 times by 8 tests: end of blockExecuted by:
| 1696 | ||||||||||||||||||||||||
| 3030 | - | |||||||||||||||||||||||||
| 3031 | /*! | - | ||||||||||||||||||||||||
| 3032 | Returns the fragment of the URL. To determine if the parsed URL contained a | - | ||||||||||||||||||||||||
| 3033 | fragment, use hasFragment(). | - | ||||||||||||||||||||||||
| 3034 | - | |||||||||||||||||||||||||
| 3035 | The \a options argument controls how to format the fragment component. All | - | ||||||||||||||||||||||||
| 3036 | values produce an unambiguous result. With QUrl::FullyDecoded, all | - | ||||||||||||||||||||||||
| 3037 | percent-encoded sequences are decoded; otherwise, the returned value may | - | ||||||||||||||||||||||||
| 3038 | contain some percent-encoded sequences for some control sequences not | - | ||||||||||||||||||||||||
| 3039 | representable in decoded form in QString. | - | ||||||||||||||||||||||||
| 3040 | - | |||||||||||||||||||||||||
| 3041 | Note that QUrl::FullyDecoded may cause data loss if those non-representable | - | ||||||||||||||||||||||||
| 3042 | sequences are present. It is recommended to use that value when the result | - | ||||||||||||||||||||||||
| 3043 | will be used in a non-URL context. | - | ||||||||||||||||||||||||
| 3044 | - | |||||||||||||||||||||||||
| 3045 | \sa setFragment(), hasFragment() | - | ||||||||||||||||||||||||
| 3046 | */ | - | ||||||||||||||||||||||||
| 3047 | QString QUrl::fragment(ComponentFormattingOptions options) const | - | ||||||||||||||||||||||||
| 3048 | { | - | ||||||||||||||||||||||||
| 3049 | if (!d) return QString(); executed 2 times by 1 test: return QString();Executed by:
| 2-128 | ||||||||||||||||||||||||
| 3050 | - | |||||||||||||||||||||||||
| 3051 | QString result; | - | ||||||||||||||||||||||||
| 3052 | d->appendFragment(result, options, QUrlPrivate::Fragment); | - | ||||||||||||||||||||||||
| 3053 | if (d->hasFragment() && result.isNull())
| 2-69 | ||||||||||||||||||||||||
| 3054 | result.detach(); executed 2 times by 1 test: result.detach();Executed by:
| 2 | ||||||||||||||||||||||||
| 3055 | return result; executed 128 times by 2 tests: return result;Executed by:
| 128 | ||||||||||||||||||||||||
| 3056 | } | - | ||||||||||||||||||||||||
| 3057 | - | |||||||||||||||||||||||||
| 3058 | /*! | - | ||||||||||||||||||||||||
| 3059 | \fn void QUrl::setEncodedFragment(const QByteArray &fragment) | - | ||||||||||||||||||||||||
| 3060 | \deprecated | - | ||||||||||||||||||||||||
| 3061 | \since 4.4 | - | ||||||||||||||||||||||||
| 3062 | - | |||||||||||||||||||||||||
| 3063 | Sets the URL's fragment to the percent-encoded \a fragment. The fragment is the | - | ||||||||||||||||||||||||
| 3064 | last part of the URL, represented by a '#' followed by a string of | - | ||||||||||||||||||||||||
| 3065 | characters. It is typically used in HTTP for referring to a | - | ||||||||||||||||||||||||
| 3066 | certain link or point on a page: | - | ||||||||||||||||||||||||
| 3067 | - | |||||||||||||||||||||||||
| 3068 | \image qurl-fragment.png | - | ||||||||||||||||||||||||
| 3069 | - | |||||||||||||||||||||||||
| 3070 | The fragment is sometimes also referred to as the URL "reference". | - | ||||||||||||||||||||||||
| 3071 | - | |||||||||||||||||||||||||
| 3072 | Passing an argument of QByteArray() (a null QByteArray) will unset the fragment. | - | ||||||||||||||||||||||||
| 3073 | Passing an argument of QByteArray("") (an empty but not null QByteArray) | - | ||||||||||||||||||||||||
| 3074 | will set the fragment to an empty string (as if the original URL | - | ||||||||||||||||||||||||
| 3075 | had a lone "#"). | - | ||||||||||||||||||||||||
| 3076 | - | |||||||||||||||||||||||||
| 3077 | \obsolete Use setFragment(), which has the same behavior of null / empty. | - | ||||||||||||||||||||||||
| 3078 | - | |||||||||||||||||||||||||
| 3079 | \sa setFragment(), encodedFragment() | - | ||||||||||||||||||||||||
| 3080 | */ | - | ||||||||||||||||||||||||
| 3081 | - | |||||||||||||||||||||||||
| 3082 | /*! | - | ||||||||||||||||||||||||
| 3083 | \fn QByteArray QUrl::encodedFragment() const | - | ||||||||||||||||||||||||
| 3084 | \deprecated | - | ||||||||||||||||||||||||
| 3085 | \since 4.4 | - | ||||||||||||||||||||||||
| 3086 | - | |||||||||||||||||||||||||
| 3087 | Returns the fragment of the URL if it is defined; otherwise an | - | ||||||||||||||||||||||||
| 3088 | empty string is returned. The returned value will have its | - | ||||||||||||||||||||||||
| 3089 | non-ASCII and other control characters percent-encoded, as in | - | ||||||||||||||||||||||||
| 3090 | toEncoded(). | - | ||||||||||||||||||||||||
| 3091 | - | |||||||||||||||||||||||||
| 3092 | \obsolete Use query(QUrl::FullyEncoded).toLatin1(). | - | ||||||||||||||||||||||||
| 3093 | - | |||||||||||||||||||||||||
| 3094 | \sa setEncodedFragment(), toEncoded() | - | ||||||||||||||||||||||||
| 3095 | */ | - | ||||||||||||||||||||||||
| 3096 | - | |||||||||||||||||||||||||
| 3097 | /*! | - | ||||||||||||||||||||||||
| 3098 | \since 4.2 | - | ||||||||||||||||||||||||
| 3099 | - | |||||||||||||||||||||||||
| 3100 | Returns \c true if this URL contains a fragment (i.e., if # was seen on it). | - | ||||||||||||||||||||||||
| 3101 | - | |||||||||||||||||||||||||
| 3102 | \sa fragment(), setFragment() | - | ||||||||||||||||||||||||
| 3103 | */ | - | ||||||||||||||||||||||||
| 3104 | bool QUrl::hasFragment() const | - | ||||||||||||||||||||||||
| 3105 | { | - | ||||||||||||||||||||||||
| 3106 | if (!d) return false; never executed: return false;
| 0-137 | ||||||||||||||||||||||||
| 3107 | return d->hasFragment(); executed 137 times by 6 tests: return d->hasFragment();Executed by:
| 137 | ||||||||||||||||||||||||
| 3108 | } | - | ||||||||||||||||||||||||
| 3109 | - | |||||||||||||||||||||||||
| 3110 | /*! | - | ||||||||||||||||||||||||
| 3111 | \since 4.8 | - | ||||||||||||||||||||||||
| 3112 | - | |||||||||||||||||||||||||
| 3113 | Returns the TLD (Top-Level Domain) of the URL, (e.g. .co.uk, .net). | - | ||||||||||||||||||||||||
| 3114 | Note that the return value is prefixed with a '.' unless the | - | ||||||||||||||||||||||||
| 3115 | URL does not contain a valid TLD, in which case the function returns | - | ||||||||||||||||||||||||
| 3116 | an empty string. | - | ||||||||||||||||||||||||
| 3117 | - | |||||||||||||||||||||||||
| 3118 | Note that this function considers a TLD to be any domain that allows users | - | ||||||||||||||||||||||||
| 3119 | to register subdomains under, including many home, dynamic DNS websites and | - | ||||||||||||||||||||||||
| 3120 | blogging providers. This is useful for determining whether two websites | - | ||||||||||||||||||||||||
| 3121 | belong to the same infrastructure and communication should be allowed, such | - | ||||||||||||||||||||||||
| 3122 | as browser cookies: two domains should be considered part of the same | - | ||||||||||||||||||||||||
| 3123 | website if they share at least one label in addition to the value | - | ||||||||||||||||||||||||
| 3124 | returned by this function. | - | ||||||||||||||||||||||||
| 3125 | - | |||||||||||||||||||||||||
| 3126 | \list | - | ||||||||||||||||||||||||
| 3127 | \li \c{foo.co.uk} and \c{foo.com} do not share a top-level domain | - | ||||||||||||||||||||||||
| 3128 | \li \c{foo.co.uk} and \c{bar.co.uk} share the \c{.co.uk} domain, but the next label is different | - | ||||||||||||||||||||||||
| 3129 | \li \c{www.foo.co.uk} and \c{ftp.foo.co.uk} share the same top-level domain and one more label, | - | ||||||||||||||||||||||||
| 3130 | so they are considered part of the same site | - | ||||||||||||||||||||||||
| 3131 | \endlist | - | ||||||||||||||||||||||||
| 3132 | - | |||||||||||||||||||||||||
| 3133 | If \a options includes EncodeUnicode, the returned string will be in | - | ||||||||||||||||||||||||
| 3134 | ASCII Compatible Encoding. | - | ||||||||||||||||||||||||
| 3135 | */ | - | ||||||||||||||||||||||||
| 3136 | QString QUrl::topLevelDomain(ComponentFormattingOptions options) const | - | ||||||||||||||||||||||||
| 3137 | { | - | ||||||||||||||||||||||||
| 3138 | QString tld = qTopLevelDomain(host()); | - | ||||||||||||||||||||||||
| 3139 | if (options & EncodeUnicode) {
| 18 | ||||||||||||||||||||||||
| 3140 | return qt_ACE_do(tld, ToAceOnly, AllowLeadingDot); executed 18 times by 1 test: return qt_ACE_do(tld, ToAceOnly, AllowLeadingDot);Executed by:
| 18 | ||||||||||||||||||||||||
| 3141 | } | - | ||||||||||||||||||||||||
| 3142 | return tld; executed 18 times by 1 test: return tld;Executed by:
| 18 | ||||||||||||||||||||||||
| 3143 | } | - | ||||||||||||||||||||||||
| 3144 | - | |||||||||||||||||||||||||
| 3145 | /*! | - | ||||||||||||||||||||||||
| 3146 | Returns the result of the merge of this URL with \a relative. This | - | ||||||||||||||||||||||||
| 3147 | URL is used as a base to convert \a relative to an absolute URL. | - | ||||||||||||||||||||||||
| 3148 | - | |||||||||||||||||||||||||
| 3149 | If \a relative is not a relative URL, this function will return \a | - | ||||||||||||||||||||||||
| 3150 | relative directly. Otherwise, the paths of the two URLs are | - | ||||||||||||||||||||||||
| 3151 | merged, and the new URL returned has the scheme and authority of | - | ||||||||||||||||||||||||
| 3152 | the base URL, but with the merged path, as in the following | - | ||||||||||||||||||||||||
| 3153 | example: | - | ||||||||||||||||||||||||
| 3154 | - | |||||||||||||||||||||||||
| 3155 | \snippet code/src_corelib_io_qurl.cpp 5 | - | ||||||||||||||||||||||||
| 3156 | - | |||||||||||||||||||||||||
| 3157 | Calling resolved() with ".." returns a QUrl whose directory is | - | ||||||||||||||||||||||||
| 3158 | one level higher than the original. Similarly, calling resolved() | - | ||||||||||||||||||||||||
| 3159 | with "../.." removes two levels from the path. If \a relative is | - | ||||||||||||||||||||||||
| 3160 | "/", the path becomes "/". | - | ||||||||||||||||||||||||
| 3161 | - | |||||||||||||||||||||||||
| 3162 | \sa isRelative() | - | ||||||||||||||||||||||||
| 3163 | */ | - | ||||||||||||||||||||||||
| 3164 | QUrl QUrl::resolved(const QUrl &relative) const | - | ||||||||||||||||||||||||
| 3165 | { | - | ||||||||||||||||||||||||
| 3166 | if (!d) return relative; executed 150 times by 7 tests: return relative;Executed by:
| 150-4486 | ||||||||||||||||||||||||
| 3167 | if (!relative.d) return *this; never executed: return *this;
| 0-4486 | ||||||||||||||||||||||||
| 3168 | - | |||||||||||||||||||||||||
| 3169 | QUrl t; | - | ||||||||||||||||||||||||
| 3170 | // Compatibility hack (mostly for qtdeclarative) : treat "file:relative.txt" as relative even though QUrl::isRelative() says false | - | ||||||||||||||||||||||||
| 3171 | if (!relative.d->scheme.isEmpty() && (!relative.isLocalFile() || QDir::isAbsolutePath(relative.d->path))) {
| 10-3402 | ||||||||||||||||||||||||
| 3172 | t = relative; | - | ||||||||||||||||||||||||
| 3173 | t.detach(); | - | ||||||||||||||||||||||||
| 3174 | } else { executed 1063 times by 3 tests: end of blockExecuted by:
| 1063 | ||||||||||||||||||||||||
| 3175 | if (relative.d->hasAuthority()) {
| 2-3421 | ||||||||||||||||||||||||
| 3176 | t = relative; | - | ||||||||||||||||||||||||
| 3177 | t.detach(); | - | ||||||||||||||||||||||||
| 3178 | } else { executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 3179 | t.d = new QUrlPrivate; | - | ||||||||||||||||||||||||
| 3180 | - | |||||||||||||||||||||||||
| 3181 | // copy the authority | - | ||||||||||||||||||||||||
| 3182 | t.d->userName = d->userName; | - | ||||||||||||||||||||||||
| 3183 | t.d->password = d->password; | - | ||||||||||||||||||||||||
| 3184 | t.d->host = d->host; | - | ||||||||||||||||||||||||
| 3185 | t.d->port = d->port; | - | ||||||||||||||||||||||||
| 3186 | t.d->sectionIsPresent = d->sectionIsPresent & QUrlPrivate::Authority; | - | ||||||||||||||||||||||||
| 3187 | - | |||||||||||||||||||||||||
| 3188 | if (relative.d->path.isEmpty()) {
| 5-3416 | ||||||||||||||||||||||||
| 3189 | t.d->path = d->path; | - | ||||||||||||||||||||||||
| 3190 | if (relative.d->hasQuery()) {
| 1-4 | ||||||||||||||||||||||||
| 3191 | t.d->query = relative.d->query; | - | ||||||||||||||||||||||||
| 3192 | t.d->sectionIsPresent |= QUrlPrivate::Query; | - | ||||||||||||||||||||||||
| 3193 | } else if (d->hasQuery()) { executed 1 time by 1 test: end of blockExecuted by:
| 1-2 | ||||||||||||||||||||||||
| 3194 | t.d->query = d->query; | - | ||||||||||||||||||||||||
| 3195 | t.d->sectionIsPresent |= QUrlPrivate::Query; | - | ||||||||||||||||||||||||
| 3196 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 3197 | } else { executed 5 times by 2 tests: end of blockExecuted by:
| 5 | ||||||||||||||||||||||||
| 3198 | t.d->path = relative.d->path.startsWith(QLatin1Char('/'))
| 27-3389 | ||||||||||||||||||||||||
| 3199 | ? relative.d->path | - | ||||||||||||||||||||||||
| 3200 | : d->mergePaths(relative.d->path); | - | ||||||||||||||||||||||||
| 3201 | if (relative.d->hasQuery()) {
| 25-3391 | ||||||||||||||||||||||||
| 3202 | t.d->query = relative.d->query; | - | ||||||||||||||||||||||||
| 3203 | t.d->sectionIsPresent |= QUrlPrivate::Query; | - | ||||||||||||||||||||||||
| 3204 | } executed 25 times by 2 tests: end of blockExecuted by:
| 25 | ||||||||||||||||||||||||
| 3205 | } executed 3416 times by 5 tests: end of blockExecuted by:
| 3416 | ||||||||||||||||||||||||
| 3206 | } | - | ||||||||||||||||||||||||
| 3207 | t.d->scheme = d->scheme; | - | ||||||||||||||||||||||||
| 3208 | if (d->hasScheme())
| 12-3411 | ||||||||||||||||||||||||
| 3209 | t.d->sectionIsPresent |= QUrlPrivate::Scheme; executed 3411 times by 5 tests: t.d->sectionIsPresent |= QUrlPrivate::Scheme;Executed by:
| 3411 | ||||||||||||||||||||||||
| 3210 | else | - | ||||||||||||||||||||||||
| 3211 | t.d->sectionIsPresent &= ~QUrlPrivate::Scheme; executed 12 times by 2 tests: t.d->sectionIsPresent &= ~QUrlPrivate::Scheme;Executed by:
| 12 | ||||||||||||||||||||||||
| 3212 | t.d->flags |= d->flags & QUrlPrivate::IsLocalFile; | - | ||||||||||||||||||||||||
| 3213 | } executed 3423 times by 5 tests: end of blockExecuted by:
| 3423 | ||||||||||||||||||||||||
| 3214 | t.d->fragment = relative.d->fragment; | - | ||||||||||||||||||||||||
| 3215 | if (relative.d->hasFragment())
| 10-4476 | ||||||||||||||||||||||||
| 3216 | t.d->sectionIsPresent |= QUrlPrivate::Fragment; executed 10 times by 2 tests: t.d->sectionIsPresent |= QUrlPrivate::Fragment;Executed by:
| 10 | ||||||||||||||||||||||||
| 3217 | else | - | ||||||||||||||||||||||||
| 3218 | t.d->sectionIsPresent &= ~QUrlPrivate::Fragment; executed 4476 times by 5 tests: t.d->sectionIsPresent &= ~QUrlPrivate::Fragment;Executed by:
| 4476 | ||||||||||||||||||||||||
| 3219 | - | |||||||||||||||||||||||||
| 3220 | removeDotsFromPath(&t.d->path); | - | ||||||||||||||||||||||||
| 3221 | - | |||||||||||||||||||||||||
| 3222 | #if defined(QURL_DEBUG) | - | ||||||||||||||||||||||||
| 3223 | qDebug("QUrl(\"%s\").resolved(\"%s\") = \"%s\"", | - | ||||||||||||||||||||||||
| 3224 | qPrintable(url()), | - | ||||||||||||||||||||||||
| 3225 | qPrintable(relative.url()), | - | ||||||||||||||||||||||||
| 3226 | qPrintable(t.url())); | - | ||||||||||||||||||||||||
| 3227 | #endif | - | ||||||||||||||||||||||||
| 3228 | return t; executed 4486 times by 5 tests: return t;Executed by:
| 4486 | ||||||||||||||||||||||||
| 3229 | } | - | ||||||||||||||||||||||||
| 3230 | - | |||||||||||||||||||||||||
| 3231 | /*! | - | ||||||||||||||||||||||||
| 3232 | Returns \c true if the URL is relative; otherwise returns \c false. A URL is | - | ||||||||||||||||||||||||
| 3233 | relative reference if its scheme is undefined; this function is therefore | - | ||||||||||||||||||||||||
| 3234 | equivalent to calling scheme().isEmpty(). | - | ||||||||||||||||||||||||
| 3235 | - | |||||||||||||||||||||||||
| 3236 | Relative references are defined in RFC 3986 section 4.2. | - | ||||||||||||||||||||||||
| 3237 | */ | - | ||||||||||||||||||||||||
| 3238 | bool QUrl::isRelative() const | - | ||||||||||||||||||||||||
| 3239 | { | - | ||||||||||||||||||||||||
| 3240 | if (!d) return true; executed 3 times by 1 test: return true;Executed by:
| 3-425 | ||||||||||||||||||||||||
| 3241 | return !d->hasScheme(); executed 425 times by 8 tests: return !d->hasScheme();Executed by:
| 425 | ||||||||||||||||||||||||
| 3242 | } | - | ||||||||||||||||||||||||
| 3243 | - | |||||||||||||||||||||||||
| 3244 | /*! | - | ||||||||||||||||||||||||
| 3245 | Returns a string representation of the URL. The output can be customized by | - | ||||||||||||||||||||||||
| 3246 | passing flags with \a options. The option QUrl::FullyDecoded is not | - | ||||||||||||||||||||||||
| 3247 | permitted in this function since it would generate ambiguous data. | - | ||||||||||||||||||||||||
| 3248 | - | |||||||||||||||||||||||||
| 3249 | The resulting QString can be passed back to a QUrl later on. | - | ||||||||||||||||||||||||
| 3250 | - | |||||||||||||||||||||||||
| 3251 | Synonym for toString(options). | - | ||||||||||||||||||||||||
| 3252 | - | |||||||||||||||||||||||||
| 3253 | \sa FormattingOptions, toEncoded(), toString() | - | ||||||||||||||||||||||||
| 3254 | */ | - | ||||||||||||||||||||||||
| 3255 | QString QUrl::url(FormattingOptions options) const | - | ||||||||||||||||||||||||
| 3256 | { | - | ||||||||||||||||||||||||
| 3257 | return toString(options); executed 43 times by 3 tests: return toString(options);Executed by:
| 43 | ||||||||||||||||||||||||
| 3258 | } | - | ||||||||||||||||||||||||
| 3259 | - | |||||||||||||||||||||||||
| 3260 | /*! | - | ||||||||||||||||||||||||
| 3261 | Returns a string representation of the URL. The output can be customized by | - | ||||||||||||||||||||||||
| 3262 | passing flags with \a options. The option QUrl::FullyDecoded is not | - | ||||||||||||||||||||||||
| 3263 | permitted in this function since it would generate ambiguous data. | - | ||||||||||||||||||||||||
| 3264 | - | |||||||||||||||||||||||||
| 3265 | The default formatting option is \l{QUrl::FormattingOptions}{PrettyDecoded}. | - | ||||||||||||||||||||||||
| 3266 | - | |||||||||||||||||||||||||
| 3267 | \sa FormattingOptions, url(), setUrl() | - | ||||||||||||||||||||||||
| 3268 | */ | - | ||||||||||||||||||||||||
| 3269 | QString QUrl::toString(FormattingOptions options) const | - | ||||||||||||||||||||||||
| 3270 | { | - | ||||||||||||||||||||||||
| 3271 | if (!isValid()) {
| 149-9059 | ||||||||||||||||||||||||
| 3272 | // also catches isEmpty() | - | ||||||||||||||||||||||||
| 3273 | return QString(); executed 149 times by 5 tests: return QString();Executed by:
| 149 | ||||||||||||||||||||||||
| 3274 | } | - | ||||||||||||||||||||||||
| 3275 | if (options == QUrl::FullyDecoded) {
| 0-9059 | ||||||||||||||||||||||||
| 3276 | qWarning("QUrl: QUrl::FullyDecoded is not permitted when reconstructing the full URL"); | - | ||||||||||||||||||||||||
| 3277 | options = QUrl::PrettyDecoded; | - | ||||||||||||||||||||||||
| 3278 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3279 | - | |||||||||||||||||||||||||
| 3280 | // return just the path if: | - | ||||||||||||||||||||||||
| 3281 | // - QUrl::PreferLocalFile is passed | - | ||||||||||||||||||||||||
| 3282 | // - QUrl::RemovePath isn't passed (rather stupid if the user did...) | - | ||||||||||||||||||||||||
| 3283 | // - there's no query or fragment to return | - | ||||||||||||||||||||||||
| 3284 | // that is, either they aren't present, or we're removing them | - | ||||||||||||||||||||||||
| 3285 | // - it's a local file | - | ||||||||||||||||||||||||
| 3286 | if (options.testFlag(QUrl::PreferLocalFile) && !options.testFlag(QUrl::RemovePath)
| 0-9052 | ||||||||||||||||||||||||
| 3287 | && (!d->hasQuery() || options.testFlag(QUrl::RemoveQuery))
| 0-7 | ||||||||||||||||||||||||
| 3288 | && (!d->hasFragment() || options.testFlag(QUrl::RemoveFragment))
| 0-6 | ||||||||||||||||||||||||
| 3289 | && isLocalFile()) {
| 2-4 | ||||||||||||||||||||||||
| 3290 | return d->toLocalFile(options); executed 4 times by 1 test: return d->toLocalFile(options);Executed by:
| 4 | ||||||||||||||||||||||||
| 3291 | } | - | ||||||||||||||||||||||||
| 3292 | - | |||||||||||||||||||||||||
| 3293 | QString url; | - | ||||||||||||||||||||||||
| 3294 | - | |||||||||||||||||||||||||
| 3295 | // for the full URL, we consider that the reserved characters are prettier if encoded | - | ||||||||||||||||||||||||
| 3296 | if (options & DecodeReserved)
| 35-9020 | ||||||||||||||||||||||||
| 3297 | options &= ~EncodeReserved; executed 35 times by 1 test: options &= ~EncodeReserved;Executed by:
| 35 | ||||||||||||||||||||||||
| 3298 | else | - | ||||||||||||||||||||||||
| 3299 | options |= EncodeReserved; executed 9020 times by 30 tests: options |= EncodeReserved;Executed by:
| 9020 | ||||||||||||||||||||||||
| 3300 | - | |||||||||||||||||||||||||
| 3301 | if (!(options & QUrl::RemoveScheme) && d->hasScheme())
| 256-7062 | ||||||||||||||||||||||||
| 3302 | url += d->scheme + QLatin1Char(':'); executed 6806 times by 25 tests: url += d->scheme + QLatin1Char(':');Executed by:
| 6806 | ||||||||||||||||||||||||
| 3303 | - | |||||||||||||||||||||||||
| 3304 | bool pathIsAbsolute = d->path.startsWith(QLatin1Char('/')); | - | ||||||||||||||||||||||||
| 3305 | if (!((options & QUrl::RemoveAuthority) == QUrl::RemoveAuthority) && d->hasAuthority()) {
| 1603-7091 | ||||||||||||||||||||||||
| 3306 | url += QLatin1String("//"); | - | ||||||||||||||||||||||||
| 3307 | d->appendAuthority(url, options, QUrlPrivate::FullUrl); | - | ||||||||||||||||||||||||
| 3308 | } else if (isLocalFile() && pathIsAbsolute) { executed 5488 times by 21 tests: end of blockExecuted by:
| 284-5488 | ||||||||||||||||||||||||
| 3309 | // Comply with the XDG file URI spec, which requires triple slashes. | - | ||||||||||||||||||||||||
| 3310 | url += QLatin1String("//"); | - | ||||||||||||||||||||||||
| 3311 | } executed 1033 times by 9 tests: end of blockExecuted by:
| 1033 | ||||||||||||||||||||||||
| 3312 | - | |||||||||||||||||||||||||
| 3313 | if (!(options & QUrl::RemovePath))
| 1906-7149 | ||||||||||||||||||||||||
| 3314 | d->appendPath(url, options, QUrlPrivate::FullUrl); executed 7149 times by 30 tests: d->appendPath(url, options, QUrlPrivate::FullUrl);Executed by:
| 7149 | ||||||||||||||||||||||||
| 3315 | - | |||||||||||||||||||||||||
| 3316 | if (!(options & QUrl::RemoveQuery) && d->hasQuery()) {
| 533-7141 | ||||||||||||||||||||||||
| 3317 | url += QLatin1Char('?'); | - | ||||||||||||||||||||||||
| 3318 | d->appendQuery(url, options, QUrlPrivate::FullUrl); | - | ||||||||||||||||||||||||
| 3319 | } executed 533 times by 4 tests: end of blockExecuted by:
| 533 | ||||||||||||||||||||||||
| 3320 | if (!(options & QUrl::RemoveFragment) && d->hasFragment()) {
| 792-6050 | ||||||||||||||||||||||||
| 3321 | url += QLatin1Char('#'); | - | ||||||||||||||||||||||||
| 3322 | d->appendFragment(url, options, QUrlPrivate::FullUrl); | - | ||||||||||||||||||||||||
| 3323 | } executed 792 times by 4 tests: end of blockExecuted by:
| 792 | ||||||||||||||||||||||||
| 3324 | - | |||||||||||||||||||||||||
| 3325 | return url; executed 9055 times by 30 tests: return url;Executed by:
| 9055 | ||||||||||||||||||||||||
| 3326 | } | - | ||||||||||||||||||||||||
| 3327 | - | |||||||||||||||||||||||||
| 3328 | /*! | - | ||||||||||||||||||||||||
| 3329 | \since 5.0 | - | ||||||||||||||||||||||||
| 3330 | - | |||||||||||||||||||||||||
| 3331 | Returns a human-displayable string representation of the URL. | - | ||||||||||||||||||||||||
| 3332 | The output can be customized by passing flags with \a options. | - | ||||||||||||||||||||||||
| 3333 | The option RemovePassword is always enabled, since passwords | - | ||||||||||||||||||||||||
| 3334 | should never be shown back to users. | - | ||||||||||||||||||||||||
| 3335 | - | |||||||||||||||||||||||||
| 3336 | With the default options, the resulting QString can be passed back | - | ||||||||||||||||||||||||
| 3337 | to a QUrl later on, but any password that was present initially will | - | ||||||||||||||||||||||||
| 3338 | be lost. | - | ||||||||||||||||||||||||
| 3339 | - | |||||||||||||||||||||||||
| 3340 | \sa FormattingOptions, toEncoded(), toString() | - | ||||||||||||||||||||||||
| 3341 | */ | - | ||||||||||||||||||||||||
| 3342 | - | |||||||||||||||||||||||||
| 3343 | QString QUrl::toDisplayString(FormattingOptions options) const | - | ||||||||||||||||||||||||
| 3344 | { | - | ||||||||||||||||||||||||
| 3345 | return toString(options | RemovePassword); executed 258 times by 5 tests: return toString(options | RemovePassword);Executed by:
| 258 | ||||||||||||||||||||||||
| 3346 | } | - | ||||||||||||||||||||||||
| 3347 | - | |||||||||||||||||||||||||
| 3348 | /*! | - | ||||||||||||||||||||||||
| 3349 | \since 5.2 | - | ||||||||||||||||||||||||
| 3350 | - | |||||||||||||||||||||||||
| 3351 | Returns an adjusted version of the URL. | - | ||||||||||||||||||||||||
| 3352 | The output can be customized by passing flags with \a options. | - | ||||||||||||||||||||||||
| 3353 | - | |||||||||||||||||||||||||
| 3354 | The encoding options from QUrl::ComponentFormattingOption don't make | - | ||||||||||||||||||||||||
| 3355 | much sense for this method, nor does QUrl::PreferLocalFile. | - | ||||||||||||||||||||||||
| 3356 | - | |||||||||||||||||||||||||
| 3357 | This is always equivalent to QUrl(url.toString(options)). | - | ||||||||||||||||||||||||
| 3358 | - | |||||||||||||||||||||||||
| 3359 | \sa FormattingOptions, toEncoded(), toString() | - | ||||||||||||||||||||||||
| 3360 | */ | - | ||||||||||||||||||||||||
| 3361 | QUrl QUrl::adjusted(QUrl::FormattingOptions options) const | - | ||||||||||||||||||||||||
| 3362 | { | - | ||||||||||||||||||||||||
| 3363 | if (!isValid()) {
| 0-66 | ||||||||||||||||||||||||
| 3364 | // also catches isEmpty() | - | ||||||||||||||||||||||||
| 3365 | return QUrl(); never executed: return QUrl(); | 0 | ||||||||||||||||||||||||
| 3366 | } | - | ||||||||||||||||||||||||
| 3367 | QUrl that = *this; | - | ||||||||||||||||||||||||
| 3368 | if (options & RemoveScheme)
| 8-58 | ||||||||||||||||||||||||
| 3369 | that.setScheme(QString()); executed 8 times by 1 test: that.setScheme(QString());Executed by:
| 8 | ||||||||||||||||||||||||
| 3370 | if ((options & RemoveAuthority) == RemoveAuthority) {
| 8-58 | ||||||||||||||||||||||||
| 3371 | that.setAuthority(QString()); | - | ||||||||||||||||||||||||
| 3372 | } else { executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||||||||
| 3373 | if ((options & RemoveUserInfo) == RemoveUserInfo)
| 3-55 | ||||||||||||||||||||||||
| 3374 | that.setUserInfo(QString()); executed 3 times by 1 test: that.setUserInfo(QString());Executed by:
| 3 | ||||||||||||||||||||||||
| 3375 | else if (options & RemovePassword)
| 5-50 | ||||||||||||||||||||||||
| 3376 | that.setPassword(QString()); executed 5 times by 1 test: that.setPassword(QString());Executed by:
| 5 | ||||||||||||||||||||||||
| 3377 | if (options & RemovePort)
| 4-54 | ||||||||||||||||||||||||
| 3378 | that.setPort(-1); executed 4 times by 1 test: that.setPort(-1);Executed by:
| 4 | ||||||||||||||||||||||||
| 3379 | } executed 58 times by 1 test: end of blockExecuted by:
| 58 | ||||||||||||||||||||||||
| 3380 | if (options & RemoveQuery)
| 4-62 | ||||||||||||||||||||||||
| 3381 | that.setQuery(QString()); executed 4 times by 1 test: that.setQuery(QString());Executed by:
| 4 | ||||||||||||||||||||||||
| 3382 | if (options & RemoveFragment)
| 4-62 | ||||||||||||||||||||||||
| 3383 | that.setFragment(QString()); executed 4 times by 1 test: that.setFragment(QString());Executed by:
| 4 | ||||||||||||||||||||||||
| 3384 | if (options & RemovePath) {
| 4-62 | ||||||||||||||||||||||||
| 3385 | that.setPath(QString()); | - | ||||||||||||||||||||||||
| 3386 | } else if (options & (StripTrailingSlash | RemoveFilename | NormalizePathSegments)) { executed 4 times by 1 test: end of blockExecuted by:
| 4-40 | ||||||||||||||||||||||||
| 3387 | that.detach(); | - | ||||||||||||||||||||||||
| 3388 | QString path; | - | ||||||||||||||||||||||||
| 3389 | d->appendPath(path, options | FullyEncoded, QUrlPrivate::Path); | - | ||||||||||||||||||||||||
| 3390 | that.d->setPath(path, 0, path.length()); | - | ||||||||||||||||||||||||
| 3391 | } executed 40 times by 1 test: end of blockExecuted by:
| 40 | ||||||||||||||||||||||||
| 3392 | return that; executed 66 times by 1 test: return that;Executed by:
| 66 | ||||||||||||||||||||||||
| 3393 | } | - | ||||||||||||||||||||||||
| 3394 | - | |||||||||||||||||||||||||
| 3395 | /*! | - | ||||||||||||||||||||||||
| 3396 | Returns the encoded representation of the URL if it's valid; | - | ||||||||||||||||||||||||
| 3397 | otherwise an empty QByteArray is returned. The output can be | - | ||||||||||||||||||||||||
| 3398 | customized by passing flags with \a options. | - | ||||||||||||||||||||||||
| 3399 | - | |||||||||||||||||||||||||
| 3400 | The user info, path and fragment are all converted to UTF-8, and | - | ||||||||||||||||||||||||
| 3401 | all non-ASCII characters are then percent encoded. The host name | - | ||||||||||||||||||||||||
| 3402 | is encoded using Punycode. | - | ||||||||||||||||||||||||
| 3403 | */ | - | ||||||||||||||||||||||||
| 3404 | QByteArray QUrl::toEncoded(FormattingOptions options) const | - | ||||||||||||||||||||||||
| 3405 | { | - | ||||||||||||||||||||||||
| 3406 | options &= ~(FullyDecoded | FullyEncoded); | - | ||||||||||||||||||||||||
| 3407 | QString stringForm = toString(options | FullyEncoded); | - | ||||||||||||||||||||||||
| 3408 | return stringForm.toLatin1(); executed 5096 times by 23 tests: return stringForm.toLatin1();Executed by:
| 5096 | ||||||||||||||||||||||||
| 3409 | } | - | ||||||||||||||||||||||||
| 3410 | - | |||||||||||||||||||||||||
| 3411 | /*! | - | ||||||||||||||||||||||||
| 3412 | \fn QUrl QUrl::fromEncoded(const QByteArray &input, ParsingMode parsingMode) | - | ||||||||||||||||||||||||
| 3413 | - | |||||||||||||||||||||||||
| 3414 | Parses \a input and returns the corresponding QUrl. \a input is | - | ||||||||||||||||||||||||
| 3415 | assumed to be in encoded form, containing only ASCII characters. | - | ||||||||||||||||||||||||
| 3416 | - | |||||||||||||||||||||||||
| 3417 | Parses the URL using \a parsingMode. See setUrl() for more information on | - | ||||||||||||||||||||||||
| 3418 | this parameter. QUrl::DecodedMode is not permitted in this context. | - | ||||||||||||||||||||||||
| 3419 | - | |||||||||||||||||||||||||
| 3420 | \sa toEncoded(), setUrl() | - | ||||||||||||||||||||||||
| 3421 | */ | - | ||||||||||||||||||||||||
| 3422 | QUrl QUrl::fromEncoded(const QByteArray &input, ParsingMode mode) | - | ||||||||||||||||||||||||
| 3423 | { | - | ||||||||||||||||||||||||
| 3424 | return QUrl(QString::fromUtf8(input.constData(), input.size()), mode); executed 302 times by 7 tests: return QUrl(QString::fromUtf8(input.constData(), input.size()), mode);Executed by:
| 302 | ||||||||||||||||||||||||
| 3425 | } | - | ||||||||||||||||||||||||
| 3426 | - | |||||||||||||||||||||||||
| 3427 | /*! | - | ||||||||||||||||||||||||
| 3428 | Returns a decoded copy of \a input. \a input is first decoded from | - | ||||||||||||||||||||||||
| 3429 | percent encoding, then converted from UTF-8 to unicode. | - | ||||||||||||||||||||||||
| 3430 | */ | - | ||||||||||||||||||||||||
| 3431 | QString QUrl::fromPercentEncoding(const QByteArray &input) | - | ||||||||||||||||||||||||
| 3432 | { | - | ||||||||||||||||||||||||
| 3433 | QByteArray ba = QByteArray::fromPercentEncoding(input); | - | ||||||||||||||||||||||||
| 3434 | return QString::fromUtf8(ba, ba.size()); executed 39 times by 2 tests: return QString::fromUtf8(ba, ba.size());Executed by:
| 39 | ||||||||||||||||||||||||
| 3435 | } | - | ||||||||||||||||||||||||
| 3436 | - | |||||||||||||||||||||||||
| 3437 | /*! | - | ||||||||||||||||||||||||
| 3438 | Returns an encoded copy of \a input. \a input is first converted | - | ||||||||||||||||||||||||
| 3439 | to UTF-8, and all ASCII-characters that are not in the unreserved group | - | ||||||||||||||||||||||||
| 3440 | are percent encoded. To prevent characters from being percent encoded | - | ||||||||||||||||||||||||
| 3441 | pass them to \a exclude. To force characters to be percent encoded pass | - | ||||||||||||||||||||||||
| 3442 | them to \a include. | - | ||||||||||||||||||||||||
| 3443 | - | |||||||||||||||||||||||||
| 3444 | Unreserved is defined as: | - | ||||||||||||||||||||||||
| 3445 | \tt {ALPHA / DIGIT / "-" / "." / "_" / "~"} | - | ||||||||||||||||||||||||
| 3446 | - | |||||||||||||||||||||||||
| 3447 | \snippet code/src_corelib_io_qurl.cpp 6 | - | ||||||||||||||||||||||||
| 3448 | */ | - | ||||||||||||||||||||||||
| 3449 | QByteArray QUrl::toPercentEncoding(const QString &input, const QByteArray &exclude, const QByteArray &include) | - | ||||||||||||||||||||||||
| 3450 | { | - | ||||||||||||||||||||||||
| 3451 | return input.toUtf8().toPercentEncoding(exclude, include); executed 13 times by 1 test: return input.toUtf8().toPercentEncoding(exclude, include);Executed by:
| 13 | ||||||||||||||||||||||||
| 3452 | } | - | ||||||||||||||||||||||||
| 3453 | - | |||||||||||||||||||||||||
| 3454 | /*! \fn QUrl QUrl::fromCFURL(CFURLRef url) | - | ||||||||||||||||||||||||
| 3455 | \since 5.2 | - | ||||||||||||||||||||||||
| 3456 | - | |||||||||||||||||||||||||
| 3457 | Constructs a QUrl containing a copy of the CFURL \a url. | - | ||||||||||||||||||||||||
| 3458 | */ | - | ||||||||||||||||||||||||
| 3459 | - | |||||||||||||||||||||||||
| 3460 | /*! \fn CFURLRef QUrl::toCFURL() const | - | ||||||||||||||||||||||||
| 3461 | \since 5.2 | - | ||||||||||||||||||||||||
| 3462 | - | |||||||||||||||||||||||||
| 3463 | Creates a CFURL from a QUrl. The caller owns the CFURL and is | - | ||||||||||||||||||||||||
| 3464 | responsible for releasing it. | - | ||||||||||||||||||||||||
| 3465 | */ | - | ||||||||||||||||||||||||
| 3466 | - | |||||||||||||||||||||||||
| 3467 | /*! | - | ||||||||||||||||||||||||
| 3468 | \fn QUrl QUrl::fromNSURL(const NSURL *url) | - | ||||||||||||||||||||||||
| 3469 | \since 5.2 | - | ||||||||||||||||||||||||
| 3470 | - | |||||||||||||||||||||||||
| 3471 | Constructs a QUrl containing a copy of the NSURL \a url. | - | ||||||||||||||||||||||||
| 3472 | */ | - | ||||||||||||||||||||||||
| 3473 | - | |||||||||||||||||||||||||
| 3474 | /*! | - | ||||||||||||||||||||||||
| 3475 | \fn NSURL* QUrl::toNSURL() const | - | ||||||||||||||||||||||||
| 3476 | \since 5.2 | - | ||||||||||||||||||||||||
| 3477 | - | |||||||||||||||||||||||||
| 3478 | Creates a NSURL from a QUrl. The NSURL is autoreleased. | - | ||||||||||||||||||||||||
| 3479 | */ | - | ||||||||||||||||||||||||
| 3480 | - | |||||||||||||||||||||||||
| 3481 | /*! | - | ||||||||||||||||||||||||
| 3482 | \internal | - | ||||||||||||||||||||||||
| 3483 | \since 5.0 | - | ||||||||||||||||||||||||
| 3484 | Used in the setEncodedXXX compatibility functions. Converts \a ba to | - | ||||||||||||||||||||||||
| 3485 | QString form. | - | ||||||||||||||||||||||||
| 3486 | */ | - | ||||||||||||||||||||||||
| 3487 | QString QUrl::fromEncodedComponent_helper(const QByteArray &ba) | - | ||||||||||||||||||||||||
| 3488 | { | - | ||||||||||||||||||||||||
| 3489 | return qt_urlRecodeByteArray(ba); executed 34 times by 1 test: return qt_urlRecodeByteArray(ba);Executed by:
| 34 | ||||||||||||||||||||||||
| 3490 | } | - | ||||||||||||||||||||||||
| 3491 | - | |||||||||||||||||||||||||
| 3492 | /*! | - | ||||||||||||||||||||||||
| 3493 | \fn QByteArray QUrl::toPunycode(const QString &uc) | - | ||||||||||||||||||||||||
| 3494 | \obsolete | - | ||||||||||||||||||||||||
| 3495 | Returns a \a uc in Punycode encoding. | - | ||||||||||||||||||||||||
| 3496 | - | |||||||||||||||||||||||||
| 3497 | Punycode is a Unicode encoding used for internationalized domain | - | ||||||||||||||||||||||||
| 3498 | names, as defined in RFC3492. If you want to convert a domain name from | - | ||||||||||||||||||||||||
| 3499 | Unicode to its ASCII-compatible representation, use toAce(). | - | ||||||||||||||||||||||||
| 3500 | */ | - | ||||||||||||||||||||||||
| 3501 | - | |||||||||||||||||||||||||
| 3502 | /*! | - | ||||||||||||||||||||||||
| 3503 | \fn QString QUrl::fromPunycode(const QByteArray &pc) | - | ||||||||||||||||||||||||
| 3504 | \obsolete | - | ||||||||||||||||||||||||
| 3505 | Returns the Punycode decoded representation of \a pc. | - | ||||||||||||||||||||||||
| 3506 | - | |||||||||||||||||||||||||
| 3507 | Punycode is a Unicode encoding used for internationalized domain | - | ||||||||||||||||||||||||
| 3508 | names, as defined in RFC3492. If you want to convert a domain from | - | ||||||||||||||||||||||||
| 3509 | its ASCII-compatible encoding to the Unicode representation, use | - | ||||||||||||||||||||||||
| 3510 | fromAce(). | - | ||||||||||||||||||||||||
| 3511 | */ | - | ||||||||||||||||||||||||
| 3512 | - | |||||||||||||||||||||||||
| 3513 | /*! | - | ||||||||||||||||||||||||
| 3514 | \since 4.2 | - | ||||||||||||||||||||||||
| 3515 | - | |||||||||||||||||||||||||
| 3516 | Returns the Unicode form of the given domain name | - | ||||||||||||||||||||||||
| 3517 | \a domain, which is encoded in the ASCII Compatible Encoding (ACE). | - | ||||||||||||||||||||||||
| 3518 | The result of this function is considered equivalent to \a domain. | - | ||||||||||||||||||||||||
| 3519 | - | |||||||||||||||||||||||||
| 3520 | If the value in \a domain cannot be encoded, it will be converted | - | ||||||||||||||||||||||||
| 3521 | to QString and returned. | - | ||||||||||||||||||||||||
| 3522 | - | |||||||||||||||||||||||||
| 3523 | The ASCII Compatible Encoding (ACE) is defined by RFC 3490, RFC 3491 | - | ||||||||||||||||||||||||
| 3524 | and RFC 3492. It is part of the Internationalizing Domain Names in | - | ||||||||||||||||||||||||
| 3525 | Applications (IDNA) specification, which allows for domain names | - | ||||||||||||||||||||||||
| 3526 | (like \c "example.com") to be written using international | - | ||||||||||||||||||||||||
| 3527 | characters. | - | ||||||||||||||||||||||||
| 3528 | */ | - | ||||||||||||||||||||||||
| 3529 | QString QUrl::fromAce(const QByteArray &domain) | - | ||||||||||||||||||||||||
| 3530 | { | - | ||||||||||||||||||||||||
| 3531 | return qt_ACE_do(QString::fromLatin1(domain), NormalizeAce, ForbidLeadingDot /*FIXME: make configurable*/); executed 431 times by 8 tests: return qt_ACE_do(QString::fromLatin1(domain), NormalizeAce, ForbidLeadingDot );Executed by:
| 431 | ||||||||||||||||||||||||
| 3532 | } | - | ||||||||||||||||||||||||
| 3533 | - | |||||||||||||||||||||||||
| 3534 | /*! | - | ||||||||||||||||||||||||
| 3535 | \since 4.2 | - | ||||||||||||||||||||||||
| 3536 | - | |||||||||||||||||||||||||
| 3537 | Returns the ASCII Compatible Encoding of the given domain name \a domain. | - | ||||||||||||||||||||||||
| 3538 | The result of this function is considered equivalent to \a domain. | - | ||||||||||||||||||||||||
| 3539 | - | |||||||||||||||||||||||||
| 3540 | The ASCII-Compatible Encoding (ACE) is defined by RFC 3490, RFC 3491 | - | ||||||||||||||||||||||||
| 3541 | and RFC 3492. It is part of the Internationalizing Domain Names in | - | ||||||||||||||||||||||||
| 3542 | Applications (IDNA) specification, which allows for domain names | - | ||||||||||||||||||||||||
| 3543 | (like \c "example.com") to be written using international | - | ||||||||||||||||||||||||
| 3544 | characters. | - | ||||||||||||||||||||||||
| 3545 | - | |||||||||||||||||||||||||
| 3546 | This function returns an empty QByteArray if \a domain is not a valid | - | ||||||||||||||||||||||||
| 3547 | hostname. Note, in particular, that IPv6 literals are not valid domain | - | ||||||||||||||||||||||||
| 3548 | names. | - | ||||||||||||||||||||||||
| 3549 | */ | - | ||||||||||||||||||||||||
| 3550 | QByteArray QUrl::toAce(const QString &domain) | - | ||||||||||||||||||||||||
| 3551 | { | - | ||||||||||||||||||||||||
| 3552 | QString result = qt_ACE_do(domain, ToAceOnly, ForbidLeadingDot /*FIXME: make configurable*/); | - | ||||||||||||||||||||||||
| 3553 | return result.toLatin1(); executed 5885 times by 31 tests: return result.toLatin1();Executed by:
| 5885 | ||||||||||||||||||||||||
| 3554 | } | - | ||||||||||||||||||||||||
| 3555 | - | |||||||||||||||||||||||||
| 3556 | /*! | - | ||||||||||||||||||||||||
| 3557 | \internal | - | ||||||||||||||||||||||||
| 3558 | - | |||||||||||||||||||||||||
| 3559 | Returns \c true if this URL is "less than" the given \a url. This | - | ||||||||||||||||||||||||
| 3560 | provides a means of ordering URLs. | - | ||||||||||||||||||||||||
| 3561 | */ | - | ||||||||||||||||||||||||
| 3562 | bool QUrl::operator <(const QUrl &url) const | - | ||||||||||||||||||||||||
| 3563 | { | - | ||||||||||||||||||||||||
| 3564 | if (!d || !url.d) {
| 8-155 | ||||||||||||||||||||||||
| 3565 | bool thisIsEmpty = !d || d->isEmpty();
| 3-18 | ||||||||||||||||||||||||
| 3566 | bool thatIsEmpty = !url.d || url.d->isEmpty();
| 4-17 | ||||||||||||||||||||||||
| 3567 | - | |||||||||||||||||||||||||
| 3568 | // sort an empty URL first | - | ||||||||||||||||||||||||
| 3569 | return thisIsEmpty && !thatIsEmpty; executed 26 times by 1 test: return thisIsEmpty && !thatIsEmpty;Executed by:
| 4-26 | ||||||||||||||||||||||||
| 3570 | } | - | ||||||||||||||||||||||||
| 3571 | - | |||||||||||||||||||||||||
| 3572 | int cmp; | - | ||||||||||||||||||||||||
| 3573 | cmp = d->scheme.compare(url.d->scheme); | - | ||||||||||||||||||||||||
| 3574 | if (cmp != 0)
| 17-130 | ||||||||||||||||||||||||
| 3575 | return cmp < 0; executed 17 times by 1 test: return cmp < 0;Executed by:
| 17 | ||||||||||||||||||||||||
| 3576 | - | |||||||||||||||||||||||||
| 3577 | cmp = d->userName.compare(url.d->userName); | - | ||||||||||||||||||||||||
| 3578 | if (cmp != 0)
| 0-130 | ||||||||||||||||||||||||
| 3579 | return cmp < 0; never executed: return cmp < 0; | 0 | ||||||||||||||||||||||||
| 3580 | - | |||||||||||||||||||||||||
| 3581 | cmp = d->password.compare(url.d->password); | - | ||||||||||||||||||||||||
| 3582 | if (cmp != 0)
| 0-130 | ||||||||||||||||||||||||
| 3583 | return cmp < 0; never executed: return cmp < 0; | 0 | ||||||||||||||||||||||||
| 3584 | - | |||||||||||||||||||||||||
| 3585 | cmp = d->host.compare(url.d->host); | - | ||||||||||||||||||||||||
| 3586 | if (cmp != 0)
| 0-130 | ||||||||||||||||||||||||
| 3587 | return cmp < 0; never executed: return cmp < 0; | 0 | ||||||||||||||||||||||||
| 3588 | - | |||||||||||||||||||||||||
| 3589 | if (d->port != url.d->port)
| 8-122 | ||||||||||||||||||||||||
| 3590 | return d->port < url.d->port; executed 8 times by 1 test: return d->port < url.d->port;Executed by:
| 8 | ||||||||||||||||||||||||
| 3591 | - | |||||||||||||||||||||||||
| 3592 | cmp = d->path.compare(url.d->path); | - | ||||||||||||||||||||||||
| 3593 | if (cmp != 0)
| 21-101 | ||||||||||||||||||||||||
| 3594 | return cmp < 0; executed 21 times by 3 tests: return cmp < 0;Executed by:
| 21 | ||||||||||||||||||||||||
| 3595 | - | |||||||||||||||||||||||||
| 3596 | if (d->hasQuery() != url.d->hasQuery())
| 8-93 | ||||||||||||||||||||||||
| 3597 | return url.d->hasQuery(); executed 8 times by 1 test: return url.d->hasQuery();Executed by:
| 8 | ||||||||||||||||||||||||
| 3598 | - | |||||||||||||||||||||||||
| 3599 | cmp = d->query.compare(url.d->query); | - | ||||||||||||||||||||||||
| 3600 | if (cmp != 0)
| 1-92 | ||||||||||||||||||||||||
| 3601 | return cmp < 0; executed 1 time by 1 test: return cmp < 0;Executed by:
| 1 | ||||||||||||||||||||||||
| 3602 | - | |||||||||||||||||||||||||
| 3603 | if (d->hasFragment() != url.d->hasFragment())
| 8-84 | ||||||||||||||||||||||||
| 3604 | return url.d->hasFragment(); executed 8 times by 1 test: return url.d->hasFragment();Executed by:
| 8 | ||||||||||||||||||||||||
| 3605 | - | |||||||||||||||||||||||||
| 3606 | cmp = d->fragment.compare(url.d->fragment); | - | ||||||||||||||||||||||||
| 3607 | return cmp < 0; executed 84 times by 6 tests: return cmp < 0;Executed by:
| 84 | ||||||||||||||||||||||||
| 3608 | } | - | ||||||||||||||||||||||||
| 3609 | - | |||||||||||||||||||||||||
| 3610 | /*! | - | ||||||||||||||||||||||||
| 3611 | Returns \c true if this URL and the given \a url are equal; | - | ||||||||||||||||||||||||
| 3612 | otherwise returns \c false. | - | ||||||||||||||||||||||||
| 3613 | */ | - | ||||||||||||||||||||||||
| 3614 | bool QUrl::operator ==(const QUrl &url) const | - | ||||||||||||||||||||||||
| 3615 | { | - | ||||||||||||||||||||||||
| 3616 | if (!d && !url.d)
| 129-3005 | ||||||||||||||||||||||||
| 3617 | return true; executed 129 times by 9 tests: return true;Executed by:
| 129 | ||||||||||||||||||||||||
| 3618 | if (!d)
| 140-3005 | ||||||||||||||||||||||||
| 3619 | return url.d->isEmpty(); executed 140 times by 7 tests: return url.d->isEmpty();Executed by:
| 140 | ||||||||||||||||||||||||
| 3620 | if (!url.d)
| 371-2634 | ||||||||||||||||||||||||
| 3621 | return d->isEmpty(); executed 371 times by 7 tests: return d->isEmpty();Executed by:
| 371 | ||||||||||||||||||||||||
| 3622 | - | |||||||||||||||||||||||||
| 3623 | // First, compare which sections are present, since it speeds up the | - | ||||||||||||||||||||||||
| 3624 | // processing considerably. We just have to ignore the host-is-present flag | - | ||||||||||||||||||||||||
| 3625 | // for local files (the "file" protocol), due to the requirements of the | - | ||||||||||||||||||||||||
| 3626 | // XDG file URI specification. | - | ||||||||||||||||||||||||
| 3627 | int mask = QUrlPrivate::FullUrl; | - | ||||||||||||||||||||||||
| 3628 | if (isLocalFile())
| 672-1962 | ||||||||||||||||||||||||
| 3629 | mask &= ~QUrlPrivate::Host; executed 1962 times by 10 tests: mask &= ~QUrlPrivate::Host;Executed by:
| 1962 | ||||||||||||||||||||||||
| 3630 | return (d->sectionIsPresent & mask) == (url.d->sectionIsPresent & mask) && executed 2634 times by 20 tests: return (d->sectionIsPresent & mask) == (url.d->sectionIsPresent & mask) && d->scheme == url.d->scheme && d->userName == url.d->userName && d->password == url.d->password && d->host == url.d->host && d->port == url.d->port && d->path == url.d->path && d->query == url.d->query && d->fragment == url.d->fragment;Executed by:
| 46-2634 | ||||||||||||||||||||||||
| 3631 | d->scheme == url.d->scheme && executed 2634 times by 20 tests: return (d->sectionIsPresent & mask) == (url.d->sectionIsPresent & mask) && d->scheme == url.d->scheme && d->userName == url.d->userName && d->password == url.d->password && d->host == url.d->host && d->port == url.d->port && d->path == url.d->path && d->query == url.d->query && d->fragment == url.d->fragment;Executed by:
| 0-2634 | ||||||||||||||||||||||||
| 3632 | d->userName == url.d->userName && executed 2634 times by 20 tests: return (d->sectionIsPresent & mask) == (url.d->sectionIsPresent & mask) && d->scheme == url.d->scheme && d->userName == url.d->userName && d->password == url.d->password && d->host == url.d->host && d->port == url.d->port && d->path == url.d->path && d->query == url.d->query && d->fragment == url.d->fragment;Executed by:
| 0-2634 | ||||||||||||||||||||||||
| 3633 | d->password == url.d->password && executed 2634 times by 20 tests: return (d->sectionIsPresent & mask) == (url.d->sectionIsPresent & mask) && d->scheme == url.d->scheme && d->userName == url.d->userName && d->password == url.d->password && d->host == url.d->host && d->port == url.d->port && d->path == url.d->path && d->query == url.d->query && d->fragment == url.d->fragment;Executed by:
| 2-2634 | ||||||||||||||||||||||||
| 3634 | d->host == url.d->host && executed 2634 times by 20 tests: return (d->sectionIsPresent & mask) == (url.d->sectionIsPresent & mask) && d->scheme == url.d->scheme && d->userName == url.d->userName && d->password == url.d->password && d->host == url.d->host && d->port == url.d->port && d->path == url.d->path && d->query == url.d->query && d->fragment == url.d->fragment;Executed by:
| 0-2634 | ||||||||||||||||||||||||
| 3635 | d->port == url.d->port && executed 2634 times by 20 tests: return (d->sectionIsPresent & mask) == (url.d->sectionIsPresent & mask) && d->scheme == url.d->scheme && d->userName == url.d->userName && d->password == url.d->password && d->host == url.d->host && d->port == url.d->port && d->path == url.d->path && d->query == url.d->query && d->fragment == url.d->fragment;Executed by:
| 2-2634 | ||||||||||||||||||||||||
| 3636 | d->path == url.d->path && executed 2634 times by 20 tests: return (d->sectionIsPresent & mask) == (url.d->sectionIsPresent & mask) && d->scheme == url.d->scheme && d->userName == url.d->userName && d->password == url.d->password && d->host == url.d->host && d->port == url.d->port && d->path == url.d->path && d->query == url.d->query && d->fragment == url.d->fragment;Executed by:
| 654-2634 | ||||||||||||||||||||||||
| 3637 | d->query == url.d->query && executed 2634 times by 20 tests: return (d->sectionIsPresent & mask) == (url.d->sectionIsPresent & mask) && d->scheme == url.d->scheme && d->userName == url.d->userName && d->password == url.d->password && d->host == url.d->host && d->port == url.d->port && d->path == url.d->path && d->query == url.d->query && d->fragment == url.d->fragment;Executed by:
| 3-2634 | ||||||||||||||||||||||||
| 3638 | d->fragment == url.d->fragment; executed 2634 times by 20 tests: return (d->sectionIsPresent & mask) == (url.d->sectionIsPresent & mask) && d->scheme == url.d->scheme && d->userName == url.d->userName && d->password == url.d->password && d->host == url.d->host && d->port == url.d->port && d->path == url.d->path && d->query == url.d->query && d->fragment == url.d->fragment;Executed by:
| 0-2634 | ||||||||||||||||||||||||
| 3639 | } | - | ||||||||||||||||||||||||
| 3640 | - | |||||||||||||||||||||||||
| 3641 | /*! | - | ||||||||||||||||||||||||
| 3642 | \since 5.2 | - | ||||||||||||||||||||||||
| 3643 | - | |||||||||||||||||||||||||
| 3644 | Returns \c true if this URL and the given \a url are equal after | - | ||||||||||||||||||||||||
| 3645 | applying \a options to both; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 3646 | - | |||||||||||||||||||||||||
| 3647 | This is equivalent to calling adjusted(options) on both URLs | - | ||||||||||||||||||||||||
| 3648 | and comparing the resulting urls, but faster. | - | ||||||||||||||||||||||||
| 3649 | - | |||||||||||||||||||||||||
| 3650 | */ | - | ||||||||||||||||||||||||
| 3651 | bool QUrl::matches(const QUrl &url, FormattingOptions options) const | - | ||||||||||||||||||||||||
| 3652 | { | - | ||||||||||||||||||||||||
| 3653 | if (!d && !url.d)
| 0-34 | ||||||||||||||||||||||||
| 3654 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 3655 | if (!d)
| 0-34 | ||||||||||||||||||||||||
| 3656 | return url.d->isEmpty(); never executed: return url.d->isEmpty(); | 0 | ||||||||||||||||||||||||
| 3657 | if (!url.d)
| 0-34 | ||||||||||||||||||||||||
| 3658 | return d->isEmpty(); never executed: return d->isEmpty(); | 0 | ||||||||||||||||||||||||
| 3659 | - | |||||||||||||||||||||||||
| 3660 | // First, compare which sections are present, since it speeds up the | - | ||||||||||||||||||||||||
| 3661 | // processing considerably. We just have to ignore the host-is-present flag | - | ||||||||||||||||||||||||
| 3662 | // for local files (the "file" protocol), due to the requirements of the | - | ||||||||||||||||||||||||
| 3663 | // XDG file URI specification. | - | ||||||||||||||||||||||||
| 3664 | int mask = QUrlPrivate::FullUrl; | - | ||||||||||||||||||||||||
| 3665 | if (isLocalFile())
| 2-32 | ||||||||||||||||||||||||
| 3666 | mask &= ~QUrlPrivate::Host; executed 2 times by 1 test: mask &= ~QUrlPrivate::Host;Executed by:
| 2 | ||||||||||||||||||||||||
| 3667 | - | |||||||||||||||||||||||||
| 3668 | if (options & QUrl::RemoveScheme)
| 0-34 | ||||||||||||||||||||||||
| 3669 | mask &= ~QUrlPrivate::Scheme; never executed: mask &= ~QUrlPrivate::Scheme; | 0 | ||||||||||||||||||||||||
| 3670 | else if (d->scheme != url.d->scheme)
| 0-34 | ||||||||||||||||||||||||
| 3671 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 3672 | - | |||||||||||||||||||||||||
| 3673 | if (options & QUrl::RemovePassword)
| 10-24 | ||||||||||||||||||||||||
| 3674 | mask &= ~QUrlPrivate::Password; executed 10 times by 1 test: mask &= ~QUrlPrivate::Password;Executed by:
| 10 | ||||||||||||||||||||||||
| 3675 | else if (d->password != url.d->password)
| 1-23 | ||||||||||||||||||||||||
| 3676 | return false; executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||||||||||||||
| 3677 | - | |||||||||||||||||||||||||
| 3678 | if (options & QUrl::RemoveUserInfo)
| 10-23 | ||||||||||||||||||||||||
| 3679 | mask &= ~QUrlPrivate::UserName; executed 10 times by 1 test: mask &= ~QUrlPrivate::UserName;Executed by:
| 10 | ||||||||||||||||||||||||
| 3680 | else if (d->userName != url.d->userName)
| 0-23 | ||||||||||||||||||||||||
| 3681 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 3682 | - | |||||||||||||||||||||||||
| 3683 | if (options & QUrl::RemovePort)
| 8-25 | ||||||||||||||||||||||||
| 3684 | mask &= ~QUrlPrivate::Port; executed 8 times by 1 test: mask &= ~QUrlPrivate::Port;Executed by:
| 8 | ||||||||||||||||||||||||
| 3685 | else if (d->port != url.d->port)
| 0-25 | ||||||||||||||||||||||||
| 3686 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 3687 | - | |||||||||||||||||||||||||
| 3688 | if (options & QUrl::RemoveAuthority)
| 10-23 | ||||||||||||||||||||||||
| 3689 | mask &= ~QUrlPrivate::Host; executed 10 times by 1 test: mask &= ~QUrlPrivate::Host;Executed by:
| 10 | ||||||||||||||||||||||||
| 3690 | else if (d->host != url.d->host)
| 2-21 | ||||||||||||||||||||||||
| 3691 | return false; executed 2 times by 1 test: return false;Executed by:
| 2 | ||||||||||||||||||||||||
| 3692 | - | |||||||||||||||||||||||||
| 3693 | if (options & QUrl::RemoveQuery)
| 4-27 | ||||||||||||||||||||||||
| 3694 | mask &= ~QUrlPrivate::Query; executed 4 times by 1 test: mask &= ~QUrlPrivate::Query;Executed by:
| 4 | ||||||||||||||||||||||||
| 3695 | else if (d->query != url.d->query)
| 2-25 | ||||||||||||||||||||||||
| 3696 | return false; executed 2 times by 1 test: return false;Executed by:
| 2 | ||||||||||||||||||||||||
| 3697 | - | |||||||||||||||||||||||||
| 3698 | if (options & QUrl::RemoveFragment)
| 3-26 | ||||||||||||||||||||||||
| 3699 | mask &= ~QUrlPrivate::Fragment; executed 3 times by 1 test: mask &= ~QUrlPrivate::Fragment;Executed by:
| 3 | ||||||||||||||||||||||||
| 3700 | else if (d->fragment != url.d->fragment)
| 1-25 | ||||||||||||||||||||||||
| 3701 | return false; executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||||||||||||||
| 3702 | - | |||||||||||||||||||||||||
| 3703 | if ((d->sectionIsPresent & mask) != (url.d->sectionIsPresent & mask))
| 1-27 | ||||||||||||||||||||||||
| 3704 | return false; executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||||||||||||||
| 3705 | - | |||||||||||||||||||||||||
| 3706 | if (options & QUrl::RemovePath)
| 5-22 | ||||||||||||||||||||||||
| 3707 | return true; executed 5 times by 1 test: return true;Executed by:
| 5 | ||||||||||||||||||||||||
| 3708 | - | |||||||||||||||||||||||||
| 3709 | // Compare paths, after applying path-related options | - | ||||||||||||||||||||||||
| 3710 | QString path1; | - | ||||||||||||||||||||||||
| 3711 | d->appendPath(path1, options, QUrlPrivate::Path); | - | ||||||||||||||||||||||||
| 3712 | QString path2; | - | ||||||||||||||||||||||||
| 3713 | url.d->appendPath(path2, options, QUrlPrivate::Path); | - | ||||||||||||||||||||||||
| 3714 | return path1 == path2; executed 22 times by 1 test: return path1 == path2;Executed by:
| 22 | ||||||||||||||||||||||||
| 3715 | } | - | ||||||||||||||||||||||||
| 3716 | - | |||||||||||||||||||||||||
| 3717 | /*! | - | ||||||||||||||||||||||||
| 3718 | Returns \c true if this URL and the given \a url are not equal; | - | ||||||||||||||||||||||||
| 3719 | otherwise returns \c false. | - | ||||||||||||||||||||||||
| 3720 | */ | - | ||||||||||||||||||||||||
| 3721 | bool QUrl::operator !=(const QUrl &url) const | - | ||||||||||||||||||||||||
| 3722 | { | - | ||||||||||||||||||||||||
| 3723 | return !(*this == url); executed 120 times by 4 tests: return !(*this == url);Executed by:
| 120 | ||||||||||||||||||||||||
| 3724 | } | - | ||||||||||||||||||||||||
| 3725 | - | |||||||||||||||||||||||||
| 3726 | /*! | - | ||||||||||||||||||||||||
| 3727 | Assigns the specified \a url to this object. | - | ||||||||||||||||||||||||
| 3728 | */ | - | ||||||||||||||||||||||||
| 3729 | QUrl &QUrl::operator =(const QUrl &url) | - | ||||||||||||||||||||||||
| 3730 | { | - | ||||||||||||||||||||||||
| 3731 | if (!d) {
| 2604-9279 | ||||||||||||||||||||||||
| 3732 | if (url.d) {
| 2211-7068 | ||||||||||||||||||||||||
| 3733 | url.d->ref.ref(); | - | ||||||||||||||||||||||||
| 3734 | d = url.d; | - | ||||||||||||||||||||||||
| 3735 | } executed 7068 times by 21 tests: end of blockExecuted by:
| 7068 | ||||||||||||||||||||||||
| 3736 | } else { executed 9279 times by 22 tests: end of blockExecuted by:
| 9279 | ||||||||||||||||||||||||
| 3737 | if (url.d)
| 107-2497 | ||||||||||||||||||||||||
| 3738 | qAtomicAssign(d, url.d); executed 2497 times by 7 tests: qAtomicAssign(d, url.d);Executed by:
| 2497 | ||||||||||||||||||||||||
| 3739 | else | - | ||||||||||||||||||||||||
| 3740 | clear(); executed 107 times by 2 tests: clear();Executed by:
| 107 | ||||||||||||||||||||||||
| 3741 | } | - | ||||||||||||||||||||||||
| 3742 | return *this; executed 11883 times by 22 tests: return *this;Executed by:
| 11883 | ||||||||||||||||||||||||
| 3743 | } | - | ||||||||||||||||||||||||
| 3744 | - | |||||||||||||||||||||||||
| 3745 | /*! | - | ||||||||||||||||||||||||
| 3746 | Assigns the specified \a url to this object. | - | ||||||||||||||||||||||||
| 3747 | */ | - | ||||||||||||||||||||||||
| 3748 | QUrl &QUrl::operator =(const QString &url) | - | ||||||||||||||||||||||||
| 3749 | { | - | ||||||||||||||||||||||||
| 3750 | if (url.isEmpty()) {
| 0-10 | ||||||||||||||||||||||||
| 3751 | clear(); | - | ||||||||||||||||||||||||
| 3752 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 3753 | detach(); | - | ||||||||||||||||||||||||
| 3754 | d->parse(url, TolerantMode); | - | ||||||||||||||||||||||||
| 3755 | } executed 10 times by 1 test: end of blockExecuted by:
| 10 | ||||||||||||||||||||||||
| 3756 | return *this; executed 10 times by 1 test: return *this;Executed by:
| 10 | ||||||||||||||||||||||||
| 3757 | } | - | ||||||||||||||||||||||||
| 3758 | - | |||||||||||||||||||||||||
| 3759 | /*! | - | ||||||||||||||||||||||||
| 3760 | \fn void QUrl::swap(QUrl &other) | - | ||||||||||||||||||||||||
| 3761 | \since 4.8 | - | ||||||||||||||||||||||||
| 3762 | - | |||||||||||||||||||||||||
| 3763 | Swaps URL \a other with this URL. This operation is very | - | ||||||||||||||||||||||||
| 3764 | fast and never fails. | - | ||||||||||||||||||||||||
| 3765 | */ | - | ||||||||||||||||||||||||
| 3766 | - | |||||||||||||||||||||||||
| 3767 | /*! | - | ||||||||||||||||||||||||
| 3768 | \internal | - | ||||||||||||||||||||||||
| 3769 | - | |||||||||||||||||||||||||
| 3770 | Forces a detach. | - | ||||||||||||||||||||||||
| 3771 | */ | - | ||||||||||||||||||||||||
| 3772 | void QUrl::detach() | - | ||||||||||||||||||||||||
| 3773 | { | - | ||||||||||||||||||||||||
| 3774 | if (!d)
| 20700-27883 | ||||||||||||||||||||||||
| 3775 | d = new QUrlPrivate; executed 20700 times by 56 tests: d = new QUrlPrivate;Executed by:
| 20700 | ||||||||||||||||||||||||
| 3776 | else | - | ||||||||||||||||||||||||
| 3777 | qAtomicDetach(d); executed 27883 times by 47 tests: qAtomicDetach(d);Executed by:
| 27883 | ||||||||||||||||||||||||
| 3778 | } | - | ||||||||||||||||||||||||
| 3779 | - | |||||||||||||||||||||||||
| 3780 | /*! | - | ||||||||||||||||||||||||
| 3781 | \internal | - | ||||||||||||||||||||||||
| 3782 | */ | - | ||||||||||||||||||||||||
| 3783 | bool QUrl::isDetached() const | - | ||||||||||||||||||||||||
| 3784 | { | - | ||||||||||||||||||||||||
| 3785 | return !d || d->ref.load() == 1; never executed: return !d || d->ref.load() == 1;
| 0 | ||||||||||||||||||||||||
| 3786 | } | - | ||||||||||||||||||||||||
| 3787 | - | |||||||||||||||||||||||||
| 3788 | - | |||||||||||||||||||||||||
| 3789 | /*! | - | ||||||||||||||||||||||||
| 3790 | Returns a QUrl representation of \a localFile, interpreted as a local | - | ||||||||||||||||||||||||
| 3791 | file. This function accepts paths separated by slashes as well as the | - | ||||||||||||||||||||||||
| 3792 | native separator for this platform. | - | ||||||||||||||||||||||||
| 3793 | - | |||||||||||||||||||||||||
| 3794 | This function also accepts paths with a doubled leading slash (or | - | ||||||||||||||||||||||||
| 3795 | backslash) to indicate a remote file, as in | - | ||||||||||||||||||||||||
| 3796 | "//servername/path/to/file.txt". Note that only certain platforms can | - | ||||||||||||||||||||||||
| 3797 | actually open this file using QFile::open(). | - | ||||||||||||||||||||||||
| 3798 | - | |||||||||||||||||||||||||
| 3799 | An empty \a localFile leads to an empty URL (since Qt 5.4). | - | ||||||||||||||||||||||||
| 3800 | - | |||||||||||||||||||||||||
| 3801 | \sa toLocalFile(), isLocalFile(), QDir::toNativeSeparators() | - | ||||||||||||||||||||||||
| 3802 | */ | - | ||||||||||||||||||||||||
| 3803 | QUrl QUrl::fromLocalFile(const QString &localFile) | - | ||||||||||||||||||||||||
| 3804 | { | - | ||||||||||||||||||||||||
| 3805 | QUrl url; | - | ||||||||||||||||||||||||
| 3806 | if (localFile.isEmpty())
| 208-5142 | ||||||||||||||||||||||||
| 3807 | return url; executed 208 times by 4 tests: return url;Executed by:
| 208 | ||||||||||||||||||||||||
| 3808 | QString scheme = fileScheme(); | - | ||||||||||||||||||||||||
| 3809 | QString deslashified = QDir::fromNativeSeparators(localFile); | - | ||||||||||||||||||||||||
| 3810 | - | |||||||||||||||||||||||||
| 3811 | // magic for drives on windows | - | ||||||||||||||||||||||||
| 3812 | if (deslashified.length() > 1 && deslashified.at(1) == QLatin1Char(':') && deslashified.at(0) != QLatin1Char('/')) {
| 0-5077 | ||||||||||||||||||||||||
| 3813 | deslashified.prepend(QLatin1Char('/')); | - | ||||||||||||||||||||||||
| 3814 | } else if (deslashified.startsWith(QLatin1String("//"))) { executed 1 time by 1 test: end of blockExecuted by:
| 1-5137 | ||||||||||||||||||||||||
| 3815 | // magic for shared drive on windows | - | ||||||||||||||||||||||||
| 3816 | int indexOfPath = deslashified.indexOf(QLatin1Char('/'), 2); | - | ||||||||||||||||||||||||
| 3817 | QString hostSpec = deslashified.mid(2, indexOfPath - 2); | - | ||||||||||||||||||||||||
| 3818 | // Check for Windows-specific WebDAV specification: "//host@SSL/path". | - | ||||||||||||||||||||||||
| 3819 | if (hostSpec.endsWith(webDavSslTag(), Qt::CaseInsensitive)) {
| 1-3 | ||||||||||||||||||||||||
| 3820 | hostSpec.chop(4); | - | ||||||||||||||||||||||||
| 3821 | scheme = webDavScheme(); | - | ||||||||||||||||||||||||
| 3822 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||
| 3823 | url.setHost(hostSpec); | - | ||||||||||||||||||||||||
| 3824 | - | |||||||||||||||||||||||||
| 3825 | if (indexOfPath > 2)
| 1-3 | ||||||||||||||||||||||||
| 3826 | deslashified = deslashified.right(deslashified.length() - indexOfPath); executed 3 times by 1 test: deslashified = deslashified.right(deslashified.length() - indexOfPath);Executed by:
| 3 | ||||||||||||||||||||||||
| 3827 | else | - | ||||||||||||||||||||||||
| 3828 | deslashified.clear(); executed 1 time by 1 test: deslashified.clear();Executed by:
| 1 | ||||||||||||||||||||||||
| 3829 | } | - | ||||||||||||||||||||||||
| 3830 | - | |||||||||||||||||||||||||
| 3831 | url.setScheme(scheme); | - | ||||||||||||||||||||||||
| 3832 | url.setPath(deslashified, DecodedMode); | - | ||||||||||||||||||||||||
| 3833 | return url; executed 5142 times by 11 tests: return url;Executed by:
| 5142 | ||||||||||||||||||||||||
| 3834 | } | - | ||||||||||||||||||||||||
| 3835 | - | |||||||||||||||||||||||||
| 3836 | /*! | - | ||||||||||||||||||||||||
| 3837 | Returns the path of this URL formatted as a local file path. The path | - | ||||||||||||||||||||||||
| 3838 | returned will use forward slashes, even if it was originally created | - | ||||||||||||||||||||||||
| 3839 | from one with backslashes. | - | ||||||||||||||||||||||||
| 3840 | - | |||||||||||||||||||||||||
| 3841 | If this URL contains a non-empty hostname, it will be encoded in the | - | ||||||||||||||||||||||||
| 3842 | returned value in the form found on SMB networks (for example, | - | ||||||||||||||||||||||||
| 3843 | "//servername/path/to/file.txt"). | - | ||||||||||||||||||||||||
| 3844 | - | |||||||||||||||||||||||||
| 3845 | Note: if the path component of this URL contains a non-UTF-8 binary | - | ||||||||||||||||||||||||
| 3846 | sequence (such as %80), the behaviour of this function is undefined. | - | ||||||||||||||||||||||||
| 3847 | - | |||||||||||||||||||||||||
| 3848 | \sa fromLocalFile(), isLocalFile() | - | ||||||||||||||||||||||||
| 3849 | */ | - | ||||||||||||||||||||||||
| 3850 | QString QUrl::toLocalFile() const | - | ||||||||||||||||||||||||
| 3851 | { | - | ||||||||||||||||||||||||
| 3852 | // the call to isLocalFile() also ensures that we're parsed | - | ||||||||||||||||||||||||
| 3853 | if (!isLocalFile())
| 1120-10434 | ||||||||||||||||||||||||
| 3854 | return QString(); executed 1120 times by 8 tests: return QString();Executed by:
| 1120 | ||||||||||||||||||||||||
| 3855 | - | |||||||||||||||||||||||||
| 3856 | return d->toLocalFile(QUrl::FullyDecoded); executed 10434 times by 15 tests: return d->toLocalFile(QUrl::FullyDecoded);Executed by:
| 10434 | ||||||||||||||||||||||||
| 3857 | } | - | ||||||||||||||||||||||||
| 3858 | - | |||||||||||||||||||||||||
| 3859 | /*! | - | ||||||||||||||||||||||||
| 3860 | \since 4.8 | - | ||||||||||||||||||||||||
| 3861 | Returns \c true if this URL is pointing to a local file path. A URL is a | - | ||||||||||||||||||||||||
| 3862 | local file path if the scheme is "file". | - | ||||||||||||||||||||||||
| 3863 | - | |||||||||||||||||||||||||
| 3864 | Note that this function considers URLs with hostnames to be local file | - | ||||||||||||||||||||||||
| 3865 | paths, even if the eventual file path cannot be opened with | - | ||||||||||||||||||||||||
| 3866 | QFile::open(). | - | ||||||||||||||||||||||||
| 3867 | - | |||||||||||||||||||||||||
| 3868 | \sa fromLocalFile(), toLocalFile() | - | ||||||||||||||||||||||||
| 3869 | */ | - | ||||||||||||||||||||||||
| 3870 | bool QUrl::isLocalFile() const | - | ||||||||||||||||||||||||
| 3871 | { | - | ||||||||||||||||||||||||
| 3872 | return d && d->isLocalFile(); executed 21200 times by 36 tests: return d && d->isLocalFile();Executed by:
| 113-21200 | ||||||||||||||||||||||||
| 3873 | } | - | ||||||||||||||||||||||||
| 3874 | - | |||||||||||||||||||||||||
| 3875 | /*! | - | ||||||||||||||||||||||||
| 3876 | Returns \c true if this URL is a parent of \a childUrl. \a childUrl is a child | - | ||||||||||||||||||||||||
| 3877 | of this URL if the two URLs share the same scheme and authority, | - | ||||||||||||||||||||||||
| 3878 | and this URL's path is a parent of the path of \a childUrl. | - | ||||||||||||||||||||||||
| 3879 | */ | - | ||||||||||||||||||||||||
| 3880 | bool QUrl::isParentOf(const QUrl &childUrl) const | - | ||||||||||||||||||||||||
| 3881 | { | - | ||||||||||||||||||||||||
| 3882 | QString childPath = childUrl.path(); | - | ||||||||||||||||||||||||
| 3883 | - | |||||||||||||||||||||||||
| 3884 | if (!d)
| 0-5 | ||||||||||||||||||||||||
| 3885 | return ((childUrl.scheme().isEmpty()) never executed: return ((childUrl.scheme().isEmpty()) && (childUrl.authority().isEmpty()) && childPath.length() > 0 && childPath.at(0) == QLatin1Char('/'));
| 0 | ||||||||||||||||||||||||
| 3886 | && (childUrl.authority().isEmpty()) never executed: return ((childUrl.scheme().isEmpty()) && (childUrl.authority().isEmpty()) && childPath.length() > 0 && childPath.at(0) == QLatin1Char('/'));
| 0 | ||||||||||||||||||||||||
| 3887 | && childPath.length() > 0 && childPath.at(0) == QLatin1Char('/')); never executed: return ((childUrl.scheme().isEmpty()) && (childUrl.authority().isEmpty()) && childPath.length() > 0 && childPath.at(0) == QLatin1Char('/'));
| 0 | ||||||||||||||||||||||||
| 3888 | - | |||||||||||||||||||||||||
| 3889 | QString ourPath = path(); | - | ||||||||||||||||||||||||
| 3890 | - | |||||||||||||||||||||||||
| 3891 | return ((childUrl.scheme().isEmpty() || d->scheme == childUrl.scheme()) executed 5 times by 1 test: return ((childUrl.scheme().isEmpty() || d->scheme == childUrl.scheme()) && (childUrl.authority().isEmpty() || authority() == childUrl.authority()) && childPath.startsWith(ourPath) && ((ourPath.endsWith(QLatin1Char('/')) && childPath.length() > ourPath.length()) || (!ourPath.endsWith(QLatin1Char('/')) && childPath.length() > ourPath.length() && childPath.at(ourPath.length()) == QLatin1Char('/'))));Executed by:
| 0-5 | ||||||||||||||||||||||||
| 3892 | && (childUrl.authority().isEmpty() || authority() == childUrl.authority()) executed 5 times by 1 test: return ((childUrl.scheme().isEmpty() || d->scheme == childUrl.scheme()) && (childUrl.authority().isEmpty() || authority() == childUrl.authority()) && childPath.startsWith(ourPath) && ((ourPath.endsWith(QLatin1Char('/')) && childPath.length() > ourPath.length()) || (!ourPath.endsWith(QLatin1Char('/')) && childPath.length() > ourPath.length() && childPath.at(ourPath.length()) == QLatin1Char('/'))));Executed by:
| 0-5 | ||||||||||||||||||||||||
| 3893 | && childPath.startsWith(ourPath) executed 5 times by 1 test: return ((childUrl.scheme().isEmpty() || d->scheme == childUrl.scheme()) && (childUrl.authority().isEmpty() || authority() == childUrl.authority()) && childPath.startsWith(ourPath) && ((ourPath.endsWith(QLatin1Char('/')) && childPath.length() > ourPath.length()) || (!ourPath.endsWith(QLatin1Char('/')) && childPath.length() > ourPath.length() && childPath.at(ourPath.length()) == QLatin1Char('/'))));Executed by:
| 1-5 | ||||||||||||||||||||||||
| 3894 | && ((ourPath.endsWith(QLatin1Char('/')) && childPath.length() > ourPath.length()) executed 5 times by 1 test: return ((childUrl.scheme().isEmpty() || d->scheme == childUrl.scheme()) && (childUrl.authority().isEmpty() || authority() == childUrl.authority()) && childPath.startsWith(ourPath) && ((ourPath.endsWith(QLatin1Char('/')) && childPath.length() > ourPath.length()) || (!ourPath.endsWith(QLatin1Char('/')) && childPath.length() > ourPath.length() && childPath.at(ourPath.length()) == QLatin1Char('/'))));Executed by:
| 0-5 | ||||||||||||||||||||||||
| 3895 | || (!ourPath.endsWith(QLatin1Char('/')) executed 5 times by 1 test: return ((childUrl.scheme().isEmpty() || d->scheme == childUrl.scheme()) && (childUrl.authority().isEmpty() || authority() == childUrl.authority()) && childPath.startsWith(ourPath) && ((ourPath.endsWith(QLatin1Char('/')) && childPath.length() > ourPath.length()) || (!ourPath.endsWith(QLatin1Char('/')) && childPath.length() > ourPath.length() && childPath.at(ourPath.length()) == QLatin1Char('/'))));Executed by:
| 0-5 | ||||||||||||||||||||||||
| 3896 | && childPath.length() > ourPath.length() && childPath.at(ourPath.length()) == QLatin1Char('/')))); executed 5 times by 1 test: return ((childUrl.scheme().isEmpty() || d->scheme == childUrl.scheme()) && (childUrl.authority().isEmpty() || authority() == childUrl.authority()) && childPath.startsWith(ourPath) && ((ourPath.endsWith(QLatin1Char('/')) && childPath.length() > ourPath.length()) || (!ourPath.endsWith(QLatin1Char('/')) && childPath.length() > ourPath.length() && childPath.at(ourPath.length()) == QLatin1Char('/'))));Executed by:
| 1-5 | ||||||||||||||||||||||||
| 3897 | } | - | ||||||||||||||||||||||||
| 3898 | - | |||||||||||||||||||||||||
| 3899 | - | |||||||||||||||||||||||||
| 3900 | #ifndef QT_NO_DATASTREAM | - | ||||||||||||||||||||||||
| 3901 | /*! \relates QUrl | - | ||||||||||||||||||||||||
| 3902 | - | |||||||||||||||||||||||||
| 3903 | Writes url \a url to the stream \a out and returns a reference | - | ||||||||||||||||||||||||
| 3904 | to the stream. | - | ||||||||||||||||||||||||
| 3905 | - | |||||||||||||||||||||||||
| 3906 | \sa{Serializing Qt Data Types}{Format of the QDataStream operators} | - | ||||||||||||||||||||||||
| 3907 | */ | - | ||||||||||||||||||||||||
| 3908 | QDataStream &operator<<(QDataStream &out, const QUrl &url) | - | ||||||||||||||||||||||||
| 3909 | { | - | ||||||||||||||||||||||||
| 3910 | QByteArray u; | - | ||||||||||||||||||||||||
| 3911 | if (url.isValid())
| 5-102 | ||||||||||||||||||||||||
| 3912 | u = url.toEncoded(); executed 102 times by 6 tests: u = url.toEncoded();Executed by:
| 102 | ||||||||||||||||||||||||
| 3913 | out << u; | - | ||||||||||||||||||||||||
| 3914 | return out; executed 107 times by 8 tests: return out;Executed by:
| 107 | ||||||||||||||||||||||||
| 3915 | } | - | ||||||||||||||||||||||||
| 3916 | - | |||||||||||||||||||||||||
| 3917 | /*! \relates QUrl | - | ||||||||||||||||||||||||
| 3918 | - | |||||||||||||||||||||||||
| 3919 | Reads a url into \a url from the stream \a in and returns a | - | ||||||||||||||||||||||||
| 3920 | reference to the stream. | - | ||||||||||||||||||||||||
| 3921 | - | |||||||||||||||||||||||||
| 3922 | \sa{Serializing Qt Data Types}{Format of the QDataStream operators} | - | ||||||||||||||||||||||||
| 3923 | */ | - | ||||||||||||||||||||||||
| 3924 | QDataStream &operator>>(QDataStream &in, QUrl &url) | - | ||||||||||||||||||||||||
| 3925 | { | - | ||||||||||||||||||||||||
| 3926 | QByteArray u; | - | ||||||||||||||||||||||||
| 3927 | in >> u; | - | ||||||||||||||||||||||||
| 3928 | url.setUrl(QString::fromLatin1(u)); | - | ||||||||||||||||||||||||
| 3929 | return in; executed 106 times by 8 tests: return in;Executed by:
| 106 | ||||||||||||||||||||||||
| 3930 | } | - | ||||||||||||||||||||||||
| 3931 | #endif // QT_NO_DATASTREAM | - | ||||||||||||||||||||||||
| 3932 | - | |||||||||||||||||||||||||
| 3933 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||||||||||||||||||||
| 3934 | QDebug operator<<(QDebug d, const QUrl &url) | - | ||||||||||||||||||||||||
| 3935 | { | - | ||||||||||||||||||||||||
| 3936 | QDebugStateSaver saver(d); | - | ||||||||||||||||||||||||
| 3937 | d.nospace() << "QUrl(" << url.toDisplayString() << ')'; | - | ||||||||||||||||||||||||
| 3938 | return d; executed 219 times by 2 tests: return d;Executed by:
| 219 | ||||||||||||||||||||||||
| 3939 | } | - | ||||||||||||||||||||||||
| 3940 | #endif | - | ||||||||||||||||||||||||
| 3941 | - | |||||||||||||||||||||||||
| 3942 | static QString errorMessage(QUrlPrivate::ErrorCode errorCode, const QString &errorSource, int errorPosition) | - | ||||||||||||||||||||||||
| 3943 | { | - | ||||||||||||||||||||||||
| 3944 | QChar c = uint(errorPosition) < uint(errorSource.length()) ?
| 94-108 | ||||||||||||||||||||||||
| 3945 | errorSource.at(errorPosition) : QChar(QChar::Null); | - | ||||||||||||||||||||||||
| 3946 | - | |||||||||||||||||||||||||
| 3947 | switch (errorCode) { | - | ||||||||||||||||||||||||
| 3948 | case QUrlPrivate::NoError: never executed: case QUrlPrivate::NoError: | 0 | ||||||||||||||||||||||||
| 3949 | Q_ASSERT_X(false, "QUrl::errorString", | - | ||||||||||||||||||||||||
| 3950 | "Impossible: QUrl::errorString should have treated this condition"); | - | ||||||||||||||||||||||||
| 3951 | Q_UNREACHABLE(); | - | ||||||||||||||||||||||||
| 3952 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||||||||
| 3953 | - | |||||||||||||||||||||||||
| 3954 | case QUrlPrivate::InvalidSchemeError: { never executed: case QUrlPrivate::InvalidSchemeError: | 0 | ||||||||||||||||||||||||
| 3955 | QString msg = QStringLiteral("Invalid scheme (character '%1' not permitted)"); never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||||||||
| 3956 | return msg.arg(c); never executed: return msg.arg(c); | 0 | ||||||||||||||||||||||||
| 3957 | } | - | ||||||||||||||||||||||||
| 3958 | - | |||||||||||||||||||||||||
| 3959 | case QUrlPrivate::InvalidUserNameError: executed 10 times by 1 test: case QUrlPrivate::InvalidUserNameError:Executed by:
| 10 | ||||||||||||||||||||||||
| 3960 | return QString(QStringLiteral("Invalid user name (character '%1' not permitted)")) executed 10 times by 1 test: return QString(([]() -> QString { enum { Size = sizeof(u"" "Invalid user name (character '%1' not permitted)")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Invalid user name (character '%1' not permitted)" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())) .arg(c);Executed by:
executed 10 times by 1 test: return qstring_literal_temp;Executed by:
| 10 | ||||||||||||||||||||||||
| 3961 | .arg(c); executed 10 times by 1 test: return QString(([]() -> QString { enum { Size = sizeof(u"" "Invalid user name (character '%1' not permitted)")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Invalid user name (character '%1' not permitted)" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())) .arg(c);Executed by:
| 10 | ||||||||||||||||||||||||
| 3962 | - | |||||||||||||||||||||||||
| 3963 | case QUrlPrivate::InvalidPasswordError: executed 5 times by 1 test: case QUrlPrivate::InvalidPasswordError:Executed by:
| 5 | ||||||||||||||||||||||||
| 3964 | return QString(QStringLiteral("Invalid password (character '%1' not permitted)")) executed 5 times by 1 test: return QString(([]() -> QString { enum { Size = sizeof(u"" "Invalid password (character '%1' not permitted)")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Invalid password (character '%1' not permitted)" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())) .arg(c);Executed by:
executed 5 times by 1 test: return qstring_literal_temp;Executed by:
| 5 | ||||||||||||||||||||||||
| 3965 | .arg(c); executed 5 times by 1 test: return QString(([]() -> QString { enum { Size = sizeof(u"" "Invalid password (character '%1' not permitted)")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Invalid password (character '%1' not permitted)" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())) .arg(c);Executed by:
| 5 | ||||||||||||||||||||||||
| 3966 | - | |||||||||||||||||||||||||
| 3967 | case QUrlPrivate::InvalidRegNameError: executed 89 times by 1 test: case QUrlPrivate::InvalidRegNameError:Executed by:
| 89 | ||||||||||||||||||||||||
| 3968 | if (errorPosition != -1)
| 0-89 | ||||||||||||||||||||||||
| 3969 | return QString(QStringLiteral("Invalid hostname (character '%1' not permitted)")) never executed: return QString(([]() -> QString { enum { Size = sizeof(u"" "Invalid hostname (character '%1' not permitted)")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Invalid hostname (character '%1' not permitted)" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())) .arg(c);never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||||||||
| 3970 | .arg(c); never executed: return QString(([]() -> QString { enum { Size = sizeof(u"" "Invalid hostname (character '%1' not permitted)")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Invalid hostname (character '%1' not permitted)" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())) .arg(c); | 0 | ||||||||||||||||||||||||
| 3971 | else | - | ||||||||||||||||||||||||
| 3972 | return QStringLiteral("Invalid hostname (contains invalid characters)"); executed 89 times by 1 test: return ([]() -> QString { enum { Size = sizeof(u"" "Invalid hostname (contains invalid characters)")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Invalid hostname (contains invalid characters)" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());Executed by:
executed 89 times by 1 test: return qstring_literal_temp;Executed by:
| 89 | ||||||||||||||||||||||||
| 3973 | case QUrlPrivate::InvalidIPv4AddressError: never executed: case QUrlPrivate::InvalidIPv4AddressError: | 0 | ||||||||||||||||||||||||
| 3974 | return QString(); // doesn't happen yet never executed: return QString(); | 0 | ||||||||||||||||||||||||
| 3975 | case QUrlPrivate::InvalidIPv6AddressError: executed 5 times by 1 test: case QUrlPrivate::InvalidIPv6AddressError:Executed by:
| 5 | ||||||||||||||||||||||||
| 3976 | return QStringLiteral("Invalid IPv6 address"); executed 5 times by 1 test: return ([]() -> QString { enum { Size = sizeof(u"" "Invalid IPv6 address")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Invalid IPv6 address" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());Executed by:
executed 5 times by 1 test: return qstring_literal_temp;Executed by:
| 5 | ||||||||||||||||||||||||
| 3977 | case QUrlPrivate::InvalidCharacterInIPv6Error: executed 15 times by 1 test: case QUrlPrivate::InvalidCharacterInIPv6Error:Executed by:
| 15 | ||||||||||||||||||||||||
| 3978 | return QStringLiteral("Invalid IPv6 address (character '%1' not permitted)").arg(c); executed 15 times by 1 test: return ([]() -> QString { enum { Size = sizeof(u"" "Invalid IPv6 address (character '%1' not permitted)")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Invalid IPv6 address (character '%1' not permitted)" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()).arg(c);Executed by:
executed 15 times by 1 test: return qstring_literal_temp;Executed by:
| 15 | ||||||||||||||||||||||||
| 3979 | case QUrlPrivate::InvalidIPvFutureError: executed 25 times by 1 test: case QUrlPrivate::InvalidIPvFutureError:Executed by:
| 25 | ||||||||||||||||||||||||
| 3980 | return QStringLiteral("Invalid IPvFuture address (character '%1' not permitted)").arg(c); executed 25 times by 1 test: return ([]() -> QString { enum { Size = sizeof(u"" "Invalid IPvFuture address (character '%1' not permitted)")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Invalid IPvFuture address (character '%1' not permitted)" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()).arg(c);Executed by:
executed 25 times by 1 test: return qstring_literal_temp;Executed by:
| 25 | ||||||||||||||||||||||||
| 3981 | case QUrlPrivate::HostMissingEndBracket: executed 5 times by 1 test: case QUrlPrivate::HostMissingEndBracket:Executed by:
| 5 | ||||||||||||||||||||||||
| 3982 | return QStringLiteral("Expected ']' to match '[' in hostname"); executed 5 times by 1 test: return ([]() -> QString { enum { Size = sizeof(u"" "Expected ']' to match '[' in hostname")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Expected ']' to match '[' in hostname" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());Executed by:
executed 5 times by 1 test: return qstring_literal_temp;Executed by:
| 5 | ||||||||||||||||||||||||
| 3983 | - | |||||||||||||||||||||||||
| 3984 | case QUrlPrivate::InvalidPortError: executed 21 times by 1 test: case QUrlPrivate::InvalidPortError:Executed by:
| 21 | ||||||||||||||||||||||||
| 3985 | return QStringLiteral("Invalid port or port number out of range"); executed 21 times by 1 test: return ([]() -> QString { enum { Size = sizeof(u"" "Invalid port or port number out of range")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Invalid port or port number out of range" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());Executed by:
executed 21 times by 1 test: return qstring_literal_temp;Executed by:
| 21 | ||||||||||||||||||||||||
| 3986 | case QUrlPrivate::PortEmptyError: never executed: case QUrlPrivate::PortEmptyError: | 0 | ||||||||||||||||||||||||
| 3987 | return QStringLiteral("Port field was empty"); never executed: return ([]() -> QString { enum { Size = sizeof(u"" "Port field was empty")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Port field was empty" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||||||||
| 3988 | - | |||||||||||||||||||||||||
| 3989 | case QUrlPrivate::InvalidPathError: executed 10 times by 1 test: case QUrlPrivate::InvalidPathError:Executed by:
| 10 | ||||||||||||||||||||||||
| 3990 | return QString(QStringLiteral("Invalid path (character '%1' not permitted)")) executed 10 times by 1 test: return QString(([]() -> QString { enum { Size = sizeof(u"" "Invalid path (character '%1' not permitted)")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Invalid path (character '%1' not permitted)" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())) .arg(c);Executed by:
executed 10 times by 1 test: return qstring_literal_temp;Executed by:
| 10 | ||||||||||||||||||||||||
| 3991 | .arg(c); executed 10 times by 1 test: return QString(([]() -> QString { enum { Size = sizeof(u"" "Invalid path (character '%1' not permitted)")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Invalid path (character '%1' not permitted)" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())) .arg(c);Executed by:
| 10 | ||||||||||||||||||||||||
| 3992 | - | |||||||||||||||||||||||||
| 3993 | case QUrlPrivate::InvalidQueryError: executed 5 times by 1 test: case QUrlPrivate::InvalidQueryError:Executed by:
| 5 | ||||||||||||||||||||||||
| 3994 | return QString(QStringLiteral("Invalid query (character '%1' not permitted)")) executed 5 times by 1 test: return QString(([]() -> QString { enum { Size = sizeof(u"" "Invalid query (character '%1' not permitted)")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Invalid query (character '%1' not permitted)" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())) .arg(c);Executed by:
executed 5 times by 1 test: return qstring_literal_temp;Executed by:
| 5 | ||||||||||||||||||||||||
| 3995 | .arg(c); executed 5 times by 1 test: return QString(([]() -> QString { enum { Size = sizeof(u"" "Invalid query (character '%1' not permitted)")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Invalid query (character '%1' not permitted)" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())) .arg(c);Executed by:
| 5 | ||||||||||||||||||||||||
| 3996 | - | |||||||||||||||||||||||||
| 3997 | case QUrlPrivate::InvalidFragmentError: executed 5 times by 1 test: case QUrlPrivate::InvalidFragmentError:Executed by:
| 5 | ||||||||||||||||||||||||
| 3998 | return QString(QStringLiteral("Invalid fragment (character '%1' not permitted)")) executed 5 times by 1 test: return QString(([]() -> QString { enum { Size = sizeof(u"" "Invalid fragment (character '%1' not permitted)")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Invalid fragment (character '%1' not permitted)" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())) .arg(c);Executed by:
executed 5 times by 1 test: return qstring_literal_temp;Executed by:
| 5 | ||||||||||||||||||||||||
| 3999 | .arg(c); executed 5 times by 1 test: return QString(([]() -> QString { enum { Size = sizeof(u"" "Invalid fragment (character '%1' not permitted)")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Invalid fragment (character '%1' not permitted)" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())) .arg(c);Executed by:
| 5 | ||||||||||||||||||||||||
| 4000 | - | |||||||||||||||||||||||||
| 4001 | case QUrlPrivate::AuthorityPresentAndPathIsRelative: executed 1 time by 1 test: case QUrlPrivate::AuthorityPresentAndPathIsRelative:Executed by:
| 1 | ||||||||||||||||||||||||
| 4002 | return QStringLiteral("Path component is relative and authority is present"); executed 1 time by 1 test: return ([]() -> QString { enum { Size = sizeof(u"" "Path component is relative and authority is present")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Path component is relative and authority is present" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());Executed by:
executed 1 time by 1 test: return qstring_literal_temp;Executed by:
| 1 | ||||||||||||||||||||||||
| 4003 | case QUrlPrivate::RelativeUrlPathContainsColonBeforeSlash: executed 6 times by 1 test: case QUrlPrivate::RelativeUrlPathContainsColonBeforeSlash:Executed by:
| 6 | ||||||||||||||||||||||||
| 4004 | return QStringLiteral("Relative URL's path component contains ':' before any '/'"); executed 6 times by 1 test: return ([]() -> QString { enum { Size = sizeof(u"" "Relative URL's path component contains ':' before any '/'")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Relative URL's path component contains ':' before any '/'" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());Executed by:
executed 6 times by 1 test: return qstring_literal_temp;Executed by:
| 6 | ||||||||||||||||||||||||
| 4005 | } | - | ||||||||||||||||||||||||
| 4006 | - | |||||||||||||||||||||||||
| 4007 | Q_ASSERT_X(false, "QUrl::errorString", "Cannot happen, unknown error"); | - | ||||||||||||||||||||||||
| 4008 | Q_UNREACHABLE(); | - | ||||||||||||||||||||||||
| 4009 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||||||||
| 4010 | } | - | ||||||||||||||||||||||||
| 4011 | - | |||||||||||||||||||||||||
| 4012 | static inline void appendComponentIfPresent(QString &msg, bool present, const char *componentName, | - | ||||||||||||||||||||||||
| 4013 | const QString &component) | - | ||||||||||||||||||||||||
| 4014 | { | - | ||||||||||||||||||||||||
| 4015 | if (present) {
| 371-1043 | ||||||||||||||||||||||||
| 4016 | msg += QLatin1String(componentName); | - | ||||||||||||||||||||||||
| 4017 | msg += QLatin1Char('"'); | - | ||||||||||||||||||||||||
| 4018 | msg += component; | - | ||||||||||||||||||||||||
| 4019 | msg += QLatin1String("\","); | - | ||||||||||||||||||||||||
| 4020 | } executed 371 times by 1 test: end of blockExecuted by:
| 371 | ||||||||||||||||||||||||
| 4021 | } executed 1414 times by 1 test: end of blockExecuted by:
| 1414 | ||||||||||||||||||||||||
| 4022 | - | |||||||||||||||||||||||||
| 4023 | /*! | - | ||||||||||||||||||||||||
| 4024 | \since 4.2 | - | ||||||||||||||||||||||||
| 4025 | - | |||||||||||||||||||||||||
| 4026 | Returns an error message if the last operation that modified this QUrl | - | ||||||||||||||||||||||||
| 4027 | object ran into a parsing error. If no error was detected, this function | - | ||||||||||||||||||||||||
| 4028 | returns an empty string and isValid() returns \c true. | - | ||||||||||||||||||||||||
| 4029 | - | |||||||||||||||||||||||||
| 4030 | The error message returned by this function is technical in nature and may | - | ||||||||||||||||||||||||
| 4031 | not be understood by end users. It is mostly useful to developers trying to | - | ||||||||||||||||||||||||
| 4032 | understand why QUrl will not accept some input. | - | ||||||||||||||||||||||||
| 4033 | - | |||||||||||||||||||||||||
| 4034 | \sa QUrl::ParsingMode | - | ||||||||||||||||||||||||
| 4035 | */ | - | ||||||||||||||||||||||||
| 4036 | QString QUrl::errorString() const | - | ||||||||||||||||||||||||
| 4037 | { | - | ||||||||||||||||||||||||
| 4038 | if (!d)
| 112-213 | ||||||||||||||||||||||||
| 4039 | return QString(); executed 112 times by 6 tests: return QString();Executed by:
| 112 | ||||||||||||||||||||||||
| 4040 | - | |||||||||||||||||||||||||
| 4041 | QString errorSource; | - | ||||||||||||||||||||||||
| 4042 | int errorPosition = 0; | - | ||||||||||||||||||||||||
| 4043 | QUrlPrivate::ErrorCode errorCode = d->validityError(&errorSource, &errorPosition); | - | ||||||||||||||||||||||||
| 4044 | if (errorCode == QUrlPrivate::NoError)
| 11-202 | ||||||||||||||||||||||||
| 4045 | return QString(); executed 11 times by 2 tests: return QString();Executed by:
| 11 | ||||||||||||||||||||||||
| 4046 | - | |||||||||||||||||||||||||
| 4047 | QString msg = errorMessage(errorCode, errorSource, errorPosition); | - | ||||||||||||||||||||||||
| 4048 | msg += QLatin1String("; source was \""); | - | ||||||||||||||||||||||||
| 4049 | msg += errorSource; | - | ||||||||||||||||||||||||
| 4050 | msg += QLatin1String("\";"); | - | ||||||||||||||||||||||||
| 4051 | appendComponentIfPresent(msg, d->sectionIsPresent & QUrlPrivate::Scheme, | - | ||||||||||||||||||||||||
| 4052 | " scheme = ", d->scheme); | - | ||||||||||||||||||||||||
| 4053 | appendComponentIfPresent(msg, d->sectionIsPresent & QUrlPrivate::UserInfo, | - | ||||||||||||||||||||||||
| 4054 | " userinfo = ", userInfo()); | - | ||||||||||||||||||||||||
| 4055 | appendComponentIfPresent(msg, d->sectionIsPresent & QUrlPrivate::Host, | - | ||||||||||||||||||||||||
| 4056 | " host = ", d->host); | - | ||||||||||||||||||||||||
| 4057 | appendComponentIfPresent(msg, d->port != -1, | - | ||||||||||||||||||||||||
| 4058 | " port = ", QString::number(d->port)); | - | ||||||||||||||||||||||||
| 4059 | appendComponentIfPresent(msg, !d->path.isEmpty(), | - | ||||||||||||||||||||||||
| 4060 | " path = ", d->path); | - | ||||||||||||||||||||||||
| 4061 | appendComponentIfPresent(msg, d->sectionIsPresent & QUrlPrivate::Query, | - | ||||||||||||||||||||||||
| 4062 | " query = ", d->query); | - | ||||||||||||||||||||||||
| 4063 | appendComponentIfPresent(msg, d->sectionIsPresent & QUrlPrivate::Fragment, | - | ||||||||||||||||||||||||
| 4064 | " fragment = ", d->fragment); | - | ||||||||||||||||||||||||
| 4065 | if (msg.endsWith(QLatin1Char(',')))
| 1-201 | ||||||||||||||||||||||||
| 4066 | msg.chop(1); executed 201 times by 1 test: msg.chop(1);Executed by:
| 201 | ||||||||||||||||||||||||
| 4067 | return msg; executed 202 times by 1 test: return msg;Executed by:
| 202 | ||||||||||||||||||||||||
| 4068 | } | - | ||||||||||||||||||||||||
| 4069 | - | |||||||||||||||||||||||||
| 4070 | /*! | - | ||||||||||||||||||||||||
| 4071 | \since 5.1 | - | ||||||||||||||||||||||||
| 4072 | - | |||||||||||||||||||||||||
| 4073 | Converts a list of \a urls into a list of QString objects, using toString(\a options). | - | ||||||||||||||||||||||||
| 4074 | */ | - | ||||||||||||||||||||||||
| 4075 | QStringList QUrl::toStringList(const QList<QUrl> &urls, FormattingOptions options) | - | ||||||||||||||||||||||||
| 4076 | { | - | ||||||||||||||||||||||||
| 4077 | QStringList lst; | - | ||||||||||||||||||||||||
| 4078 | lst.reserve(urls.size()); | - | ||||||||||||||||||||||||
| 4079 | foreach (const QUrl &url, urls) | - | ||||||||||||||||||||||||
| 4080 | lst.append(url.toString(options)); executed 463 times by 5 tests: lst.append(url.toString(options));Executed by:
| 463 | ||||||||||||||||||||||||
| 4081 | return lst; executed 234 times by 5 tests: return lst;Executed by:
| 234 | ||||||||||||||||||||||||
| 4082 | - | |||||||||||||||||||||||||
| 4083 | } | - | ||||||||||||||||||||||||
| 4084 | - | |||||||||||||||||||||||||
| 4085 | /*! | - | ||||||||||||||||||||||||
| 4086 | \since 5.1 | - | ||||||||||||||||||||||||
| 4087 | - | |||||||||||||||||||||||||
| 4088 | Converts a list of strings representing \a urls into a list of urls, using QUrl(str, \a mode). | - | ||||||||||||||||||||||||
| 4089 | Note that this means all strings must be urls, not for instance local paths. | - | ||||||||||||||||||||||||
| 4090 | */ | - | ||||||||||||||||||||||||
| 4091 | QList<QUrl> QUrl::fromStringList(const QStringList &urls, ParsingMode mode) | - | ||||||||||||||||||||||||
| 4092 | { | - | ||||||||||||||||||||||||
| 4093 | QList<QUrl> lst; | - | ||||||||||||||||||||||||
| 4094 | lst.reserve(urls.size()); | - | ||||||||||||||||||||||||
| 4095 | foreach (const QString &str, urls) { | - | ||||||||||||||||||||||||
| 4096 | lst.append(QUrl(str, mode)); | - | ||||||||||||||||||||||||
| 4097 | } executed 507 times by 5 tests: end of blockExecuted by:
| 507 | ||||||||||||||||||||||||
| 4098 | return lst; executed 255 times by 5 tests: return lst;Executed by:
| 255 | ||||||||||||||||||||||||
| 4099 | } | - | ||||||||||||||||||||||||
| 4100 | - | |||||||||||||||||||||||||
| 4101 | /*! | - | ||||||||||||||||||||||||
| 4102 | \typedef QUrl::DataPtr | - | ||||||||||||||||||||||||
| 4103 | \internal | - | ||||||||||||||||||||||||
| 4104 | */ | - | ||||||||||||||||||||||||
| 4105 | - | |||||||||||||||||||||||||
| 4106 | /*! | - | ||||||||||||||||||||||||
| 4107 | \fn DataPtr &QUrl::data_ptr() | - | ||||||||||||||||||||||||
| 4108 | \internal | - | ||||||||||||||||||||||||
| 4109 | */ | - | ||||||||||||||||||||||||
| 4110 | - | |||||||||||||||||||||||||
| 4111 | /*! | - | ||||||||||||||||||||||||
| 4112 | Returns the hash value for the \a url. If specified, \a seed is used to | - | ||||||||||||||||||||||||
| 4113 | initialize the hash. | - | ||||||||||||||||||||||||
| 4114 | - | |||||||||||||||||||||||||
| 4115 | \relates QHash | - | ||||||||||||||||||||||||
| 4116 | \since 5.0 | - | ||||||||||||||||||||||||
| 4117 | */ | - | ||||||||||||||||||||||||
| 4118 | uint qHash(const QUrl &url, uint seed) Q_DECL_NOTHROW | - | ||||||||||||||||||||||||
| 4119 | { | - | ||||||||||||||||||||||||
| 4120 | if (!url.d)
| 3-7 | ||||||||||||||||||||||||
| 4121 | return qHash(-1, seed); // the hash of an unset port (-1) executed 3 times by 1 test: return qHash(-1, seed);Executed by:
| 3 | ||||||||||||||||||||||||
| 4122 | - | |||||||||||||||||||||||||
| 4123 | return qHash(url.d->scheme) ^ executed 7 times by 1 test: return qHash(url.d->scheme) ^ qHash(url.d->userName) ^ qHash(url.d->password) ^ qHash(url.d->host) ^ qHash(url.d->port, seed) ^ qHash(url.d->path) ^ qHash(url.d->query) ^ qHash(url.d->fragment);Executed by:
| 7 | ||||||||||||||||||||||||
| 4124 | qHash(url.d->userName) ^ executed 7 times by 1 test: return qHash(url.d->scheme) ^ qHash(url.d->userName) ^ qHash(url.d->password) ^ qHash(url.d->host) ^ qHash(url.d->port, seed) ^ qHash(url.d->path) ^ qHash(url.d->query) ^ qHash(url.d->fragment);Executed by:
| 7 | ||||||||||||||||||||||||
| 4125 | qHash(url.d->password) ^ executed 7 times by 1 test: return qHash(url.d->scheme) ^ qHash(url.d->userName) ^ qHash(url.d->password) ^ qHash(url.d->host) ^ qHash(url.d->port, seed) ^ qHash(url.d->path) ^ qHash(url.d->query) ^ qHash(url.d->fragment);Executed by:
| 7 | ||||||||||||||||||||||||
| 4126 | qHash(url.d->host) ^ executed 7 times by 1 test: return qHash(url.d->scheme) ^ qHash(url.d->userName) ^ qHash(url.d->password) ^ qHash(url.d->host) ^ qHash(url.d->port, seed) ^ qHash(url.d->path) ^ qHash(url.d->query) ^ qHash(url.d->fragment);Executed by:
| 7 | ||||||||||||||||||||||||
| 4127 | qHash(url.d->port, seed) ^ executed 7 times by 1 test: return qHash(url.d->scheme) ^ qHash(url.d->userName) ^ qHash(url.d->password) ^ qHash(url.d->host) ^ qHash(url.d->port, seed) ^ qHash(url.d->path) ^ qHash(url.d->query) ^ qHash(url.d->fragment);Executed by:
| 7 | ||||||||||||||||||||||||
| 4128 | qHash(url.d->path) ^ executed 7 times by 1 test: return qHash(url.d->scheme) ^ qHash(url.d->userName) ^ qHash(url.d->password) ^ qHash(url.d->host) ^ qHash(url.d->port, seed) ^ qHash(url.d->path) ^ qHash(url.d->query) ^ qHash(url.d->fragment);Executed by:
| 7 | ||||||||||||||||||||||||
| 4129 | qHash(url.d->query) ^ executed 7 times by 1 test: return qHash(url.d->scheme) ^ qHash(url.d->userName) ^ qHash(url.d->password) ^ qHash(url.d->host) ^ qHash(url.d->port, seed) ^ qHash(url.d->path) ^ qHash(url.d->query) ^ qHash(url.d->fragment);Executed by:
| 7 | ||||||||||||||||||||||||
| 4130 | qHash(url.d->fragment); executed 7 times by 1 test: return qHash(url.d->scheme) ^ qHash(url.d->userName) ^ qHash(url.d->password) ^ qHash(url.d->host) ^ qHash(url.d->port, seed) ^ qHash(url.d->path) ^ qHash(url.d->query) ^ qHash(url.d->fragment);Executed by:
| 7 | ||||||||||||||||||||||||
| 4131 | } | - | ||||||||||||||||||||||||
| 4132 | - | |||||||||||||||||||||||||
| 4133 | static QUrl adjustFtpPath(QUrl url) | - | ||||||||||||||||||||||||
| 4134 | { | - | ||||||||||||||||||||||||
| 4135 | if (url.scheme() == ftpScheme()) {
| 3-31 | ||||||||||||||||||||||||
| 4136 | QString path = url.path(QUrl::PrettyDecoded); | - | ||||||||||||||||||||||||
| 4137 | if (path.startsWith(QLatin1String("//")))
| 1-2 | ||||||||||||||||||||||||
| 4138 | url.setPath(QLatin1String("/%2F") + path.midRef(2), QUrl::TolerantMode); executed 2 times by 1 test: url.setPath(QLatin1String("/%2F") + path.midRef(2), QUrl::TolerantMode);Executed by:
| 2 | ||||||||||||||||||||||||
| 4139 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||||||||
| 4140 | return url; executed 34 times by 2 tests: return url;Executed by:
| 34 | ||||||||||||||||||||||||
| 4141 | } | - | ||||||||||||||||||||||||
| 4142 | - | |||||||||||||||||||||||||
| 4143 | static bool isIp6(const QString &text) | - | ||||||||||||||||||||||||
| 4144 | { | - | ||||||||||||||||||||||||
| 4145 | QIPAddressUtils::IPv6Address address; | - | ||||||||||||||||||||||||
| 4146 | return !text.isEmpty() && QIPAddressUtils::parseIp6(address, text.begin(), text.end()) == 0; executed 104 times by 2 tests: return !text.isEmpty() && QIPAddressUtils::parseIp6(address, text.begin(), text.end()) == 0;Executed by:
| 1-104 | ||||||||||||||||||||||||
| 4147 | } | - | ||||||||||||||||||||||||
| 4148 | - | |||||||||||||||||||||||||
| 4149 | // The following code has the following copyright: | - | ||||||||||||||||||||||||
| 4150 | /* | - | ||||||||||||||||||||||||
| 4151 | Copyright (C) Research In Motion Limited 2009. All rights reserved. | - | ||||||||||||||||||||||||
| 4152 | - | |||||||||||||||||||||||||
| 4153 | Redistribution and use in source and binary forms, with or without | - | ||||||||||||||||||||||||
| 4154 | modification, are permitted provided that the following conditions are met: | - | ||||||||||||||||||||||||
| 4155 | * Redistributions of source code must retain the above copyright | - | ||||||||||||||||||||||||
| 4156 | notice, this list of conditions and the following disclaimer. | - | ||||||||||||||||||||||||
| 4157 | * Redistributions in binary form must reproduce the above copyright | - | ||||||||||||||||||||||||
| 4158 | notice, this list of conditions and the following disclaimer in the | - | ||||||||||||||||||||||||
| 4159 | documentation and/or other materials provided with the distribution. | - | ||||||||||||||||||||||||
| 4160 | * Neither the name of Research In Motion Limited nor the | - | ||||||||||||||||||||||||
| 4161 | contributors may be used to endorse or promote products derived | - | ||||||||||||||||||||||||
| 4162 | derived from this software without specific prior written permission. | - | ||||||||||||||||||||||||
| 4163 | - | |||||||||||||||||||||||||
| 4164 | THIS SOFTWARE IS PROVIDED BY Research In Motion Limited ''AS IS'' AND ANY | - | ||||||||||||||||||||||||
| 4165 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | - | ||||||||||||||||||||||||
| 4166 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | - | ||||||||||||||||||||||||
| 4167 | DISCLAIMED. IN NO EVENT SHALL Research In Motion Limited BE LIABLE FOR ANY | - | ||||||||||||||||||||||||
| 4168 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | - | ||||||||||||||||||||||||
| 4169 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | - | ||||||||||||||||||||||||
| 4170 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | - | ||||||||||||||||||||||||
| 4171 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | - | ||||||||||||||||||||||||
| 4172 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | - | ||||||||||||||||||||||||
| 4173 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | - | ||||||||||||||||||||||||
| 4174 | - | |||||||||||||||||||||||||
| 4175 | */ | - | ||||||||||||||||||||||||
| 4176 | - | |||||||||||||||||||||||||
| 4177 | - | |||||||||||||||||||||||||
| 4178 | /*! | - | ||||||||||||||||||||||||
| 4179 | Returns a valid URL from a user supplied \a userInput string if one can be | - | ||||||||||||||||||||||||
| 4180 | deducted. In the case that is not possible, an invalid QUrl() is returned. | - | ||||||||||||||||||||||||
| 4181 | - | |||||||||||||||||||||||||
| 4182 | This overload takes a \a workingDirectory path, in order to be able to | - | ||||||||||||||||||||||||
| 4183 | handle relative paths. This is especially useful when handling command | - | ||||||||||||||||||||||||
| 4184 | line arguments. | - | ||||||||||||||||||||||||
| 4185 | If \a workingDirectory is empty, no handling of relative paths will be done, | - | ||||||||||||||||||||||||
| 4186 | so this method will behave like its one argument overload. | - | ||||||||||||||||||||||||
| 4187 | - | |||||||||||||||||||||||||
| 4188 | By default, an input string that looks like a relative path will only be treated | - | ||||||||||||||||||||||||
| 4189 | as such if the file actually exists in the given working directory. | - | ||||||||||||||||||||||||
| 4190 | - | |||||||||||||||||||||||||
| 4191 | If the application can handle files that don't exist yet, it should pass the | - | ||||||||||||||||||||||||
| 4192 | flag AssumeLocalFile in \a options. | - | ||||||||||||||||||||||||
| 4193 | - | |||||||||||||||||||||||||
| 4194 | \since 5.4 | - | ||||||||||||||||||||||||
| 4195 | */ | - | ||||||||||||||||||||||||
| 4196 | QUrl QUrl::fromUserInput(const QString &userInput, const QString &workingDirectory, | - | ||||||||||||||||||||||||
| 4197 | UserInputResolutionOptions options) | - | ||||||||||||||||||||||||
| 4198 | { | - | ||||||||||||||||||||||||
| 4199 | QString trimmedString = userInput.trimmed(); | - | ||||||||||||||||||||||||
| 4200 | - | |||||||||||||||||||||||||
| 4201 | if (trimmedString.isEmpty())
| 2-44 | ||||||||||||||||||||||||
| 4202 | return QUrl(); executed 2 times by 1 test: return QUrl();Executed by:
| 2 | ||||||||||||||||||||||||
| 4203 | - | |||||||||||||||||||||||||
| 4204 | - | |||||||||||||||||||||||||
| 4205 | // Check for IPv6 addresses, since a path starting with ":" is absolute (a resource) | - | ||||||||||||||||||||||||
| 4206 | // and IPv6 addresses can start with "c:" too | - | ||||||||||||||||||||||||
| 4207 | if (isIp6(trimmedString)) {
| 12-32 | ||||||||||||||||||||||||
| 4208 | QUrl url; | - | ||||||||||||||||||||||||
| 4209 | url.setHost(trimmedString); | - | ||||||||||||||||||||||||
| 4210 | url.setScheme(QStringLiteral("http")); executed 12 times by 1 test: return qstring_literal_temp;Executed by:
| 12 | ||||||||||||||||||||||||
| 4211 | return url; executed 12 times by 1 test: return url;Executed by:
| 12 | ||||||||||||||||||||||||
| 4212 | } | - | ||||||||||||||||||||||||
| 4213 | - | |||||||||||||||||||||||||
| 4214 | QUrl url = QUrl(trimmedString, QUrl::TolerantMode); | - | ||||||||||||||||||||||||
| 4215 | // Check both QUrl::isRelative (to detect full URLs) and QDir::isAbsolutePath (since on Windows drive letters can be interpreted as schemes) | - | ||||||||||||||||||||||||
| 4216 | if (url.isRelative() && !QDir::isAbsolutePath(trimmedString)) {
| 2-30 | ||||||||||||||||||||||||
| 4217 | QFileInfo fileInfo(QDir(workingDirectory), trimmedString); | - | ||||||||||||||||||||||||
| 4218 | if ((options & AssumeLocalFile) || fileInfo.exists())
| 3-11 | ||||||||||||||||||||||||
| 4219 | return QUrl::fromLocalFile(fileInfo.absoluteFilePath()); executed 25 times by 1 test: return QUrl::fromLocalFile(fileInfo.absoluteFilePath());Executed by:
| 25 | ||||||||||||||||||||||||
| 4220 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||||||||
| 4221 | - | |||||||||||||||||||||||||
| 4222 | return fromUserInput(trimmedString); executed 7 times by 1 test: return fromUserInput(trimmedString);Executed by:
| 7 | ||||||||||||||||||||||||
| 4223 | } | - | ||||||||||||||||||||||||
| 4224 | - | |||||||||||||||||||||||||
| 4225 | /*! | - | ||||||||||||||||||||||||
| 4226 | Returns a valid URL from a user supplied \a userInput string if one can be | - | ||||||||||||||||||||||||
| 4227 | deducted. In the case that is not possible, an invalid QUrl() is returned. | - | ||||||||||||||||||||||||
| 4228 | - | |||||||||||||||||||||||||
| 4229 | \since 4.6 | - | ||||||||||||||||||||||||
| 4230 | - | |||||||||||||||||||||||||
| 4231 | Most applications that can browse the web, allow the user to input a URL | - | ||||||||||||||||||||||||
| 4232 | in the form of a plain string. This string can be manually typed into | - | ||||||||||||||||||||||||
| 4233 | a location bar, obtained from the clipboard, or passed in via command | - | ||||||||||||||||||||||||
| 4234 | line arguments. | - | ||||||||||||||||||||||||
| 4235 | - | |||||||||||||||||||||||||
| 4236 | When the string is not already a valid URL, a best guess is performed, | - | ||||||||||||||||||||||||
| 4237 | making various web related assumptions. | - | ||||||||||||||||||||||||
| 4238 | - | |||||||||||||||||||||||||
| 4239 | In the case the string corresponds to a valid file path on the system, | - | ||||||||||||||||||||||||
| 4240 | a file:// URL is constructed, using QUrl::fromLocalFile(). | - | ||||||||||||||||||||||||
| 4241 | - | |||||||||||||||||||||||||
| 4242 | If that is not the case, an attempt is made to turn the string into a | - | ||||||||||||||||||||||||
| 4243 | http:// or ftp:// URL. The latter in the case the string starts with | - | ||||||||||||||||||||||||
| 4244 | 'ftp'. The result is then passed through QUrl's tolerant parser, and | - | ||||||||||||||||||||||||
| 4245 | in the case or success, a valid QUrl is returned, or else a QUrl(). | - | ||||||||||||||||||||||||
| 4246 | - | |||||||||||||||||||||||||
| 4247 | \section1 Examples: | - | ||||||||||||||||||||||||
| 4248 | - | |||||||||||||||||||||||||
| 4249 | \list | - | ||||||||||||||||||||||||
| 4250 | \li qt-project.org becomes http://qt-project.org | - | ||||||||||||||||||||||||
| 4251 | \li ftp.qt-project.org becomes ftp://ftp.qt-project.org | - | ||||||||||||||||||||||||
| 4252 | \li hostname becomes http://hostname | - | ||||||||||||||||||||||||
| 4253 | \li /home/user/test.html becomes file:///home/user/test.html | - | ||||||||||||||||||||||||
| 4254 | \endlist | - | ||||||||||||||||||||||||
| 4255 | */ | - | ||||||||||||||||||||||||
| 4256 | QUrl QUrl::fromUserInput(const QString &userInput) | - | ||||||||||||||||||||||||
| 4257 | { | - | ||||||||||||||||||||||||
| 4258 | QString trimmedString = userInput.trimmed(); | - | ||||||||||||||||||||||||
| 4259 | - | |||||||||||||||||||||||||
| 4260 | // Check for IPv6 addresses, since a path starting with ":" is absolute (a resource) | - | ||||||||||||||||||||||||
| 4261 | // and IPv6 addresses can start with "c:" too | - | ||||||||||||||||||||||||
| 4262 | if (isIp6(trimmedString)) {
| 6-54 | ||||||||||||||||||||||||
| 4263 | QUrl url; | - | ||||||||||||||||||||||||
| 4264 | url.setHost(trimmedString); | - | ||||||||||||||||||||||||
| 4265 | url.setScheme(QStringLiteral("http")); executed 6 times by 1 test: return qstring_literal_temp;Executed by:
| 6 | ||||||||||||||||||||||||
| 4266 | return url; executed 6 times by 1 test: return url;Executed by:
| 6 | ||||||||||||||||||||||||
| 4267 | } | - | ||||||||||||||||||||||||
| 4268 | - | |||||||||||||||||||||||||
| 4269 | // Check first for files, since on Windows drive letters can be interpretted as schemes | - | ||||||||||||||||||||||||
| 4270 | if (QDir::isAbsolutePath(trimmedString))
| 19-35 | ||||||||||||||||||||||||
| 4271 | return QUrl::fromLocalFile(trimmedString); executed 19 times by 1 test: return QUrl::fromLocalFile(trimmedString);Executed by:
| 19 | ||||||||||||||||||||||||
| 4272 | - | |||||||||||||||||||||||||
| 4273 | QUrl url = QUrl(trimmedString, QUrl::TolerantMode); | - | ||||||||||||||||||||||||
| 4274 | QUrl urlPrepended = QUrl(QStringLiteral("http://") + trimmedString, QUrl::TolerantMode); executed 35 times by 2 tests: return qstring_literal_temp;Executed by:
| 35 | ||||||||||||||||||||||||
| 4275 | - | |||||||||||||||||||||||||
| 4276 | // Check the most common case of a valid url with a scheme | - | ||||||||||||||||||||||||
| 4277 | // We check if the port would be valid by adding the scheme to handle the case host:port | - | ||||||||||||||||||||||||
| 4278 | // where the host would be interpretted as the scheme | - | ||||||||||||||||||||||||
| 4279 | if (url.isValid()
| 1-34 | ||||||||||||||||||||||||
| 4280 | && !url.scheme().isEmpty()
| 16-18 | ||||||||||||||||||||||||
| 4281 | && urlPrepended.port() == -1)
| 3-15 | ||||||||||||||||||||||||
| 4282 | return adjustFtpPath(url); executed 15 times by 2 tests: return adjustFtpPath(url);Executed by:
| 15 | ||||||||||||||||||||||||
| 4283 | - | |||||||||||||||||||||||||
| 4284 | // Else, try the prepended one and adjust the scheme from the host name | - | ||||||||||||||||||||||||
| 4285 | if (urlPrepended.isValid() && (!urlPrepended.host().isEmpty() || !urlPrepended.path().isEmpty()))
| 0-20 | ||||||||||||||||||||||||
| 4286 | { | - | ||||||||||||||||||||||||
| 4287 | int dotIndex = trimmedString.indexOf(QLatin1Char('.')); | - | ||||||||||||||||||||||||
| 4288 | const QString hostscheme = trimmedString.left(dotIndex).toLower(); | - | ||||||||||||||||||||||||
| 4289 | if (hostscheme == ftpScheme())
| 2-17 | ||||||||||||||||||||||||
| 4290 | urlPrepended.setScheme(ftpScheme()); executed 2 times by 1 test: urlPrepended.setScheme(ftpScheme());Executed by:
| 2 | ||||||||||||||||||||||||
| 4291 | return adjustFtpPath(urlPrepended); executed 19 times by 1 test: return adjustFtpPath(urlPrepended);Executed by:
| 19 | ||||||||||||||||||||||||
| 4292 | } | - | ||||||||||||||||||||||||
| 4293 | - | |||||||||||||||||||||||||
| 4294 | return QUrl(); executed 1 time by 1 test: return QUrl();Executed by:
| 1 | ||||||||||||||||||||||||
| 4295 | } | - | ||||||||||||||||||||||||
| 4296 | // end of BSD code | - | ||||||||||||||||||||||||
| 4297 | - | |||||||||||||||||||||||||
| 4298 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |