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) 2016 The Qt Company Ltd. | - | ||||||||||||||||||
4 | ** Copyright (C) 2016 Intel Corporation. | - | ||||||||||||||||||
5 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||
6 | ** | - | ||||||||||||||||||
7 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||
8 | ** | - | ||||||||||||||||||
9 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||
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 https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
16 | ** information use the contact form at https://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 3 as published by the Free Software | - | ||||||||||||||||||
21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||
22 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||
23 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||
24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||
25 | ** | - | ||||||||||||||||||
26 | ** GNU General Public License Usage | - | ||||||||||||||||||
27 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||
28 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||
29 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||
30 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||
31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||
32 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||
33 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||
34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||
35 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||
36 | ** | - | ||||||||||||||||||
37 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
38 | ** | - | ||||||||||||||||||
39 | ****************************************************************************/ | - | ||||||||||||||||||
40 | - | |||||||||||||||||||
41 | /*! | - | ||||||||||||||||||
42 | \class QUrl | - | ||||||||||||||||||
43 | \inmodule QtCore | - | ||||||||||||||||||
44 | - | |||||||||||||||||||
45 | \brief The QUrl class provides a convenient interface for working | - | ||||||||||||||||||
46 | with URLs. | - | ||||||||||||||||||
47 | - | |||||||||||||||||||
48 | \reentrant | - | ||||||||||||||||||
49 | \ingroup io | - | ||||||||||||||||||
50 | \ingroup network | - | ||||||||||||||||||
51 | \ingroup shared | - | ||||||||||||||||||
52 | - | |||||||||||||||||||
53 | - | |||||||||||||||||||
54 | It can parse and construct URLs in both encoded and unencoded | - | ||||||||||||||||||
55 | form. QUrl also has support for internationalized domain names | - | ||||||||||||||||||
56 | (IDNs). | - | ||||||||||||||||||
57 | - | |||||||||||||||||||
58 | The most common way to use QUrl is to initialize it via the | - | ||||||||||||||||||
59 | constructor by passing a QString. Otherwise, setUrl() can also | - | ||||||||||||||||||
60 | be used. | - | ||||||||||||||||||
61 | - | |||||||||||||||||||
62 | URLs can be represented in two forms: encoded or unencoded. The | - | ||||||||||||||||||
63 | unencoded representation is suitable for showing to users, but | - | ||||||||||||||||||
64 | the encoded representation is typically what you would send to | - | ||||||||||||||||||
65 | a web server. For example, the unencoded URL | - | ||||||||||||||||||
66 | "http://bühler.example.com/List of applicants.xml" | - | ||||||||||||||||||
67 | would be sent to the server as | - | ||||||||||||||||||
68 | "http://xn--bhler-kva.example.com/List%20of%20applicants.xml". | - | ||||||||||||||||||
69 | - | |||||||||||||||||||
70 | A URL can also be constructed piece by piece by calling | - | ||||||||||||||||||
71 | setScheme(), setUserName(), setPassword(), setHost(), setPort(), | - | ||||||||||||||||||
72 | setPath(), setQuery() and setFragment(). Some convenience | - | ||||||||||||||||||
73 | functions are also available: setAuthority() sets the user name, | - | ||||||||||||||||||
74 | password, host and port. setUserInfo() sets the user name and | - | ||||||||||||||||||
75 | password at once. | - | ||||||||||||||||||
76 | - | |||||||||||||||||||
77 | Call isValid() to check if the URL is valid. This can be done at any point | - | ||||||||||||||||||
78 | during the constructing of a URL. If isValid() returns \c false, you should | - | ||||||||||||||||||
79 | clear() the URL before proceeding, or start over by parsing a new URL with | - | ||||||||||||||||||
80 | setUrl(). | - | ||||||||||||||||||
81 | - | |||||||||||||||||||
82 | Constructing a query is particularly convenient through the use of the \l | - | ||||||||||||||||||
83 | QUrlQuery class and its methods QUrlQuery::setQueryItems(), | - | ||||||||||||||||||
84 | QUrlQuery::addQueryItem() and QUrlQuery::removeQueryItem(). Use | - | ||||||||||||||||||
85 | QUrlQuery::setQueryDelimiters() to customize the delimiters used for | - | ||||||||||||||||||
86 | generating the query string. | - | ||||||||||||||||||
87 | - | |||||||||||||||||||
88 | For the convenience of generating encoded URL strings or query | - | ||||||||||||||||||
89 | strings, there are two static functions called | - | ||||||||||||||||||
90 | fromPercentEncoding() and toPercentEncoding() which deal with | - | ||||||||||||||||||
91 | percent encoding and decoding of QString objects. | - | ||||||||||||||||||
92 | - | |||||||||||||||||||
93 | Calling isRelative() will tell whether or not the URL is | - | ||||||||||||||||||
94 | relative. A relative URL can be resolved by passing it as argument | - | ||||||||||||||||||
95 | to resolved(), which returns an absolute URL. isParentOf() is used | - | ||||||||||||||||||
96 | for determining whether one URL is a parent of another. | - | ||||||||||||||||||
97 | - | |||||||||||||||||||
98 | fromLocalFile() constructs a QUrl by parsing a local | - | ||||||||||||||||||
99 | file path. toLocalFile() converts a URL to a local file path. | - | ||||||||||||||||||
100 | - | |||||||||||||||||||
101 | The human readable representation of the URL is fetched with | - | ||||||||||||||||||
102 | toString(). This representation is appropriate for displaying a | - | ||||||||||||||||||
103 | URL to a user in unencoded form. The encoded form however, as | - | ||||||||||||||||||
104 | returned by toEncoded(), is for internal use, passing to web | - | ||||||||||||||||||
105 | servers, mail clients and so on. Both forms are technically correct | - | ||||||||||||||||||
106 | and represent the same URL unambiguously -- in fact, passing either | - | ||||||||||||||||||
107 | form to QUrl's constructor or to setUrl() will yield the same QUrl | - | ||||||||||||||||||
108 | object. | - | ||||||||||||||||||
109 | - | |||||||||||||||||||
110 | QUrl conforms to the URI specification from | - | ||||||||||||||||||
111 | \l{RFC 3986} (Uniform Resource Identifier: Generic Syntax), and includes | - | ||||||||||||||||||
112 | scheme extensions from \l{RFC 1738} (Uniform Resource Locators). Case | - | ||||||||||||||||||
113 | folding rules in QUrl conform to \l{RFC 3491} (Nameprep: A Stringprep | - | ||||||||||||||||||
114 | Profile for Internationalized Domain Names (IDN)). It is also compatible with the | - | ||||||||||||||||||
115 | \l{http://freedesktop.org/wiki/Specifications/file-uri-spec/}{file URI specification} | - | ||||||||||||||||||
116 | from freedesktop.org, provided that the locale encodes file names using | - | ||||||||||||||||||
117 | UTF-8 (required by IDN). | - | ||||||||||||||||||
118 | - | |||||||||||||||||||
119 | \section2 Error checking | - | ||||||||||||||||||
120 | - | |||||||||||||||||||
121 | QUrl is capable of detecting many errors in URLs while parsing it or when | - | ||||||||||||||||||
122 | components of the URL are set with individual setter methods (like | - | ||||||||||||||||||
123 | setScheme(), setHost() or setPath()). If the parsing or setter function is | - | ||||||||||||||||||
124 | successful, any previously recorded error conditions will be discarded. | - | ||||||||||||||||||
125 | - | |||||||||||||||||||
126 | By default, QUrl setter methods operate in QUrl::TolerantMode, which means | - | ||||||||||||||||||
127 | they accept some common mistakes and mis-representation of data. An | - | ||||||||||||||||||
128 | alternate method of parsing is QUrl::StrictMode, which applies further | - | ||||||||||||||||||
129 | checks. See QUrl::ParsingMode for a description of the difference of the | - | ||||||||||||||||||
130 | parsing modes. | - | ||||||||||||||||||
131 | - | |||||||||||||||||||
132 | QUrl only checks for conformance with the URL specification. It does not | - | ||||||||||||||||||
133 | try to verify that high-level protocol URLs are in the format they are | - | ||||||||||||||||||
134 | expected to be by handlers elsewhere. For example, the following URIs are | - | ||||||||||||||||||
135 | all considered valid by QUrl, even if they do not make sense when used: | - | ||||||||||||||||||
136 | - | |||||||||||||||||||
137 | \list | - | ||||||||||||||||||
138 | \li "http:/filename.html" | - | ||||||||||||||||||
139 | \li "mailto://example.com" | - | ||||||||||||||||||
140 | \endlist | - | ||||||||||||||||||
141 | - | |||||||||||||||||||
142 | When the parser encounters an error, it signals the event by making | - | ||||||||||||||||||
143 | isValid() return false and toString() / toEncoded() return an empty string. | - | ||||||||||||||||||
144 | If it is necessary to show the user the reason why the URL failed to parse, | - | ||||||||||||||||||
145 | the error condition can be obtained from QUrl by calling errorString(). | - | ||||||||||||||||||
146 | Note that this message is highly technical and may not make sense to | - | ||||||||||||||||||
147 | end-users. | - | ||||||||||||||||||
148 | - | |||||||||||||||||||
149 | QUrl is capable of recording only one error condition. If more than one | - | ||||||||||||||||||
150 | error is found, it is undefined which error is reported. | - | ||||||||||||||||||
151 | - | |||||||||||||||||||
152 | \section2 Character Conversions | - | ||||||||||||||||||
153 | - | |||||||||||||||||||
154 | Follow these rules to avoid erroneous character conversion when | - | ||||||||||||||||||
155 | dealing with URLs and strings: | - | ||||||||||||||||||
156 | - | |||||||||||||||||||
157 | \list | - | ||||||||||||||||||
158 | \li When creating a QString to contain a URL from a QByteArray or a | - | ||||||||||||||||||
159 | char*, always use QString::fromUtf8(). | - | ||||||||||||||||||
160 | \endlist | - | ||||||||||||||||||
161 | */ | - | ||||||||||||||||||
162 | - | |||||||||||||||||||
163 | /*! | - | ||||||||||||||||||
164 | \enum QUrl::ParsingMode | - | ||||||||||||||||||
165 | - | |||||||||||||||||||
166 | The parsing mode controls the way QUrl parses strings. | - | ||||||||||||||||||
167 | - | |||||||||||||||||||
168 | \value TolerantMode QUrl will try to correct some common errors in URLs. | - | ||||||||||||||||||
169 | This mode is useful for parsing URLs coming from sources | - | ||||||||||||||||||
170 | not known to be strictly standards-conforming. | - | ||||||||||||||||||
171 | - | |||||||||||||||||||
172 | \value StrictMode Only valid URLs are accepted. This mode is useful for | - | ||||||||||||||||||
173 | general URL validation. | - | ||||||||||||||||||
174 | - | |||||||||||||||||||
175 | \value DecodedMode QUrl will interpret the URL component in the fully-decoded form, | - | ||||||||||||||||||
176 | where percent characters stand for themselves, not as the beginning | - | ||||||||||||||||||
177 | of a percent-encoded sequence. This mode is only valid for the | - | ||||||||||||||||||
178 | setters setting components of a URL; it is not permitted in | - | ||||||||||||||||||
179 | the QUrl constructor, in fromEncoded() or in setUrl(). | - | ||||||||||||||||||
180 | For more information on this mode, see the documentation for | - | ||||||||||||||||||
181 | \l {QUrl::ComponentFormattingOption}{QUrl::FullyDecoded}. | - | ||||||||||||||||||
182 | - | |||||||||||||||||||
183 | In TolerantMode, the parser has the following behaviour: | - | ||||||||||||||||||
184 | - | |||||||||||||||||||
185 | \list | - | ||||||||||||||||||
186 | - | |||||||||||||||||||
187 | \li Spaces and "%20": unencoded space characters will be accepted and will | - | ||||||||||||||||||
188 | be treated as equivalent to "%20". | - | ||||||||||||||||||
189 | - | |||||||||||||||||||
190 | \li Single "%" characters: Any occurrences of a percent character "%" not | - | ||||||||||||||||||
191 | followed by exactly two hexadecimal characters (e.g., "13% coverage.html") | - | ||||||||||||||||||
192 | will be replaced by "%25". Note that one lone "%" character will trigger | - | ||||||||||||||||||
193 | the correction mode for all percent characters. | - | ||||||||||||||||||
194 | - | |||||||||||||||||||
195 | \li Reserved and unreserved characters: An encoded URL should only | - | ||||||||||||||||||
196 | contain a few characters as literals; all other characters should | - | ||||||||||||||||||
197 | be percent-encoded. In TolerantMode, these characters will be | - | ||||||||||||||||||
198 | accepted if they are found in the URL: | - | ||||||||||||||||||
199 | space / double-quote / "<" / ">" / "\" / | - | ||||||||||||||||||
200 | "^" / "`" / "{" / "|" / "}" | - | ||||||||||||||||||
201 | Those same characters can be decoded again by passing QUrl::DecodeReserved | - | ||||||||||||||||||
202 | to toString() or toEncoded(). In the getters of individual components, | - | ||||||||||||||||||
203 | those characters are often returned in decoded form. | - | ||||||||||||||||||
204 | - | |||||||||||||||||||
205 | \endlist | - | ||||||||||||||||||
206 | - | |||||||||||||||||||
207 | When in StrictMode, if a parsing error is found, isValid() will return \c | - | ||||||||||||||||||
208 | false and errorString() will return a message describing the error. | - | ||||||||||||||||||
209 | If more than one error is detected, it is undefined which error gets | - | ||||||||||||||||||
210 | reported. | - | ||||||||||||||||||
211 | - | |||||||||||||||||||
212 | Note that TolerantMode is not usually enough for parsing user input, which | - | ||||||||||||||||||
213 | often contains more errors and expectations than the parser can deal with. | - | ||||||||||||||||||
214 | When dealing with data coming directly from the user -- as opposed to data | - | ||||||||||||||||||
215 | coming from data-transfer sources, such as other programs -- it is | - | ||||||||||||||||||
216 | recommended to use fromUserInput(). | - | ||||||||||||||||||
217 | - | |||||||||||||||||||
218 | \sa fromUserInput(), setUrl(), toString(), toEncoded(), QUrl::FormattingOptions | - | ||||||||||||||||||
219 | */ | - | ||||||||||||||||||
220 | - | |||||||||||||||||||
221 | /*! | - | ||||||||||||||||||
222 | \enum QUrl::UrlFormattingOption | - | ||||||||||||||||||
223 | - | |||||||||||||||||||
224 | The formatting options define how the URL is formatted when written out | - | ||||||||||||||||||
225 | as text. | - | ||||||||||||||||||
226 | - | |||||||||||||||||||
227 | \value None The format of the URL is unchanged. | - | ||||||||||||||||||
228 | \value RemoveScheme The scheme is removed from the URL. | - | ||||||||||||||||||
229 | \value RemovePassword Any password in the URL is removed. | - | ||||||||||||||||||
230 | \value RemoveUserInfo Any user information in the URL is removed. | - | ||||||||||||||||||
231 | \value RemovePort Any specified port is removed from the URL. | - | ||||||||||||||||||
232 | \value RemoveAuthority | - | ||||||||||||||||||
233 | \value RemovePath The URL's path is removed, leaving only the scheme, | - | ||||||||||||||||||
234 | host address, and port (if present). | - | ||||||||||||||||||
235 | \value RemoveQuery The query part of the URL (following a '?' character) | - | ||||||||||||||||||
236 | is removed. | - | ||||||||||||||||||
237 | \value RemoveFragment | - | ||||||||||||||||||
238 | \value RemoveFilename The filename (i.e. everything after the last '/' in the path) is removed. | - | ||||||||||||||||||
239 | The trailing '/' is kept, unless StripTrailingSlash is set. | - | ||||||||||||||||||
240 | Only valid if RemovePath is not set. | - | ||||||||||||||||||
241 | \value PreferLocalFile If the URL is a local file according to isLocalFile() | - | ||||||||||||||||||
242 | and contains no query or fragment, a local file path is returned. | - | ||||||||||||||||||
243 | \value StripTrailingSlash The trailing slash is removed if one is present. | - | ||||||||||||||||||
244 | \value NormalizePathSegments Modifies the path to remove redundant directory separators, | - | ||||||||||||||||||
245 | and to resolve "."s and ".."s (as far as possible). | - | ||||||||||||||||||
246 | - | |||||||||||||||||||
247 | Note that the case folding rules in \l{RFC 3491}{Nameprep}, which QUrl | - | ||||||||||||||||||
248 | conforms to, require host names to always be converted to lower case, | - | ||||||||||||||||||
249 | regardless of the Qt::FormattingOptions used. | - | ||||||||||||||||||
250 | - | |||||||||||||||||||
251 | The options from QUrl::ComponentFormattingOptions are also possible. | - | ||||||||||||||||||
252 | - | |||||||||||||||||||
253 | \sa QUrl::ComponentFormattingOptions | - | ||||||||||||||||||
254 | */ | - | ||||||||||||||||||
255 | - | |||||||||||||||||||
256 | /*! | - | ||||||||||||||||||
257 | \enum QUrl::ComponentFormattingOption | - | ||||||||||||||||||
258 | \since 5.0 | - | ||||||||||||||||||
259 | - | |||||||||||||||||||
260 | The component formatting options define how the components of an URL will | - | ||||||||||||||||||
261 | be formatted when written out as text. They can be combined with the | - | ||||||||||||||||||
262 | options from QUrl::FormattingOptions when used in toString() and | - | ||||||||||||||||||
263 | toEncoded(). | - | ||||||||||||||||||
264 | - | |||||||||||||||||||
265 | \value PrettyDecoded The component is returned in a "pretty form", with | - | ||||||||||||||||||
266 | most percent-encoded characters decoded. The exact | - | ||||||||||||||||||
267 | behavior of PrettyDecoded varies from component to | - | ||||||||||||||||||
268 | component and may also change from Qt release to Qt | - | ||||||||||||||||||
269 | release. This is the default. | - | ||||||||||||||||||
270 | - | |||||||||||||||||||
271 | \value EncodeSpaces Leave space characters in their encoded form ("%20"). | - | ||||||||||||||||||
272 | - | |||||||||||||||||||
273 | \value EncodeUnicode Leave non-US-ASCII characters encoded in their UTF-8 | - | ||||||||||||||||||
274 | percent-encoded form (e.g., "%C3%A9" for the U+00E9 | - | ||||||||||||||||||
275 | codepoint, LATIN SMALL LETTER E WITH ACUTE). | - | ||||||||||||||||||
276 | - | |||||||||||||||||||
277 | \value EncodeDelimiters Leave certain delimiters in their encoded form, as | - | ||||||||||||||||||
278 | would appear in the URL when the full URL is | - | ||||||||||||||||||
279 | represented as text. The delimiters are affected | - | ||||||||||||||||||
280 | by this option change from component to component. | - | ||||||||||||||||||
281 | This flag has no effect in toString() or toEncoded(). | - | ||||||||||||||||||
282 | - | |||||||||||||||||||
283 | \value EncodeReserved Leave US-ASCII characters not permitted in the URL by | - | ||||||||||||||||||
284 | the specification in their encoded form. This is the | - | ||||||||||||||||||
285 | default on toString() and toEncoded(). | - | ||||||||||||||||||
286 | - | |||||||||||||||||||
287 | \value DecodeReserved Decode the US-ASCII characters that the URL specification | - | ||||||||||||||||||
288 | does not allow to appear in the URL. This is the | - | ||||||||||||||||||
289 | default on the getters of individual components. | - | ||||||||||||||||||
290 | - | |||||||||||||||||||
291 | \value FullyEncoded Leave all characters in their properly-encoded form, | - | ||||||||||||||||||
292 | as this component would appear as part of a URL. When | - | ||||||||||||||||||
293 | used with toString(), this produces a fully-compliant | - | ||||||||||||||||||
294 | URL in QString form, exactly equal to the result of | - | ||||||||||||||||||
295 | toEncoded() | - | ||||||||||||||||||
296 | - | |||||||||||||||||||
297 | \value FullyDecoded Attempt to decode as much as possible. For individual | - | ||||||||||||||||||
298 | components of the URL, this decodes every percent | - | ||||||||||||||||||
299 | encoding sequence, including control characters (U+0000 | - | ||||||||||||||||||
300 | to U+001F) and UTF-8 sequences found in percent-encoded form. | - | ||||||||||||||||||
301 | Use of this mode may cause data loss, see below for more information. | - | ||||||||||||||||||
302 | - | |||||||||||||||||||
303 | The values of EncodeReserved and DecodeReserved should not be used together | - | ||||||||||||||||||
304 | in one call. The behavior is undefined if that happens. They are provided | - | ||||||||||||||||||
305 | as separate values because the behavior of the "pretty mode" with regards | - | ||||||||||||||||||
306 | to reserved characters is different on certain components and specially on | - | ||||||||||||||||||
307 | the full URL. | - | ||||||||||||||||||
308 | - | |||||||||||||||||||
309 | \section2 Full decoding | - | ||||||||||||||||||
310 | - | |||||||||||||||||||
311 | The FullyDecoded mode is similar to the behavior of the functions returning | - | ||||||||||||||||||
312 | QString in Qt 4.x, in that every character represents itself and never has | - | ||||||||||||||||||
313 | any special meaning. This is true even for the percent character ('%'), | - | ||||||||||||||||||
314 | which should be interpreted to mean a literal percent, not the beginning of | - | ||||||||||||||||||
315 | a percent-encoded sequence. The same actual character, in all other | - | ||||||||||||||||||
316 | decoding modes, is represented by the sequence "%25". | - | ||||||||||||||||||
317 | - | |||||||||||||||||||
318 | Whenever re-applying data obtained with QUrl::FullyDecoded into a QUrl, | - | ||||||||||||||||||
319 | care must be taken to use the QUrl::DecodedMode parameter to the setters | - | ||||||||||||||||||
320 | (like setPath() and setUserName()). Failure to do so may cause | - | ||||||||||||||||||
321 | re-interpretation of the percent character ('%') as the beginning of a | - | ||||||||||||||||||
322 | percent-encoded sequence. | - | ||||||||||||||||||
323 | - | |||||||||||||||||||
324 | This mode is quite useful when portions of a URL are used in a non-URL | - | ||||||||||||||||||
325 | context. For example, to extract the username, password or file paths in an | - | ||||||||||||||||||
326 | FTP client application, the FullyDecoded mode should be used. | - | ||||||||||||||||||
327 | - | |||||||||||||||||||
328 | This mode should be used with care, since there are two conditions that | - | ||||||||||||||||||
329 | cannot be reliably represented in the returned QString. They are: | - | ||||||||||||||||||
330 | - | |||||||||||||||||||
331 | \list | - | ||||||||||||||||||
332 | \li \b{Non-UTF-8 sequences:} URLs may contain sequences of | - | ||||||||||||||||||
333 | percent-encoded characters that do not form valid UTF-8 sequences. Since | - | ||||||||||||||||||
334 | URLs need to be decoded using UTF-8, any decoder failure will result in | - | ||||||||||||||||||
335 | the QString containing one or more replacement characters where the | - | ||||||||||||||||||
336 | sequence existed. | - | ||||||||||||||||||
337 | - | |||||||||||||||||||
338 | \li \b{Encoded delimiters:} URLs are also allowed to make a distinction | - | ||||||||||||||||||
339 | between a delimiter found in its literal form and its equivalent in | - | ||||||||||||||||||
340 | percent-encoded form. This is most commonly found in the query, but is | - | ||||||||||||||||||
341 | permitted in most parts of the URL. | - | ||||||||||||||||||
342 | \endlist | - | ||||||||||||||||||
343 | - | |||||||||||||||||||
344 | The following example illustrates the problem: | - | ||||||||||||||||||
345 | - | |||||||||||||||||||
346 | \code | - | ||||||||||||||||||
347 | QUrl original("http://example.com/?q=a%2B%3Db%26c"); | - | ||||||||||||||||||
348 | QUrl copy(original); | - | ||||||||||||||||||
349 | copy.setQuery(copy.query(QUrl::FullyDecoded), QUrl::DecodedMode); | - | ||||||||||||||||||
350 | - | |||||||||||||||||||
351 | qDebug() << original.toString(); // prints: http://example.com/?q=a%2B%3Db%26c | - | ||||||||||||||||||
352 | qDebug() << copy.toString(); // prints: http://example.com/?q=a+=b&c | - | ||||||||||||||||||
353 | \endcode | - | ||||||||||||||||||
354 | - | |||||||||||||||||||
355 | If the two URLs were used via HTTP GET, the interpretation by the web | - | ||||||||||||||||||
356 | server would probably be different. In the first case, it would interpret | - | ||||||||||||||||||
357 | as one parameter, with a key of "q" and value "a+=b&c". In the second | - | ||||||||||||||||||
358 | case, it would probably interpret as two parameters, one with a key of "q" | - | ||||||||||||||||||
359 | and value "a =b", and the second with a key "c" and no value. | - | ||||||||||||||||||
360 | - | |||||||||||||||||||
361 | \sa QUrl::FormattingOptions | - | ||||||||||||||||||
362 | */ | - | ||||||||||||||||||
363 | - | |||||||||||||||||||
364 | /*! | - | ||||||||||||||||||
365 | \enum QUrl::UserInputResolutionOption | - | ||||||||||||||||||
366 | \since 5.4 | - | ||||||||||||||||||
367 | - | |||||||||||||||||||
368 | The user input resolution options define how fromUserInput() should | - | ||||||||||||||||||
369 | interpret strings that could either be a relative path or the short | - | ||||||||||||||||||
370 | form of a HTTP URL. For instance \c{file.pl} can be either a local file | - | ||||||||||||||||||
371 | or the URL \c{http://file.pl}. | - | ||||||||||||||||||
372 | - | |||||||||||||||||||
373 | \value DefaultResolution The default resolution mechanism is to check | - | ||||||||||||||||||
374 | whether a local file exists, in the working | - | ||||||||||||||||||
375 | directory given to fromUserInput, and only | - | ||||||||||||||||||
376 | return a local path in that case. Otherwise a URL | - | ||||||||||||||||||
377 | is assumed. | - | ||||||||||||||||||
378 | \value AssumeLocalFile This option makes fromUserInput() always return | - | ||||||||||||||||||
379 | a local path unless the input contains a scheme, such as | - | ||||||||||||||||||
380 | \c{http://file.pl}. This is useful for applications | - | ||||||||||||||||||
381 | such as text editors, which are able to create | - | ||||||||||||||||||
382 | the file if it doesn't exist. | - | ||||||||||||||||||
383 | - | |||||||||||||||||||
384 | \sa fromUserInput() | - | ||||||||||||||||||
385 | */ | - | ||||||||||||||||||
386 | - | |||||||||||||||||||
387 | /*! | - | ||||||||||||||||||
388 | \fn QUrl::QUrl(QUrl &&other) | - | ||||||||||||||||||
389 | - | |||||||||||||||||||
390 | Move-constructs a QUrl instance, making it point at the same | - | ||||||||||||||||||
391 | object that \a other was pointing to. | - | ||||||||||||||||||
392 | - | |||||||||||||||||||
393 | \since 5.2 | - | ||||||||||||||||||
394 | */ | - | ||||||||||||||||||
395 | - | |||||||||||||||||||
396 | /*! | - | ||||||||||||||||||
397 | \fn QUrl &QUrl::operator=(QUrl &&other) | - | ||||||||||||||||||
398 | - | |||||||||||||||||||
399 | Move-assigns \a other to this QUrl instance. | - | ||||||||||||||||||
400 | - | |||||||||||||||||||
401 | \since 5.2 | - | ||||||||||||||||||
402 | */ | - | ||||||||||||||||||
403 | - | |||||||||||||||||||
404 | #include "qurl.h" | - | ||||||||||||||||||
405 | #include "qurl_p.h" | - | ||||||||||||||||||
406 | #include "qplatformdefs.h" | - | ||||||||||||||||||
407 | #include "qstring.h" | - | ||||||||||||||||||
408 | #include "qstringlist.h" | - | ||||||||||||||||||
409 | #include "qdebug.h" | - | ||||||||||||||||||
410 | #include "qhash.h" | - | ||||||||||||||||||
411 | #include "qdir.h" // for QDir::fromNativeSeparators | - | ||||||||||||||||||
412 | #include "qdatastream.h" | - | ||||||||||||||||||
413 | #include "qtldurl_p.h" | - | ||||||||||||||||||
414 | #include "private/qipaddress_p.h" | - | ||||||||||||||||||
415 | #include "qurlquery.h" | - | ||||||||||||||||||
416 | #if defined(Q_OS_WINCE_WM) | - | ||||||||||||||||||
417 | #pragma optimize("g", off) | - | ||||||||||||||||||
418 | #endif | - | ||||||||||||||||||
419 | - | |||||||||||||||||||
420 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
421 | extern QString qt_normalizePathSegments(const QString &name, bool allowUncPaths); // qdir.cpp | - | ||||||||||||||||||
422 | - | |||||||||||||||||||
423 | inline static bool isHex(char c) | - | ||||||||||||||||||
424 | { | - | ||||||||||||||||||
425 | c |= 0x20; | - | ||||||||||||||||||
426 | return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f'); | - | ||||||||||||||||||
427 | } | - | ||||||||||||||||||
428 | - | |||||||||||||||||||
429 | static inline QString ftpScheme() | - | ||||||||||||||||||
430 | { | - | ||||||||||||||||||
431 | return QStringLiteral("ftp"); | - | ||||||||||||||||||
432 | } | - | ||||||||||||||||||
433 | - | |||||||||||||||||||
434 | static inline QString fileScheme() | - | ||||||||||||||||||
435 | { | - | ||||||||||||||||||
436 | return QStringLiteral("file"); | - | ||||||||||||||||||
437 | } | - | ||||||||||||||||||
438 | - | |||||||||||||||||||
439 | static inline QString webDavScheme() | - | ||||||||||||||||||
440 | { | - | ||||||||||||||||||
441 | return QStringLiteral("webdavs"); | - | ||||||||||||||||||
442 | } | - | ||||||||||||||||||
443 | - | |||||||||||||||||||
444 | static inline QString webDavSslTag() | - | ||||||||||||||||||
445 | { | - | ||||||||||||||||||
446 | return QStringLiteral("@SSL"); | - | ||||||||||||||||||
447 | } | - | ||||||||||||||||||
448 | - | |||||||||||||||||||
449 | #ifdef Q_COMPILER_CLASS_ENUM | - | ||||||||||||||||||
450 | # define colon_uchar : uchar | - | ||||||||||||||||||
451 | #else | - | ||||||||||||||||||
452 | # define colon_uchar | - | ||||||||||||||||||
453 | #endif | - | ||||||||||||||||||
454 | - | |||||||||||||||||||
455 | class QUrlPrivate | - | ||||||||||||||||||
456 | { | - | ||||||||||||||||||
457 | public: | - | ||||||||||||||||||
458 | enum Section colon_uchar { | - | ||||||||||||||||||
459 | Scheme = 0x01, | - | ||||||||||||||||||
460 | UserName = 0x02, | - | ||||||||||||||||||
461 | Password = 0x04, | - | ||||||||||||||||||
462 | UserInfo = UserName | Password, | - | ||||||||||||||||||
463 | Host = 0x08, | - | ||||||||||||||||||
464 | Port = 0x10, | - | ||||||||||||||||||
465 | Authority = UserInfo | Host | Port, | - | ||||||||||||||||||
466 | Path = 0x20, | - | ||||||||||||||||||
467 | Hierarchy = Authority | Path, | - | ||||||||||||||||||
468 | Query = 0x40, | - | ||||||||||||||||||
469 | Fragment = 0x80, | - | ||||||||||||||||||
470 | FullUrl = 0xff | - | ||||||||||||||||||
471 | }; | - | ||||||||||||||||||
472 | - | |||||||||||||||||||
473 | enum Flags colon_uchar { | - | ||||||||||||||||||
474 | IsLocalFile = 0x01 | - | ||||||||||||||||||
475 | }; | - | ||||||||||||||||||
476 | - | |||||||||||||||||||
477 | enum ErrorCode { | - | ||||||||||||||||||
478 | // the high byte of the error code matches the Section | - | ||||||||||||||||||
479 | // the first item in each value must be the generic "Invalid xxx Error" | - | ||||||||||||||||||
480 | InvalidSchemeError = Scheme << 8, | - | ||||||||||||||||||
481 | - | |||||||||||||||||||
482 | InvalidUserNameError = UserName << 8, | - | ||||||||||||||||||
483 | - | |||||||||||||||||||
484 | InvalidPasswordError = Password << 8, | - | ||||||||||||||||||
485 | - | |||||||||||||||||||
486 | InvalidRegNameError = Host << 8, | - | ||||||||||||||||||
487 | InvalidIPv4AddressError, | - | ||||||||||||||||||
488 | InvalidIPv6AddressError, | - | ||||||||||||||||||
489 | InvalidCharacterInIPv6Error, | - | ||||||||||||||||||
490 | InvalidIPvFutureError, | - | ||||||||||||||||||
491 | HostMissingEndBracket, | - | ||||||||||||||||||
492 | - | |||||||||||||||||||
493 | InvalidPortError = Port << 8, | - | ||||||||||||||||||
494 | PortEmptyError, | - | ||||||||||||||||||
495 | - | |||||||||||||||||||
496 | InvalidPathError = Path << 8, | - | ||||||||||||||||||
497 | - | |||||||||||||||||||
498 | InvalidQueryError = Query << 8, | - | ||||||||||||||||||
499 | - | |||||||||||||||||||
500 | InvalidFragmentError = Fragment << 8, | - | ||||||||||||||||||
501 | - | |||||||||||||||||||
502 | // the following two cases are only possible in combination | - | ||||||||||||||||||
503 | // with presence/absence of the authority and scheme. See validityError(). | - | ||||||||||||||||||
504 | AuthorityPresentAndPathIsRelative = Authority << 8 | Path << 8 | 0x10000, | - | ||||||||||||||||||
505 | RelativeUrlPathContainsColonBeforeSlash = Scheme << 8 | Authority << 8 | Path << 8 | 0x10000, | - | ||||||||||||||||||
506 | - | |||||||||||||||||||
507 | NoError = 0 | - | ||||||||||||||||||
508 | }; | - | ||||||||||||||||||
509 | - | |||||||||||||||||||
510 | struct Error { | - | ||||||||||||||||||
511 | QString source; | - | ||||||||||||||||||
512 | ErrorCode code; | - | ||||||||||||||||||
513 | int position; | - | ||||||||||||||||||
514 | }; | - | ||||||||||||||||||
515 | - | |||||||||||||||||||
516 | QUrlPrivate(); | - | ||||||||||||||||||
517 | QUrlPrivate(const QUrlPrivate ©); | - | ||||||||||||||||||
518 | ~QUrlPrivate(); | - | ||||||||||||||||||
519 | - | |||||||||||||||||||
520 | void parse(const QString &url, QUrl::ParsingMode parsingMode); | - | ||||||||||||||||||
521 | bool isEmpty() const | - | ||||||||||||||||||
522 | { return sectionIsPresent == 0 && port == -1 && path.isEmpty(); } | - | ||||||||||||||||||
523 | - | |||||||||||||||||||
524 | Error *cloneError() const; | - | ||||||||||||||||||
525 | void clearError(); | - | ||||||||||||||||||
526 | void setError(ErrorCode errorCode, const QString &source, int supplement = -1); | - | ||||||||||||||||||
527 | ErrorCode validityError(QString *source = 0, int *position = 0) const; | - | ||||||||||||||||||
528 | bool validateComponent(Section section, const QString &input, int begin, int end); | - | ||||||||||||||||||
529 | bool validateComponent(Section section, const QString &input) | - | ||||||||||||||||||
530 | { return validateComponent(section, input, 0, uint(input.length())); } | - | ||||||||||||||||||
531 | - | |||||||||||||||||||
532 | // no QString scheme() const; | - | ||||||||||||||||||
533 | void appendAuthority(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const; | - | ||||||||||||||||||
534 | void appendUserInfo(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const; | - | ||||||||||||||||||
535 | void appendUserName(QString &appendTo, QUrl::FormattingOptions options) const; | - | ||||||||||||||||||
536 | void appendPassword(QString &appendTo, QUrl::FormattingOptions options) const; | - | ||||||||||||||||||
537 | void appendHost(QString &appendTo, QUrl::FormattingOptions options) const; | - | ||||||||||||||||||
538 | void appendPath(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const; | - | ||||||||||||||||||
539 | void appendQuery(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const; | - | ||||||||||||||||||
540 | void appendFragment(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const; | - | ||||||||||||||||||
541 | - | |||||||||||||||||||
542 | // the "end" parameters are like STL iterators: they point to one past the last valid element | - | ||||||||||||||||||
543 | bool setScheme(const QString &value, int len, bool doSetError); | - | ||||||||||||||||||
544 | void setAuthority(const QString &auth, int from, int end, QUrl::ParsingMode mode); | - | ||||||||||||||||||
545 | void setUserInfo(const QString &userInfo, int from, int end); | - | ||||||||||||||||||
546 | void setUserName(const QString &value, int from, int end); | - | ||||||||||||||||||
547 | void setPassword(const QString &value, int from, int end); | - | ||||||||||||||||||
548 | bool setHost(const QString &value, int from, int end, QUrl::ParsingMode mode); | - | ||||||||||||||||||
549 | void setPath(const QString &value, int from, int end); | - | ||||||||||||||||||
550 | void setQuery(const QString &value, int from, int end); | - | ||||||||||||||||||
551 | void setFragment(const QString &value, int from, int end); | - | ||||||||||||||||||
552 | - | |||||||||||||||||||
553 | inline bool hasScheme() const { return sectionIsPresent & Scheme; } | - | ||||||||||||||||||
554 | inline bool hasAuthority() const { return sectionIsPresent & Authority; } | - | ||||||||||||||||||
555 | inline bool hasUserInfo() const { return sectionIsPresent & UserInfo; } | - | ||||||||||||||||||
556 | inline bool hasUserName() const { return sectionIsPresent & UserName; } | - | ||||||||||||||||||
557 | inline bool hasPassword() const { return sectionIsPresent & Password; } | - | ||||||||||||||||||
558 | inline bool hasHost() const { return sectionIsPresent & Host; } | - | ||||||||||||||||||
559 | inline bool hasPort() const { return port != -1; } | - | ||||||||||||||||||
560 | inline bool hasPath() const { return !path.isEmpty(); } | - | ||||||||||||||||||
561 | inline bool hasQuery() const { return sectionIsPresent & Query; } | - | ||||||||||||||||||
562 | inline bool hasFragment() const { return sectionIsPresent & Fragment; } | - | ||||||||||||||||||
563 | - | |||||||||||||||||||
564 | inline bool isLocalFile() const { return flags & IsLocalFile; } | - | ||||||||||||||||||
565 | QString toLocalFile(QUrl::FormattingOptions options) const; | - | ||||||||||||||||||
566 | - | |||||||||||||||||||
567 | QString mergePaths(const QString &relativePath) const; | - | ||||||||||||||||||
568 | - | |||||||||||||||||||
569 | QAtomicInt ref; | - | ||||||||||||||||||
570 | int port; | - | ||||||||||||||||||
571 | - | |||||||||||||||||||
572 | QString scheme; | - | ||||||||||||||||||
573 | QString userName; | - | ||||||||||||||||||
574 | QString password; | - | ||||||||||||||||||
575 | QString host; | - | ||||||||||||||||||
576 | QString path; | - | ||||||||||||||||||
577 | QString query; | - | ||||||||||||||||||
578 | QString fragment; | - | ||||||||||||||||||
579 | - | |||||||||||||||||||
580 | Error *error; | - | ||||||||||||||||||
581 | - | |||||||||||||||||||
582 | // not used for: | - | ||||||||||||||||||
583 | // - Port (port == -1 means absence) | - | ||||||||||||||||||
584 | // - Path (there's no path delimiter, so we optimize its use out of existence) | - | ||||||||||||||||||
585 | // Schemes are never supposed to be empty, but we keep the flag anyway | - | ||||||||||||||||||
586 | uchar sectionIsPresent; | - | ||||||||||||||||||
587 | uchar flags; | - | ||||||||||||||||||
588 | - | |||||||||||||||||||
589 | // 32-bit: 2 bytes tail padding available | - | ||||||||||||||||||
590 | // 64-bit: 6 bytes tail padding available | - | ||||||||||||||||||
591 | }; | - | ||||||||||||||||||
592 | #undef colon_uchar | - | ||||||||||||||||||
593 | - | |||||||||||||||||||
594 | inline QUrlPrivate::QUrlPrivate() | - | ||||||||||||||||||
595 | : ref(1), port(-1), | - | ||||||||||||||||||
596 | error(0), | - | ||||||||||||||||||
597 | sectionIsPresent(0), | - | ||||||||||||||||||
598 | flags(0) | - | ||||||||||||||||||
599 | { | - | ||||||||||||||||||
600 | } | - | ||||||||||||||||||
601 | - | |||||||||||||||||||
602 | inline QUrlPrivate::QUrlPrivate(const QUrlPrivate ©) | - | ||||||||||||||||||
603 | : ref(1), port(copy.port), | - | ||||||||||||||||||
604 | scheme(copy.scheme), | - | ||||||||||||||||||
605 | userName(copy.userName), | - | ||||||||||||||||||
606 | password(copy.password), | - | ||||||||||||||||||
607 | host(copy.host), | - | ||||||||||||||||||
608 | path(copy.path), | - | ||||||||||||||||||
609 | query(copy.query), | - | ||||||||||||||||||
610 | fragment(copy.fragment), | - | ||||||||||||||||||
611 | error(copy.cloneError()), | - | ||||||||||||||||||
612 | sectionIsPresent(copy.sectionIsPresent), | - | ||||||||||||||||||
613 | flags(copy.flags) | - | ||||||||||||||||||
614 | { | - | ||||||||||||||||||
615 | } | - | ||||||||||||||||||
616 | - | |||||||||||||||||||
617 | inline QUrlPrivate::~QUrlPrivate() | - | ||||||||||||||||||
618 | { | - | ||||||||||||||||||
619 | delete error; | - | ||||||||||||||||||
620 | } | - | ||||||||||||||||||
621 | - | |||||||||||||||||||
622 | inline QUrlPrivate::Error *QUrlPrivate::cloneError() const | - | ||||||||||||||||||
623 | { | - | ||||||||||||||||||
624 | return error ? new Error(*error) : 0; | - | ||||||||||||||||||
625 | } | - | ||||||||||||||||||
626 | - | |||||||||||||||||||
627 | inline void QUrlPrivate::clearError() | - | ||||||||||||||||||
628 | { | - | ||||||||||||||||||
629 | delete error; | - | ||||||||||||||||||
630 | error = 0; | - | ||||||||||||||||||
631 | } | - | ||||||||||||||||||
632 | - | |||||||||||||||||||
633 | inline void QUrlPrivate::setError(ErrorCode errorCode, const QString &source, int supplement) | - | ||||||||||||||||||
634 | { | - | ||||||||||||||||||
635 | if (error) { | - | ||||||||||||||||||
636 | // don't overwrite an error set in a previous section during parsing | - | ||||||||||||||||||
637 | return; | - | ||||||||||||||||||
638 | } | - | ||||||||||||||||||
639 | error = new Error; | - | ||||||||||||||||||
640 | error->code = errorCode; | - | ||||||||||||||||||
641 | error->source = source; | - | ||||||||||||||||||
642 | error->position = supplement; | - | ||||||||||||||||||
643 | } | - | ||||||||||||||||||
644 | - | |||||||||||||||||||
645 | // From RFC 3986, Appendix A Collected ABNF for URI | - | ||||||||||||||||||
646 | // URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] | - | ||||||||||||||||||
647 | //[...] | - | ||||||||||||||||||
648 | // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) | - | ||||||||||||||||||
649 | // | - | ||||||||||||||||||
650 | // authority = [ userinfo "@" ] host [ ":" port ] | - | ||||||||||||||||||
651 | // userinfo = *( unreserved / pct-encoded / sub-delims / ":" ) | - | ||||||||||||||||||
652 | // host = IP-literal / IPv4address / reg-name | - | ||||||||||||||||||
653 | // port = *DIGIT | - | ||||||||||||||||||
654 | //[...] | - | ||||||||||||||||||
655 | // reg-name = *( unreserved / pct-encoded / sub-delims ) | - | ||||||||||||||||||
656 | //[..] | - | ||||||||||||||||||
657 | // pchar = unreserved / pct-encoded / sub-delims / ":" / "@" | - | ||||||||||||||||||
658 | // | - | ||||||||||||||||||
659 | // query = *( pchar / "/" / "?" ) | - | ||||||||||||||||||
660 | // | - | ||||||||||||||||||
661 | // fragment = *( pchar / "/" / "?" ) | - | ||||||||||||||||||
662 | // | - | ||||||||||||||||||
663 | // pct-encoded = "%" HEXDIG HEXDIG | - | ||||||||||||||||||
664 | // | - | ||||||||||||||||||
665 | // unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" | - | ||||||||||||||||||
666 | // reserved = gen-delims / sub-delims | - | ||||||||||||||||||
667 | // gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@" | - | ||||||||||||||||||
668 | // sub-delims = "!" / "$" / "&" / "'" / "(" / ")" | - | ||||||||||||||||||
669 | // / "*" / "+" / "," / ";" / "=" | - | ||||||||||||||||||
670 | // the path component has a complex ABNF that basically boils down to | - | ||||||||||||||||||
671 | // slash-separated segments of "pchar" | - | ||||||||||||||||||
672 | - | |||||||||||||||||||
673 | // The above is the strict definition of the URL components and we mostly | - | ||||||||||||||||||
674 | // adhere to it, with few exceptions. QUrl obeys the following behavior: | - | ||||||||||||||||||
675 | // - percent-encoding sequences always use uppercase HEXDIG; | - | ||||||||||||||||||
676 | // - unreserved characters are *always* decoded, no exceptions; | - | ||||||||||||||||||
677 | // - the space character and bytes with the high bit set are controlled by | - | ||||||||||||||||||
678 | // the EncodeSpaces and EncodeUnicode bits; | - | ||||||||||||||||||
679 | // - control characters, the percent sign itself, and bytes with the high | - | ||||||||||||||||||
680 | // bit set that don't form valid UTF-8 sequences are always encoded, | - | ||||||||||||||||||
681 | // except in FullyDecoded mode; | - | ||||||||||||||||||
682 | // - sub-delims are always left alone, except in FullyDecoded mode; | - | ||||||||||||||||||
683 | // - gen-delim change behavior depending on which section of the URL (or | - | ||||||||||||||||||
684 | // the entire URL) we're looking at; see below; | - | ||||||||||||||||||
685 | // - characters not mentioned above, like "<", and ">", are usually | - | ||||||||||||||||||
686 | // decoded in individual sections of the URL, but encoded when the full | - | ||||||||||||||||||
687 | // URL is put together (we can change on subjective definition of | - | ||||||||||||||||||
688 | // "pretty"). | - | ||||||||||||||||||
689 | // | - | ||||||||||||||||||
690 | // The behavior for the delimiters bears some explanation. The spec says in | - | ||||||||||||||||||
691 | // section 2.2: | - | ||||||||||||||||||
692 | // URIs that differ in the replacement of a reserved character with its | - | ||||||||||||||||||
693 | // corresponding percent-encoded octet are not equivalent. | - | ||||||||||||||||||
694 | // (note: QUrl API mistakenly uses the "reserved" term, so we will refer to | - | ||||||||||||||||||
695 | // them here as "delimiters"). | - | ||||||||||||||||||
696 | // | - | ||||||||||||||||||
697 | // For that reason, we cannot encode delimiters found in decoded form and we | - | ||||||||||||||||||
698 | // cannot decode the ones found in encoded form if that would change the | - | ||||||||||||||||||
699 | // interpretation. Conversely, we *can* perform the transformation if it would | - | ||||||||||||||||||
700 | // not change the interpretation. From the last component of a URL to the first, | - | ||||||||||||||||||
701 | // here are the gen-delims we can unambiguously transform when the field is | - | ||||||||||||||||||
702 | // taken in isolation: | - | ||||||||||||||||||
703 | // - fragment: none, since it's the last | - | ||||||||||||||||||
704 | // - query: "#" is unambiguous | - | ||||||||||||||||||
705 | // - path: "#" and "?" are unambiguous | - | ||||||||||||||||||
706 | // - host: completely special but never ambiguous, see setHost() below. | - | ||||||||||||||||||
707 | // - password: the "#", "?", "/", "[", "]" and "@" characters are unambiguous | - | ||||||||||||||||||
708 | // - username: the "#", "?", "/", "[", "]", "@", and ":" characters are unambiguous | - | ||||||||||||||||||
709 | // - scheme: doesn't accept any delimiter, see setScheme() below. | - | ||||||||||||||||||
710 | // | - | ||||||||||||||||||
711 | // Internally, QUrl stores each component in the format that corresponds to the | - | ||||||||||||||||||
712 | // default mode (PrettyDecoded). It deviates from the "strict" FullyEncoded | - | ||||||||||||||||||
713 | // mode in the following way: | - | ||||||||||||||||||
714 | // - spaces are decoded | - | ||||||||||||||||||
715 | // - valid UTF-8 sequences are decoded | - | ||||||||||||||||||
716 | // - gen-delims that can be unambiguously transformed are decoded | - | ||||||||||||||||||
717 | // - characters controlled by DecodeReserved are often decoded, though this behavior | - | ||||||||||||||||||
718 | // can change depending on the subjective definition of "pretty" | - | ||||||||||||||||||
719 | // | - | ||||||||||||||||||
720 | // Note that the list of gen-delims that we can transform is different for the | - | ||||||||||||||||||
721 | // user info (user name + password) and the authority (user info + host + | - | ||||||||||||||||||
722 | // port). | - | ||||||||||||||||||
723 | - | |||||||||||||||||||
724 | - | |||||||||||||||||||
725 | // list the recoding table modifications to be used with the recodeFromUser and | - | ||||||||||||||||||
726 | // appendToUser functions, according to the rules above. Spaces and UTF-8 | - | ||||||||||||||||||
727 | // sequences are handled outside the tables. | - | ||||||||||||||||||
728 | - | |||||||||||||||||||
729 | // the encodedXXX tables are run with the delimiters set to "leave" by default; | - | ||||||||||||||||||
730 | // the decodedXXX tables are run with the delimiters set to "decode" by default | - | ||||||||||||||||||
731 | // (except for the query, which doesn't use these functions) | - | ||||||||||||||||||
732 | - | |||||||||||||||||||
733 | #define decode(x) ushort(x) | - | ||||||||||||||||||
734 | #define leave(x) ushort(0x100 | (x)) | - | ||||||||||||||||||
735 | #define encode(x) ushort(0x200 | (x)) | - | ||||||||||||||||||
736 | - | |||||||||||||||||||
737 | static const ushort userNameInIsolation[] = { | - | ||||||||||||||||||
738 | decode(':'), // 0 | - | ||||||||||||||||||
739 | decode('@'), // 1 | - | ||||||||||||||||||
740 | decode(']'), // 2 | - | ||||||||||||||||||
741 | decode('['), // 3 | - | ||||||||||||||||||
742 | decode('/'), // 4 | - | ||||||||||||||||||
743 | decode('?'), // 5 | - | ||||||||||||||||||
744 | decode('#'), // 6 | - | ||||||||||||||||||
745 | - | |||||||||||||||||||
746 | decode('"'), // 7 | - | ||||||||||||||||||
747 | decode('<'), | - | ||||||||||||||||||
748 | decode('>'), | - | ||||||||||||||||||
749 | decode('^'), | - | ||||||||||||||||||
750 | decode('\\'), | - | ||||||||||||||||||
751 | decode('|'), | - | ||||||||||||||||||
752 | decode('{'), | - | ||||||||||||||||||
753 | decode('}'), | - | ||||||||||||||||||
754 | 0 | - | ||||||||||||||||||
755 | }; | - | ||||||||||||||||||
756 | static const ushort * const passwordInIsolation = userNameInIsolation + 1; | - | ||||||||||||||||||
757 | static const ushort * const pathInIsolation = userNameInIsolation + 5; | - | ||||||||||||||||||
758 | static const ushort * const queryInIsolation = userNameInIsolation + 6; | - | ||||||||||||||||||
759 | static const ushort * const fragmentInIsolation = userNameInIsolation + 7; | - | ||||||||||||||||||
760 | - | |||||||||||||||||||
761 | static const ushort userNameInUserInfo[] = { | - | ||||||||||||||||||
762 | encode(':'), // 0 | - | ||||||||||||||||||
763 | decode('@'), // 1 | - | ||||||||||||||||||
764 | decode(']'), // 2 | - | ||||||||||||||||||
765 | decode('['), // 3 | - | ||||||||||||||||||
766 | decode('/'), // 4 | - | ||||||||||||||||||
767 | decode('?'), // 5 | - | ||||||||||||||||||
768 | decode('#'), // 6 | - | ||||||||||||||||||
769 | - | |||||||||||||||||||
770 | decode('"'), // 7 | - | ||||||||||||||||||
771 | decode('<'), | - | ||||||||||||||||||
772 | decode('>'), | - | ||||||||||||||||||
773 | decode('^'), | - | ||||||||||||||||||
774 | decode('\\'), | - | ||||||||||||||||||
775 | decode('|'), | - | ||||||||||||||||||
776 | decode('{'), | - | ||||||||||||||||||
777 | decode('}'), | - | ||||||||||||||||||
778 | 0 | - | ||||||||||||||||||
779 | }; | - | ||||||||||||||||||
780 | static const ushort * const passwordInUserInfo = userNameInUserInfo + 1; | - | ||||||||||||||||||
781 | - | |||||||||||||||||||
782 | static const ushort userNameInAuthority[] = { | - | ||||||||||||||||||
783 | encode(':'), // 0 | - | ||||||||||||||||||
784 | encode('@'), // 1 | - | ||||||||||||||||||
785 | encode(']'), // 2 | - | ||||||||||||||||||
786 | encode('['), // 3 | - | ||||||||||||||||||
787 | decode('/'), // 4 | - | ||||||||||||||||||
788 | decode('?'), // 5 | - | ||||||||||||||||||
789 | decode('#'), // 6 | - | ||||||||||||||||||
790 | - | |||||||||||||||||||
791 | decode('"'), // 7 | - | ||||||||||||||||||
792 | decode('<'), | - | ||||||||||||||||||
793 | decode('>'), | - | ||||||||||||||||||
794 | decode('^'), | - | ||||||||||||||||||
795 | decode('\\'), | - | ||||||||||||||||||
796 | decode('|'), | - | ||||||||||||||||||
797 | decode('{'), | - | ||||||||||||||||||
798 | decode('}'), | - | ||||||||||||||||||
799 | 0 | - | ||||||||||||||||||
800 | }; | - | ||||||||||||||||||
801 | static const ushort * const passwordInAuthority = userNameInAuthority + 1; | - | ||||||||||||||||||
802 | - | |||||||||||||||||||
803 | static const ushort userNameInUrl[] = { | - | ||||||||||||||||||
804 | encode(':'), // 0 | - | ||||||||||||||||||
805 | encode('@'), // 1 | - | ||||||||||||||||||
806 | encode(']'), // 2 | - | ||||||||||||||||||
807 | encode('['), // 3 | - | ||||||||||||||||||
808 | encode('/'), // 4 | - | ||||||||||||||||||
809 | encode('?'), // 5 | - | ||||||||||||||||||
810 | encode('#'), // 6 | - | ||||||||||||||||||
811 | - | |||||||||||||||||||
812 | // no need to list encode(x) for the other characters | - | ||||||||||||||||||
813 | 0 | - | ||||||||||||||||||
814 | }; | - | ||||||||||||||||||
815 | static const ushort * const passwordInUrl = userNameInUrl + 1; | - | ||||||||||||||||||
816 | static const ushort * const pathInUrl = userNameInUrl + 5; | - | ||||||||||||||||||
817 | static const ushort * const queryInUrl = userNameInUrl + 6; | - | ||||||||||||||||||
818 | static const ushort * const fragmentInUrl = userNameInUrl + 6; | - | ||||||||||||||||||
819 | - | |||||||||||||||||||
820 | static inline void parseDecodedComponent(QString &data) | - | ||||||||||||||||||
821 | { | - | ||||||||||||||||||
822 | data.replace(QLatin1Char('%'), QStringLiteralQLatin1String("%25")); | - | ||||||||||||||||||
823 | } executed 14930 times by 40 tests: end of block Executed by:
| 14930 | ||||||||||||||||||
824 | - | |||||||||||||||||||
825 | static inline QString | - | ||||||||||||||||||
826 | recodeFromUser(const QString &input, const ushort *actions, int from, int to) | - | ||||||||||||||||||
827 | { | - | ||||||||||||||||||
828 | QString output; | - | ||||||||||||||||||
829 | const QChar *begin = input.constData() + from; | - | ||||||||||||||||||
830 | const QChar *end = input.constData() + to; | - | ||||||||||||||||||
831 | if (qt_urlRecode(output, begin, end, 0, actions)) | - | ||||||||||||||||||
832 | return output; | - | ||||||||||||||||||
833 | - | |||||||||||||||||||
834 | return input.mid(from, to - from); | - | ||||||||||||||||||
835 | } | - | ||||||||||||||||||
836 | - | |||||||||||||||||||
837 | // appendXXXX functions: copy from the internal form to the external, user form. | - | ||||||||||||||||||
838 | // the internal value is stored in its PrettyDecoded form, so that case is easy. | - | ||||||||||||||||||
839 | static inline void appendToUser(QString &appendTo, const QString &value, QUrl::FormattingOptions options, | - | ||||||||||||||||||
840 | const ushort *actions) | - | ||||||||||||||||||
841 | { | - | ||||||||||||||||||
842 | if (options == QUrl::PrettyDecoded) { | - | ||||||||||||||||||
843 | appendTo += value; | - | ||||||||||||||||||
844 | return; | - | ||||||||||||||||||
845 | } | - | ||||||||||||||||||
846 | - | |||||||||||||||||||
847 | if (!qt_urlRecode(appendTo, value.constData(), value.constEnd(), options, actions)) | - | ||||||||||||||||||
848 | appendTo += value; | - | ||||||||||||||||||
849 | } | - | ||||||||||||||||||
850 | - | |||||||||||||||||||
851 | inline void QUrlPrivate::appendAuthority(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const | - | ||||||||||||||||||
852 | { | - | ||||||||||||||||||
853 | if ((options & QUrl::RemoveUserInfo) != QUrl::RemoveUserInfo) { | - | ||||||||||||||||||
854 | appendUserInfo(appendTo, options, appendingTo); | - | ||||||||||||||||||
855 | - | |||||||||||||||||||
856 | // add '@' only if we added anything | - | ||||||||||||||||||
857 | if (hasUserName() || (hasPassword() && (options & QUrl::RemovePassword) == 0)) | - | ||||||||||||||||||
858 | appendTo += QLatin1Char('@'); | - | ||||||||||||||||||
859 | } | - | ||||||||||||||||||
860 | appendHost(appendTo, options); | - | ||||||||||||||||||
861 | if (!(options & QUrl::RemovePort) && port != -1) | - | ||||||||||||||||||
862 | appendTo += QLatin1Char(':') + QString::number(port); | - | ||||||||||||||||||
863 | } | - | ||||||||||||||||||
864 | - | |||||||||||||||||||
865 | inline void QUrlPrivate::appendUserInfo(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const | - | ||||||||||||||||||
866 | { | - | ||||||||||||||||||
867 | if (Q_LIKELY(!hasUserInfo())) | - | ||||||||||||||||||
868 | return; | - | ||||||||||||||||||
869 | - | |||||||||||||||||||
870 | const ushort *userNameActions; | - | ||||||||||||||||||
871 | const ushort *passwordActions; | - | ||||||||||||||||||
872 | if (options & QUrl::EncodeDelimiters) { | - | ||||||||||||||||||
873 | userNameActions = userNameInUrl; | - | ||||||||||||||||||
874 | passwordActions = passwordInUrl; | - | ||||||||||||||||||
875 | } else { | - | ||||||||||||||||||
876 | switch (appendingTo) { | - | ||||||||||||||||||
877 | case UserInfo: | - | ||||||||||||||||||
878 | userNameActions = userNameInUserInfo; | - | ||||||||||||||||||
879 | passwordActions = passwordInUserInfo; | - | ||||||||||||||||||
880 | break; | - | ||||||||||||||||||
881 | - | |||||||||||||||||||
882 | case Authority: | - | ||||||||||||||||||
883 | userNameActions = userNameInAuthority; | - | ||||||||||||||||||
884 | passwordActions = passwordInAuthority; | - | ||||||||||||||||||
885 | break; | - | ||||||||||||||||||
886 | - | |||||||||||||||||||
887 | case FullUrl: | - | ||||||||||||||||||
888 | userNameActions = userNameInUrl; | - | ||||||||||||||||||
889 | passwordActions = passwordInUrl; | - | ||||||||||||||||||
890 | break; | - | ||||||||||||||||||
891 | - | |||||||||||||||||||
892 | default: | - | ||||||||||||||||||
893 | // can't happen | - | ||||||||||||||||||
894 | Q_UNREACHABLE(); | - | ||||||||||||||||||
895 | break; | - | ||||||||||||||||||
896 | } | - | ||||||||||||||||||
897 | } | - | ||||||||||||||||||
898 | - | |||||||||||||||||||
899 | if (!qt_urlRecode(appendTo, userName.constData(), userName.constEnd(), options, userNameActions)) | - | ||||||||||||||||||
900 | appendTo += userName; | - | ||||||||||||||||||
901 | if (options & QUrl::RemovePassword || !hasPassword()) { | - | ||||||||||||||||||
902 | return; | - | ||||||||||||||||||
903 | } else { | - | ||||||||||||||||||
904 | appendTo += QLatin1Char(':'); | - | ||||||||||||||||||
905 | if (!qt_urlRecode(appendTo, password.constData(), password.constEnd(), options, passwordActions)) | - | ||||||||||||||||||
906 | appendTo += password; | - | ||||||||||||||||||
907 | } | - | ||||||||||||||||||
908 | } | - | ||||||||||||||||||
909 | - | |||||||||||||||||||
910 | inline void QUrlPrivate::appendUserName(QString &appendTo, QUrl::FormattingOptions options) const | - | ||||||||||||||||||
911 | { | - | ||||||||||||||||||
912 | // only called from QUrl::userName() | - | ||||||||||||||||||
913 | appendToUser(appendTo, userName, options, | - | ||||||||||||||||||
914 | options & QUrl::EncodeDelimiters ? userNameInUrl : userNameInIsolation); | - | ||||||||||||||||||
915 | } | - | ||||||||||||||||||
916 | - | |||||||||||||||||||
917 | inline void QUrlPrivate::appendPassword(QString &appendTo, QUrl::FormattingOptions options) const | - | ||||||||||||||||||
918 | { | - | ||||||||||||||||||
919 | // only called from QUrl::password() | - | ||||||||||||||||||
920 | appendToUser(appendTo, password, options, | - | ||||||||||||||||||
921 | options & QUrl::EncodeDelimiters ? passwordInUrl : passwordInIsolation); | - | ||||||||||||||||||
922 | } | - | ||||||||||||||||||
923 | - | |||||||||||||||||||
924 | inline void QUrlPrivate::appendPath(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const | - | ||||||||||||||||||
925 | { | - | ||||||||||||||||||
926 | QString thePath = path; | - | ||||||||||||||||||
927 | if (options & QUrl::NormalizePathSegments) { | - | ||||||||||||||||||
928 | thePath = qt_normalizePathSegments(path, false); | - | ||||||||||||||||||
929 | } | - | ||||||||||||||||||
930 | if (options & QUrl::RemoveFilename) { | - | ||||||||||||||||||
931 | const int slash = path.lastIndexOf(QLatin1Char('/')); | - | ||||||||||||||||||
932 | if (slash == -1) | - | ||||||||||||||||||
933 | return; | - | ||||||||||||||||||
934 | thePath = path.left(slash+1); | - | ||||||||||||||||||
935 | } | - | ||||||||||||||||||
936 | // check if we need to remove trailing slashes | - | ||||||||||||||||||
937 | if (options & QUrl::StripTrailingSlash) { | - | ||||||||||||||||||
938 | while (thePath.length() > 1 && thePath.endsWith(QLatin1Char('/'))) | - | ||||||||||||||||||
939 | thePath.chop(1); | - | ||||||||||||||||||
940 | } | - | ||||||||||||||||||
941 | - | |||||||||||||||||||
942 | appendToUser(appendTo, thePath, options, | - | ||||||||||||||||||
943 | appendingTo == FullUrl || options & QUrl::EncodeDelimiters ? pathInUrl : pathInIsolation); | - | ||||||||||||||||||
944 | - | |||||||||||||||||||
945 | } | - | ||||||||||||||||||
946 | - | |||||||||||||||||||
947 | inline void QUrlPrivate::appendFragment(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const | - | ||||||||||||||||||
948 | { | - | ||||||||||||||||||
949 | appendToUser(appendTo, fragment, options, | - | ||||||||||||||||||
950 | options & QUrl::EncodeDelimiters ? fragmentInUrl : | - | ||||||||||||||||||
951 | appendingTo == FullUrl ? 0 : fragmentInIsolation); | - | ||||||||||||||||||
952 | } | - | ||||||||||||||||||
953 | - | |||||||||||||||||||
954 | inline void QUrlPrivate::appendQuery(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const | - | ||||||||||||||||||
955 | { | - | ||||||||||||||||||
956 | appendToUser(appendTo, query, options, | - | ||||||||||||||||||
957 | appendingTo == FullUrl || options & QUrl::EncodeDelimiters ? queryInUrl : queryInIsolation); | - | ||||||||||||||||||
958 | } | - | ||||||||||||||||||
959 | - | |||||||||||||||||||
960 | // setXXX functions | - | ||||||||||||||||||
961 | - | |||||||||||||||||||
962 | inline bool QUrlPrivate::setScheme(const QString &value, int len, bool doSetError) | - | ||||||||||||||||||
963 | { | - | ||||||||||||||||||
964 | // schemes are strictly RFC-compliant: | - | ||||||||||||||||||
965 | // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) | - | ||||||||||||||||||
966 | // we also lowercase the scheme | - | ||||||||||||||||||
967 | - | |||||||||||||||||||
968 | // schemes in URLs are not allowed to be empty, but they can be in | - | ||||||||||||||||||
969 | // "Relative URIs" which QUrl also supports. QUrl::setScheme does | - | ||||||||||||||||||
970 | // not call us with len == 0, so this can only be from parse() | - | ||||||||||||||||||
971 | scheme.clear(); | - | ||||||||||||||||||
972 | if (len == 0) | - | ||||||||||||||||||
973 | return false; | - | ||||||||||||||||||
974 | - | |||||||||||||||||||
975 | sectionIsPresent |= Scheme; | - | ||||||||||||||||||
976 | - | |||||||||||||||||||
977 | // validate it: | - | ||||||||||||||||||
978 | int needsLowercasing = -1; | - | ||||||||||||||||||
979 | const ushort *p = reinterpret_cast<const ushort *>(value.constData()); | - | ||||||||||||||||||
980 | for (int i = 0; i < len; ++i) { | - | ||||||||||||||||||
981 | if (p[i] >= 'a' && p[i] <= 'z') | - | ||||||||||||||||||
982 | continue; | - | ||||||||||||||||||
983 | if (p[i] >= 'A' && p[i] <= 'Z') { | - | ||||||||||||||||||
984 | needsLowercasing = i; | - | ||||||||||||||||||
985 | continue; | - | ||||||||||||||||||
986 | } | - | ||||||||||||||||||
987 | if (i) { | - | ||||||||||||||||||
988 | if (p[i] >= '0' && p[i] <= '9') | - | ||||||||||||||||||
989 | continue; | - | ||||||||||||||||||
990 | if (p[i] == '+' || p[i] == '-' || p[i] == '.') | - | ||||||||||||||||||
991 | continue; | - | ||||||||||||||||||
992 | } | - | ||||||||||||||||||
993 | - | |||||||||||||||||||
994 | // found something else | - | ||||||||||||||||||
995 | // don't call setError needlessly: | - | ||||||||||||||||||
996 | // if we've been called from parse(), it will try to recover | - | ||||||||||||||||||
997 | if (doSetError) | - | ||||||||||||||||||
998 | setError(InvalidSchemeError, value, i); | - | ||||||||||||||||||
999 | return false; | - | ||||||||||||||||||
1000 | } | - | ||||||||||||||||||
1001 | - | |||||||||||||||||||
1002 | scheme = value.left(len); | - | ||||||||||||||||||
1003 | - | |||||||||||||||||||
1004 | if (needsLowercasing != -1) { | - | ||||||||||||||||||
1005 | // schemes are ASCII only, so we don't need the full Unicode toLower | - | ||||||||||||||||||
1006 | QChar *schemeData = scheme.data(); // force detaching here | - | ||||||||||||||||||
1007 | for (int i = needsLowercasing; i >= 0; --i) { | - | ||||||||||||||||||
1008 | ushort c = schemeData[i].unicode(); | - | ||||||||||||||||||
1009 | if (c >= 'A' && c <= 'Z') | - | ||||||||||||||||||
1010 | schemeData[i] = c + 0x20; | - | ||||||||||||||||||
1011 | } | - | ||||||||||||||||||
1012 | } | - | ||||||||||||||||||
1013 | - | |||||||||||||||||||
1014 | // did we set to the file protocol? | - | ||||||||||||||||||
1015 | if (scheme == fileScheme() | - | ||||||||||||||||||
1016 | #ifdef Q_OS_WIN | - | ||||||||||||||||||
1017 | || scheme == webDavScheme() | - | ||||||||||||||||||
1018 | #endif | - | ||||||||||||||||||
1019 | ) { | - | ||||||||||||||||||
1020 | flags |= IsLocalFile; | - | ||||||||||||||||||
1021 | } else { | - | ||||||||||||||||||
1022 | flags &= ~IsLocalFile; | - | ||||||||||||||||||
1023 | } | - | ||||||||||||||||||
1024 | return true; | - | ||||||||||||||||||
1025 | } | - | ||||||||||||||||||
1026 | - | |||||||||||||||||||
1027 | inline void QUrlPrivate::setAuthority(const QString &auth, int from, int end, QUrl::ParsingMode mode) | - | ||||||||||||||||||
1028 | { | - | ||||||||||||||||||
1029 | sectionIsPresent &= ~Authority; | - | ||||||||||||||||||
1030 | sectionIsPresent |= Host; | - | ||||||||||||||||||
1031 | - | |||||||||||||||||||
1032 | // we never actually _loop_ | - | ||||||||||||||||||
1033 | while (from != end) { | - | ||||||||||||||||||
1034 | int userInfoIndex = auth.indexOf(QLatin1Char('@'), from); | - | ||||||||||||||||||
1035 | if (uint(userInfoIndex) < uint(end)) { | - | ||||||||||||||||||
1036 | setUserInfo(auth, from, userInfoIndex); | - | ||||||||||||||||||
1037 | if (mode == QUrl::StrictMode && !validateComponent(UserInfo, auth, from, userInfoIndex)) | - | ||||||||||||||||||
1038 | break; | - | ||||||||||||||||||
1039 | from = userInfoIndex + 1; | - | ||||||||||||||||||
1040 | } | - | ||||||||||||||||||
1041 | - | |||||||||||||||||||
1042 | int colonIndex = auth.lastIndexOf(QLatin1Char(':'), end - 1); | - | ||||||||||||||||||
1043 | if (colonIndex < from) | - | ||||||||||||||||||
1044 | colonIndex = -1; | - | ||||||||||||||||||
1045 | - | |||||||||||||||||||
1046 | if (uint(colonIndex) < uint(end)) { | - | ||||||||||||||||||
1047 | if (auth.at(from).unicode() == '[') { | - | ||||||||||||||||||
1048 | // check if colonIndex isn't inside the "[...]" part | - | ||||||||||||||||||
1049 | int closingBracket = auth.indexOf(QLatin1Char(']'), from); | - | ||||||||||||||||||
1050 | if (uint(closingBracket) > uint(colonIndex)) | - | ||||||||||||||||||
1051 | colonIndex = -1; | - | ||||||||||||||||||
1052 | } | - | ||||||||||||||||||
1053 | } | - | ||||||||||||||||||
1054 | - | |||||||||||||||||||
1055 | if (colonIndex == end - 1) { | - | ||||||||||||||||||
1056 | // found a colon but no digits after it | - | ||||||||||||||||||
1057 | port = -1; | - | ||||||||||||||||||
1058 | } else if (uint(colonIndex) < uint(end)) { | - | ||||||||||||||||||
1059 | unsigned long x = 0; | - | ||||||||||||||||||
1060 | for (int i = colonIndex + 1; i < end; ++i) { | - | ||||||||||||||||||
1061 | ushort c = auth.at(i).unicode(); | - | ||||||||||||||||||
1062 | if (c >= '0' && c <= '9') { | - | ||||||||||||||||||
1063 | x *= 10; | - | ||||||||||||||||||
1064 | x += c - '0'; | - | ||||||||||||||||||
1065 | } else { | - | ||||||||||||||||||
1066 | x = ulong(-1); // x != ushort(x) | - | ||||||||||||||||||
1067 | break; | - | ||||||||||||||||||
1068 | } | - | ||||||||||||||||||
1069 | } | - | ||||||||||||||||||
1070 | if (x == ushort(x)) { | - | ||||||||||||||||||
1071 | port = ushort(x); | - | ||||||||||||||||||
1072 | } else { | - | ||||||||||||||||||
1073 | setError(InvalidPortError, auth, colonIndex + 1); | - | ||||||||||||||||||
1074 | if (mode == QUrl::StrictMode) | - | ||||||||||||||||||
1075 | break; | - | ||||||||||||||||||
1076 | } | - | ||||||||||||||||||
1077 | } else { | - | ||||||||||||||||||
1078 | port = -1; | - | ||||||||||||||||||
1079 | } | - | ||||||||||||||||||
1080 | - | |||||||||||||||||||
1081 | setHost(auth, from, qMin<uint>(end, colonIndex), mode); | - | ||||||||||||||||||
1082 | if (mode == QUrl::StrictMode && !validateComponent(Host, auth, from, qMin<uint>(end, colonIndex))) { | - | ||||||||||||||||||
1083 | // clear host too | - | ||||||||||||||||||
1084 | sectionIsPresent &= ~Authority; | - | ||||||||||||||||||
1085 | break; | - | ||||||||||||||||||
1086 | } | - | ||||||||||||||||||
1087 | - | |||||||||||||||||||
1088 | // success | - | ||||||||||||||||||
1089 | return; | - | ||||||||||||||||||
1090 | } | - | ||||||||||||||||||
1091 | // clear all sections but host | - | ||||||||||||||||||
1092 | sectionIsPresent &= ~Authority | Host; | - | ||||||||||||||||||
1093 | userName.clear(); | - | ||||||||||||||||||
1094 | password.clear(); | - | ||||||||||||||||||
1095 | host.clear(); | - | ||||||||||||||||||
1096 | port = -1; | - | ||||||||||||||||||
1097 | } | - | ||||||||||||||||||
1098 | - | |||||||||||||||||||
1099 | inline void QUrlPrivate::setUserInfo(const QString &userInfo, int from, int end) | - | ||||||||||||||||||
1100 | { | - | ||||||||||||||||||
1101 | int delimIndex = userInfo.indexOf(QLatin1Char(':'), from); | - | ||||||||||||||||||
1102 | setUserName(userInfo, from, qMin<uint>(delimIndex, end)); | - | ||||||||||||||||||
1103 | - | |||||||||||||||||||
1104 | if (uint(delimIndex) >= uint(end)) { | - | ||||||||||||||||||
1105 | password.clear(); | - | ||||||||||||||||||
1106 | sectionIsPresent &= ~Password; | - | ||||||||||||||||||
1107 | } else { | - | ||||||||||||||||||
1108 | setPassword(userInfo, delimIndex + 1, end); | - | ||||||||||||||||||
1109 | } | - | ||||||||||||||||||
1110 | } | - | ||||||||||||||||||
1111 | - | |||||||||||||||||||
1112 | inline void QUrlPrivate::setUserName(const QString &value, int from, int end) | - | ||||||||||||||||||
1113 | { | - | ||||||||||||||||||
1114 | sectionIsPresent |= UserName; | - | ||||||||||||||||||
1115 | userName = recodeFromUser(value, userNameInIsolation, from, end); | - | ||||||||||||||||||
1116 | } | - | ||||||||||||||||||
1117 | - | |||||||||||||||||||
1118 | inline void QUrlPrivate::setPassword(const QString &value, int from, int end) | - | ||||||||||||||||||
1119 | { | - | ||||||||||||||||||
1120 | sectionIsPresent |= Password; | - | ||||||||||||||||||
1121 | password = recodeFromUser(value, passwordInIsolation, from, end); | - | ||||||||||||||||||
1122 | } | - | ||||||||||||||||||
1123 | - | |||||||||||||||||||
1124 | inline void QUrlPrivate::setPath(const QString &value, int from, int end) | - | ||||||||||||||||||
1125 | { | - | ||||||||||||||||||
1126 | // sectionIsPresent |= Path; // not used, save some cycles | - | ||||||||||||||||||
1127 | path = recodeFromUser(value, pathInIsolation, from, end); | - | ||||||||||||||||||
1128 | } | - | ||||||||||||||||||
1129 | - | |||||||||||||||||||
1130 | inline void QUrlPrivate::setFragment(const QString &value, int from, int end) | - | ||||||||||||||||||
1131 | { | - | ||||||||||||||||||
1132 | sectionIsPresent |= Fragment; | - | ||||||||||||||||||
1133 | fragment = recodeFromUser(value, fragmentInIsolation, from, end); | - | ||||||||||||||||||
1134 | } | - | ||||||||||||||||||
1135 | - | |||||||||||||||||||
1136 | inline void QUrlPrivate::setQuery(const QString &value, int from, int iend) | - | ||||||||||||||||||
1137 | { | - | ||||||||||||||||||
1138 | sectionIsPresent |= Query; | - | ||||||||||||||||||
1139 | query = recodeFromUser(value, queryInIsolation, from, iend); | - | ||||||||||||||||||
1140 | } | - | ||||||||||||||||||
1141 | - | |||||||||||||||||||
1142 | // Host handling | - | ||||||||||||||||||
1143 | // The RFC says the host is: | - | ||||||||||||||||||
1144 | // host = IP-literal / IPv4address / reg-name | - | ||||||||||||||||||
1145 | // IP-literal = "[" ( IPv6address / IPvFuture ) "]" | - | ||||||||||||||||||
1146 | // IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" ) | - | ||||||||||||||||||
1147 | // [a strict definition of IPv6Address and IPv4Address] | - | ||||||||||||||||||
1148 | // reg-name = *( unreserved / pct-encoded / sub-delims ) | - | ||||||||||||||||||
1149 | // | - | ||||||||||||||||||
1150 | // We deviate from the standard in all but IPvFuture. For IPvFuture we accept | - | ||||||||||||||||||
1151 | // and store only exactly what the RFC says we should. No percent-encoding is | - | ||||||||||||||||||
1152 | // permitted in this field, so Unicode characters and space aren't either. | - | ||||||||||||||||||
1153 | // | - | ||||||||||||||||||
1154 | // For IPv4 addresses, we accept broken addresses like inet_aton does (that is, | - | ||||||||||||||||||
1155 | // less than three dots). However, we correct the address to the proper form | - | ||||||||||||||||||
1156 | // and store the corrected address. After correction, we comply to the RFC and | - | ||||||||||||||||||
1157 | // it's exclusively composed of unreserved characters. | - | ||||||||||||||||||
1158 | // | - | ||||||||||||||||||
1159 | // For IPv6 addresses, we accept addresses including trailing (embedded) IPv4 | - | ||||||||||||||||||
1160 | // addresses, the so-called v4-compat and v4-mapped addresses. We also store | - | ||||||||||||||||||
1161 | // those addresses like that in the hostname field, which violates the spec. | - | ||||||||||||||||||
1162 | // IPv6 hosts are stored with the square brackets in the QString. It also | - | ||||||||||||||||||
1163 | // requires no transformation in any way. | - | ||||||||||||||||||
1164 | // | - | ||||||||||||||||||
1165 | // As for registered names, it's the other way around: we accept only valid | - | ||||||||||||||||||
1166 | // hostnames as specified by STD 3 and IDNA. That means everything we accept is | - | ||||||||||||||||||
1167 | // valid in the RFC definition above, but there are many valid reg-names | - | ||||||||||||||||||
1168 | // according to the RFC that we do not accept in the name of security. Since we | - | ||||||||||||||||||
1169 | // do accept IDNA, reg-names are subject to ACE encoding and decoding, which is | - | ||||||||||||||||||
1170 | // specified by the DecodeUnicode flag. The hostname is stored in its Unicode form. | - | ||||||||||||||||||
1171 | - | |||||||||||||||||||
1172 | inline void QUrlPrivate::appendHost(QString &appendTo, QUrl::FormattingOptions options) const | - | ||||||||||||||||||
1173 | { | - | ||||||||||||||||||
1174 | // EncodeUnicode is the only flag that matters | - | ||||||||||||||||||
1175 | if ((options & QUrl::FullyDecoded) == QUrl::FullyDecoded) | - | ||||||||||||||||||
1176 | options = 0; | - | ||||||||||||||||||
1177 | else | - | ||||||||||||||||||
1178 | options &= QUrl::EncodeUnicode; | - | ||||||||||||||||||
1179 | if (host.isEmpty()) | - | ||||||||||||||||||
1180 | return; | - | ||||||||||||||||||
1181 | if (host.at(0).unicode() == '[') { | - | ||||||||||||||||||
1182 | // IPv6Address and IPvFuture address never require any transformation | - | ||||||||||||||||||
1183 | appendTo += host; | - | ||||||||||||||||||
1184 | } else { | - | ||||||||||||||||||
1185 | // this is either an IPv4Address or a reg-name | - | ||||||||||||||||||
1186 | // if it is a reg-name, it is already stored in Unicode form | - | ||||||||||||||||||
1187 | if (options & QUrl::EncodeUnicode && !(options & 0x4000000)) | - | ||||||||||||||||||
1188 | appendTo += qt_ACE_do(host, ToAceOnly, AllowLeadingDot); | - | ||||||||||||||||||
1189 | else | - | ||||||||||||||||||
1190 | appendTo += host; | - | ||||||||||||||||||
1191 | } | - | ||||||||||||||||||
1192 | } | - | ||||||||||||||||||
1193 | - | |||||||||||||||||||
1194 | // the whole IPvFuture is passed and parsed here, including brackets; | - | ||||||||||||||||||
1195 | // returns null if the parsing was successful, or the QChar of the first failure | - | ||||||||||||||||||
1196 | static const QChar *parseIpFuture(QString &host, const QChar *begin, const QChar *end, QUrl::ParsingMode mode) | - | ||||||||||||||||||
1197 | { | - | ||||||||||||||||||
1198 | // IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" ) | - | ||||||||||||||||||
1199 | static const char acceptable[] = | - | ||||||||||||||||||
1200 | "!$&'()*+,;=" // sub-delims | - | ||||||||||||||||||
1201 | ":" // ":" | - | ||||||||||||||||||
1202 | "-._~"; // unreserved | - | ||||||||||||||||||
1203 | - | |||||||||||||||||||
1204 | // the brackets and the "v" have been checked | - | ||||||||||||||||||
1205 | const QChar *const origBegin = begin; | - | ||||||||||||||||||
1206 | if (begin[3].unicode() != '.') | - | ||||||||||||||||||
1207 | return &begin[3]; | - | ||||||||||||||||||
1208 | if ((begin[2].unicode() >= 'A' && begin[2].unicode() <= 'F') || | - | ||||||||||||||||||
1209 | (begin[2].unicode() >= 'a' && begin[2].unicode() <= 'f') || | - | ||||||||||||||||||
1210 | (begin[2].unicode() >= '0' && begin[2].unicode() <= '9')) { | - | ||||||||||||||||||
1211 | // this is so unlikely that we'll just go down the slow path | - | ||||||||||||||||||
1212 | // decode the whole string, skipping the "[vH." and "]" which we already know to be there | - | ||||||||||||||||||
1213 | host += QString::fromRawData(begin, 4); | - | ||||||||||||||||||
1214 | - | |||||||||||||||||||
1215 | // uppercase the version, if necessary | - | ||||||||||||||||||
1216 | if (begin[2].unicode() >= 'a') | - | ||||||||||||||||||
1217 | host[host.length() - 2] = begin[2].unicode() - 0x20; | - | ||||||||||||||||||
1218 | - | |||||||||||||||||||
1219 | begin += 4; | - | ||||||||||||||||||
1220 | --end; | - | ||||||||||||||||||
1221 | - | |||||||||||||||||||
1222 | QString decoded; | - | ||||||||||||||||||
1223 | if (mode == QUrl::TolerantMode && qt_urlRecode(decoded, begin, end, QUrl::FullyDecoded, 0)) { | - | ||||||||||||||||||
1224 | begin = decoded.constBegin(); | - | ||||||||||||||||||
1225 | end = decoded.constEnd(); | - | ||||||||||||||||||
1226 | } | - | ||||||||||||||||||
1227 | - | |||||||||||||||||||
1228 | for ( ; begin != end; ++begin) { | - | ||||||||||||||||||
1229 | if (begin->unicode() >= 'A' && begin->unicode() <= 'Z') | - | ||||||||||||||||||
1230 | host += *begin; | - | ||||||||||||||||||
1231 | else if (begin->unicode() >= 'a' && begin->unicode() <= 'z') | - | ||||||||||||||||||
1232 | host += *begin; | - | ||||||||||||||||||
1233 | else if (begin->unicode() >= '0' && begin->unicode() <= '9') | - | ||||||||||||||||||
1234 | host += *begin; | - | ||||||||||||||||||
1235 | else if (begin->unicode() < 0x80 && strchr(acceptable, begin->unicode()) != 0) | - | ||||||||||||||||||
1236 | host += *begin; | - | ||||||||||||||||||
1237 | else | - | ||||||||||||||||||
1238 | return decoded.isEmpty() ? begin : &origBegin[2]; | - | ||||||||||||||||||
1239 | } | - | ||||||||||||||||||
1240 | host += QLatin1Char(']'); | - | ||||||||||||||||||
1241 | return 0; | - | ||||||||||||||||||
1242 | } | - | ||||||||||||||||||
1243 | return &origBegin[2]; | - | ||||||||||||||||||
1244 | } | - | ||||||||||||||||||
1245 | - | |||||||||||||||||||
1246 | // ONLY the IPv6 address is parsed here, WITHOUT the brackets | - | ||||||||||||||||||
1247 | static const QChar *parseIp6(QString &host, const QChar *begin, const QChar *end, QUrl::ParsingMode mode) | - | ||||||||||||||||||
1248 | { | - | ||||||||||||||||||
1249 | QIPAddressUtils::IPv6Address address; | - | ||||||||||||||||||
1250 | const QChar *ret = QIPAddressUtils::parseIp6(address, begin, end); | - | ||||||||||||||||||
1251 | if (ret) { | - | ||||||||||||||||||
1252 | // this struct is kept in automatic storage because it's only 4 bytes | - | ||||||||||||||||||
1253 | const ushort decodeColon[] = { decode(':'), 0 }; | - | ||||||||||||||||||
1254 | - | |||||||||||||||||||
1255 | // IPv6 failed parsing, check if it was a percent-encoded character in | - | ||||||||||||||||||
1256 | // the middle and try again | - | ||||||||||||||||||
1257 | QString decoded; | - | ||||||||||||||||||
1258 | if (mode == QUrl::TolerantMode && qt_urlRecode(decoded, begin, end, 0, decodeColon)) { | - | ||||||||||||||||||
1259 | // recurse | - | ||||||||||||||||||
1260 | // if the parsing fails again, the qt_urlRecode above will return 0 | - | ||||||||||||||||||
1261 | ret = parseIp6(host, decoded.constBegin(), decoded.constEnd(), mode); | - | ||||||||||||||||||
1262 | - | |||||||||||||||||||
1263 | // we can't return ret, otherwise it would be dangling | - | ||||||||||||||||||
1264 | return ret ? end : 0; | - | ||||||||||||||||||
1265 | } | - | ||||||||||||||||||
1266 | - | |||||||||||||||||||
1267 | // no transformation, nothing to re-parse | - | ||||||||||||||||||
1268 | return ret; | - | ||||||||||||||||||
1269 | } | - | ||||||||||||||||||
1270 | - | |||||||||||||||||||
1271 | host.reserve(host.size() + (end - begin)); | - | ||||||||||||||||||
1272 | host += QLatin1Char('['); | - | ||||||||||||||||||
1273 | QIPAddressUtils::toString(host, address); | - | ||||||||||||||||||
1274 | host += QLatin1Char(']'); | - | ||||||||||||||||||
1275 | return 0; | - | ||||||||||||||||||
1276 | } | - | ||||||||||||||||||
1277 | - | |||||||||||||||||||
1278 | inline bool QUrlPrivate::setHost(const QString &value, int from, int iend, QUrl::ParsingMode mode) | - | ||||||||||||||||||
1279 | { | - | ||||||||||||||||||
1280 | const QChar *begin = value.constData() + from; | - | ||||||||||||||||||
1281 | const QChar *end = value.constData() + iend; | - | ||||||||||||||||||
1282 | - | |||||||||||||||||||
1283 | const int len = end - begin; | - | ||||||||||||||||||
1284 | host.clear(); | - | ||||||||||||||||||
1285 | sectionIsPresent |= Host; | - | ||||||||||||||||||
1286 | if (len == 0) | - | ||||||||||||||||||
1287 | return true; | - | ||||||||||||||||||
1288 | - | |||||||||||||||||||
1289 | if (begin[0].unicode() == '[') { | - | ||||||||||||||||||
1290 | // IPv6Address or IPvFuture | - | ||||||||||||||||||
1291 | // smallest IPv6 address is "[::]" (len = 4) | - | ||||||||||||||||||
1292 | // smallest IPvFuture address is "[v7.X]" (len = 6) | - | ||||||||||||||||||
1293 | if (end[-1].unicode() != ']') { | - | ||||||||||||||||||
1294 | setError(HostMissingEndBracket, value); | - | ||||||||||||||||||
1295 | return false; | - | ||||||||||||||||||
1296 | } | - | ||||||||||||||||||
1297 | - | |||||||||||||||||||
1298 | if (len > 5 && begin[1].unicode() == 'v') { | - | ||||||||||||||||||
1299 | const QChar *c = parseIpFuture(host, begin, end, mode); | - | ||||||||||||||||||
1300 | if (c) | - | ||||||||||||||||||
1301 | setError(InvalidIPvFutureError, value, c - value.constData()); | - | ||||||||||||||||||
1302 | return !c; | - | ||||||||||||||||||
1303 | } else if (begin[1].unicode() == 'v') { | - | ||||||||||||||||||
1304 | setError(InvalidIPvFutureError, value, from); | - | ||||||||||||||||||
1305 | } | - | ||||||||||||||||||
1306 | - | |||||||||||||||||||
1307 | const QChar *c = parseIp6(host, begin + 1, end - 1, mode); | - | ||||||||||||||||||
1308 | if (!c) | - | ||||||||||||||||||
1309 | return true; | - | ||||||||||||||||||
1310 | - | |||||||||||||||||||
1311 | if (c == end - 1) | - | ||||||||||||||||||
1312 | setError(InvalidIPv6AddressError, value, from); | - | ||||||||||||||||||
1313 | else | - | ||||||||||||||||||
1314 | setError(InvalidCharacterInIPv6Error, value, c - value.constData()); | - | ||||||||||||||||||
1315 | return false; | - | ||||||||||||||||||
1316 | } | - | ||||||||||||||||||
1317 | - | |||||||||||||||||||
1318 | // check if it's an IPv4 address | - | ||||||||||||||||||
1319 | QIPAddressUtils::IPv4Address ip4; | - | ||||||||||||||||||
1320 | if (QIPAddressUtils::parseIp4(ip4, begin, end)) { | - | ||||||||||||||||||
1321 | // yes, it was | - | ||||||||||||||||||
1322 | QIPAddressUtils::toString(host, ip4); | - | ||||||||||||||||||
1323 | return true; | - | ||||||||||||||||||
1324 | } | - | ||||||||||||||||||
1325 | - | |||||||||||||||||||
1326 | // This is probably a reg-name. | - | ||||||||||||||||||
1327 | // But it can also be an encoded string that, when decoded becomes one | - | ||||||||||||||||||
1328 | // of the types above. | - | ||||||||||||||||||
1329 | // | - | ||||||||||||||||||
1330 | // Two types of encoding are possible: | - | ||||||||||||||||||
1331 | // percent encoding (e.g., "%31%30%2E%30%2E%30%2E%31" -> "10.0.0.1") | - | ||||||||||||||||||
1332 | // Unicode encoding (some non-ASCII characters case-fold to digits | - | ||||||||||||||||||
1333 | // when nameprepping is done) | - | ||||||||||||||||||
1334 | // | - | ||||||||||||||||||
1335 | // The qt_ACE_do function below applies nameprepping and the STD3 check. | - | ||||||||||||||||||
1336 | // That means a Unicode string may become an IPv4 address, but it cannot | - | ||||||||||||||||||
1337 | // produce a '[' or a '%'. | - | ||||||||||||||||||
1338 | - | |||||||||||||||||||
1339 | // check for percent-encoding first | - | ||||||||||||||||||
1340 | QString s; | - | ||||||||||||||||||
1341 | if (mode == QUrl::TolerantMode && qt_urlRecode(s, begin, end, 0, 0)) { | - | ||||||||||||||||||
1342 | // something was decoded | - | ||||||||||||||||||
1343 | // anything encoded left? | - | ||||||||||||||||||
1344 | int pos = s.indexOf(QChar(0x25)); // '%' | - | ||||||||||||||||||
1345 | if (pos != -1) { | - | ||||||||||||||||||
1346 | setError(InvalidRegNameError, s, pos); | - | ||||||||||||||||||
1347 | return false; | - | ||||||||||||||||||
1348 | } | - | ||||||||||||||||||
1349 | - | |||||||||||||||||||
1350 | // recurse | - | ||||||||||||||||||
1351 | return setHost(s, 0, s.length(), QUrl::StrictMode); | - | ||||||||||||||||||
1352 | } | - | ||||||||||||||||||
1353 | - | |||||||||||||||||||
1354 | s = qt_ACE_do(QString::fromRawData(begin, len), NormalizeAce, ForbidLeadingDot); | - | ||||||||||||||||||
1355 | if (s.isEmpty()) { | - | ||||||||||||||||||
1356 | setError(InvalidRegNameError, value); | - | ||||||||||||||||||
1357 | return false; | - | ||||||||||||||||||
1358 | } | - | ||||||||||||||||||
1359 | - | |||||||||||||||||||
1360 | // check IPv4 again | - | ||||||||||||||||||
1361 | if (QIPAddressUtils::parseIp4(ip4, s.constBegin(), s.constEnd())) { | - | ||||||||||||||||||
1362 | QIPAddressUtils::toString(host, ip4); | - | ||||||||||||||||||
1363 | } else { | - | ||||||||||||||||||
1364 | host = s; | - | ||||||||||||||||||
1365 | } | - | ||||||||||||||||||
1366 | return true; | - | ||||||||||||||||||
1367 | } | - | ||||||||||||||||||
1368 | - | |||||||||||||||||||
1369 | inline void QUrlPrivate::parse(const QString &url, QUrl::ParsingMode parsingMode) | - | ||||||||||||||||||
1370 | { | - | ||||||||||||||||||
1371 | // URI-reference = URI / relative-ref | - | ||||||||||||||||||
1372 | // URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] | - | ||||||||||||||||||
1373 | // relative-ref = relative-part [ "?" query ] [ "#" fragment ] | - | ||||||||||||||||||
1374 | // hier-part = "//" authority path-abempty | - | ||||||||||||||||||
1375 | // / other path types | - | ||||||||||||||||||
1376 | // relative-part = "//" authority path-abempty | - | ||||||||||||||||||
1377 | // / other path types here | - | ||||||||||||||||||
1378 | - | |||||||||||||||||||
1379 | sectionIsPresent = 0; | - | ||||||||||||||||||
1380 | flags = 0; | - | ||||||||||||||||||
1381 | clearError(); | - | ||||||||||||||||||
1382 | - | |||||||||||||||||||
1383 | // find the important delimiters | - | ||||||||||||||||||
1384 | int colon = -1; | - | ||||||||||||||||||
1385 | int question = -1; | - | ||||||||||||||||||
1386 | int hash = -1; | - | ||||||||||||||||||
1387 | const int len = url.length(); | - | ||||||||||||||||||
1388 | const QChar *const begin = url.constData(); | - | ||||||||||||||||||
1389 | const ushort *const data = reinterpret_cast<const ushort *>(begin); | - | ||||||||||||||||||
1390 | - | |||||||||||||||||||
1391 | for (int i = 0; i < len; ++i) { | - | ||||||||||||||||||
1392 | uint uc = data[i]; | - | ||||||||||||||||||
1393 | if (uc == '#' && hash == -1) { | - | ||||||||||||||||||
1394 | hash = i; | - | ||||||||||||||||||
1395 | - | |||||||||||||||||||
1396 | // nothing more to be found | - | ||||||||||||||||||
1397 | break; | - | ||||||||||||||||||
1398 | } | - | ||||||||||||||||||
1399 | - | |||||||||||||||||||
1400 | if (question == -1) { | - | ||||||||||||||||||
1401 | if (uc == ':' && colon == -1) | - | ||||||||||||||||||
1402 | colon = i; | - | ||||||||||||||||||
1403 | else if (uc == '?') | - | ||||||||||||||||||
1404 | question = i; | - | ||||||||||||||||||
1405 | } | - | ||||||||||||||||||
1406 | } | - | ||||||||||||||||||
1407 | - | |||||||||||||||||||
1408 | // check if we have a scheme | - | ||||||||||||||||||
1409 | int hierStart; | - | ||||||||||||||||||
1410 | if (colon != -1 && setScheme(url, colon, /* don't set error */ false)) { | - | ||||||||||||||||||
1411 | hierStart = colon + 1; | - | ||||||||||||||||||
1412 | } else { | - | ||||||||||||||||||
1413 | // recover from a failed scheme: it might not have been a scheme at all | - | ||||||||||||||||||
1414 | scheme.clear(); | - | ||||||||||||||||||
1415 | sectionIsPresent = 0; | - | ||||||||||||||||||
1416 | hierStart = 0; | - | ||||||||||||||||||
1417 | } | - | ||||||||||||||||||
1418 | - | |||||||||||||||||||
1419 | int pathStart; | - | ||||||||||||||||||
1420 | int hierEnd = qMin<uint>(qMin<uint>(question, hash), len); | - | ||||||||||||||||||
1421 | if (hierEnd - hierStart >= 2 && data[hierStart] == '/' && data[hierStart + 1] == '/') { | - | ||||||||||||||||||
1422 | // we have an authority, it ends at the first slash after these | - | ||||||||||||||||||
1423 | int authorityEnd = hierEnd; | - | ||||||||||||||||||
1424 | for (int i = hierStart + 2; i < authorityEnd ; ++i) { | - | ||||||||||||||||||
1425 | if (data[i] == '/') { | - | ||||||||||||||||||
1426 | authorityEnd = i; | - | ||||||||||||||||||
1427 | break; | - | ||||||||||||||||||
1428 | } | - | ||||||||||||||||||
1429 | } | - | ||||||||||||||||||
1430 | - | |||||||||||||||||||
1431 | setAuthority(url, hierStart + 2, authorityEnd, parsingMode); | - | ||||||||||||||||||
1432 | - | |||||||||||||||||||
1433 | // even if we failed to set the authority properly, let's try to recover | - | ||||||||||||||||||
1434 | pathStart = authorityEnd; | - | ||||||||||||||||||
1435 | setPath(url, pathStart, hierEnd); | - | ||||||||||||||||||
1436 | } else { | - | ||||||||||||||||||
1437 | userName.clear(); | - | ||||||||||||||||||
1438 | password.clear(); | - | ||||||||||||||||||
1439 | host.clear(); | - | ||||||||||||||||||
1440 | port = -1; | - | ||||||||||||||||||
1441 | pathStart = hierStart; | - | ||||||||||||||||||
1442 | - | |||||||||||||||||||
1443 | if (hierStart < hierEnd) | - | ||||||||||||||||||
1444 | setPath(url, hierStart, hierEnd); | - | ||||||||||||||||||
1445 | else | - | ||||||||||||||||||
1446 | path.clear(); | - | ||||||||||||||||||
1447 | } | - | ||||||||||||||||||
1448 | - | |||||||||||||||||||
1449 | if (uint(question) < uint(hash)) | - | ||||||||||||||||||
1450 | setQuery(url, question + 1, qMin<uint>(hash, len)); | - | ||||||||||||||||||
1451 | - | |||||||||||||||||||
1452 | if (hash != -1) | - | ||||||||||||||||||
1453 | setFragment(url, hash + 1, len); | - | ||||||||||||||||||
1454 | - | |||||||||||||||||||
1455 | if (error || parsingMode == QUrl::TolerantMode) | - | ||||||||||||||||||
1456 | return; | - | ||||||||||||||||||
1457 | - | |||||||||||||||||||
1458 | // The parsing so far was partially tolerant of errors, except for the | - | ||||||||||||||||||
1459 | // scheme parser (which is always strict) and the authority (which was | - | ||||||||||||||||||
1460 | // executed in strict mode). | - | ||||||||||||||||||
1461 | // If we haven't found any errors so far, continue the strict-mode parsing | - | ||||||||||||||||||
1462 | // from the path component onwards. | - | ||||||||||||||||||
1463 | - | |||||||||||||||||||
1464 | if (!validateComponent(Path, url, pathStart, hierEnd)) | - | ||||||||||||||||||
1465 | return; | - | ||||||||||||||||||
1466 | if (uint(question) < uint(hash) && !validateComponent(Query, url, question + 1, qMin<uint>(hash, len))) | - | ||||||||||||||||||
1467 | return; | - | ||||||||||||||||||
1468 | if (hash != -1) | - | ||||||||||||||||||
1469 | validateComponent(Fragment, url, hash + 1, len); | - | ||||||||||||||||||
1470 | } | - | ||||||||||||||||||
1471 | - | |||||||||||||||||||
1472 | QString QUrlPrivate::toLocalFile(QUrl::FormattingOptions options) const | - | ||||||||||||||||||
1473 | { | - | ||||||||||||||||||
1474 | QString tmp; | - | ||||||||||||||||||
1475 | QString ourPath; | - | ||||||||||||||||||
1476 | appendPath(ourPath, options, QUrlPrivate::Path); | - | ||||||||||||||||||
1477 | - | |||||||||||||||||||
1478 | // magic for shared drive on windows | - | ||||||||||||||||||
1479 | if (!host.isEmpty()) {
| 4-10627 | ||||||||||||||||||
1480 | tmp = QStringLiteralQLatin1String("//") + host; | - | ||||||||||||||||||
1481 | #ifdef Q_OS_WIN // QTBUG-42346, WebDAV is visible as local file on Windows only. | - | ||||||||||||||||||
1482 | if (scheme == webDavScheme()) | - | ||||||||||||||||||
1483 | tmp += webDavSslTag(); | - | ||||||||||||||||||
1484 | #endif | - | ||||||||||||||||||
1485 | if (!ourPath.isEmpty() && !ourPath.startsWith(QLatin1Char('/')))
| 1-3 | ||||||||||||||||||
1486 | tmp += QLatin1Char('/'); executed 1 time by 1 test: tmp += QLatin1Char('/'); Executed by:
| 1 | ||||||||||||||||||
1487 | tmp += ourPath; | - | ||||||||||||||||||
1488 | } else { executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
1489 | tmp = ourPath; | - | ||||||||||||||||||
1490 | #ifdef Q_OS_WIN | - | ||||||||||||||||||
1491 | // magic for drives on windows | - | ||||||||||||||||||
1492 | if (ourPath.length() > 2 && ourPath.at(0) == QLatin1Char('/') && ourPath.at(2) == QLatin1Char(':')) | - | ||||||||||||||||||
1493 | tmp.remove(0, 1); | - | ||||||||||||||||||
1494 | #endif | - | ||||||||||||||||||
1495 | } executed 10627 times by 15 tests: end of block Executed by:
| 10627 | ||||||||||||||||||
1496 | return tmp; executed 10631 times by 15 tests: return tmp; Executed by:
| 10631 | ||||||||||||||||||
1497 | } | - | ||||||||||||||||||
1498 | - | |||||||||||||||||||
1499 | /* | - | ||||||||||||||||||
1500 | From http://www.ietf.org/rfc/rfc3986.txt, 5.2.3: Merge paths | - | ||||||||||||||||||
1501 | - | |||||||||||||||||||
1502 | Returns a merge of the current path with the relative path passed | - | ||||||||||||||||||
1503 | as argument. | - | ||||||||||||||||||
1504 | - | |||||||||||||||||||
1505 | Note: \a relativePath is relative (does not start with '/'). | - | ||||||||||||||||||
1506 | */ | - | ||||||||||||||||||
1507 | inline QString QUrlPrivate::mergePaths(const QString &relativePath) const | - | ||||||||||||||||||
1508 | { | - | ||||||||||||||||||
1509 | // If the base URI has a defined authority component and an empty | - | ||||||||||||||||||
1510 | // path, then return a string consisting of "/" concatenated with | - | ||||||||||||||||||
1511 | // the reference's path; otherwise, | - | ||||||||||||||||||
1512 | if (!host.isEmpty() && path.isEmpty()) | - | ||||||||||||||||||
1513 | return QLatin1Char('/') + relativePath; | - | ||||||||||||||||||
1514 | - | |||||||||||||||||||
1515 | // Return a string consisting of the reference's path component | - | ||||||||||||||||||
1516 | // appended to all but the last segment of the base URI's path | - | ||||||||||||||||||
1517 | // (i.e., excluding any characters after the right-most "/" in the | - | ||||||||||||||||||
1518 | // base URI path, or excluding the entire base URI path if it does | - | ||||||||||||||||||
1519 | // not contain any "/" characters). | - | ||||||||||||||||||
1520 | QString newPath; | - | ||||||||||||||||||
1521 | if (!path.contains(QLatin1Char('/'))) | - | ||||||||||||||||||
1522 | newPath = relativePath; | - | ||||||||||||||||||
1523 | else | - | ||||||||||||||||||
1524 | newPath = path.leftRef(path.lastIndexOf(QLatin1Char('/')) + 1) + relativePath; | - | ||||||||||||||||||
1525 | - | |||||||||||||||||||
1526 | return newPath; | - | ||||||||||||||||||
1527 | } | - | ||||||||||||||||||
1528 | - | |||||||||||||||||||
1529 | /* | - | ||||||||||||||||||
1530 | From http://www.ietf.org/rfc/rfc3986.txt, 5.2.4: Remove dot segments | - | ||||||||||||||||||
1531 | - | |||||||||||||||||||
1532 | Removes unnecessary ../ and ./ from the path. Used for normalizing | - | ||||||||||||||||||
1533 | the URL. | - | ||||||||||||||||||
1534 | */ | - | ||||||||||||||||||
1535 | static void removeDotsFromPath(QString *path) | - | ||||||||||||||||||
1536 | { | - | ||||||||||||||||||
1537 | // The input buffer is initialized with the now-appended path | - | ||||||||||||||||||
1538 | // components and the output buffer is initialized to the empty | - | ||||||||||||||||||
1539 | // string. | - | ||||||||||||||||||
1540 | QChar *out = path->data(); | - | ||||||||||||||||||
1541 | const QChar *in = out; | - | ||||||||||||||||||
1542 | const QChar *end = out + path->size(); | - | ||||||||||||||||||
1543 | - | |||||||||||||||||||
1544 | // If the input buffer consists only of | - | ||||||||||||||||||
1545 | // "." or "..", then remove that from the input | - | ||||||||||||||||||
1546 | // buffer; | - | ||||||||||||||||||
1547 | if (path->size() == 1 && in[0].unicode() == '.') | - | ||||||||||||||||||
1548 | ++in; | - | ||||||||||||||||||
1549 | else if (path->size() == 2 && in[0].unicode() == '.' && in[1].unicode() == '.') | - | ||||||||||||||||||
1550 | in += 2; | - | ||||||||||||||||||
1551 | // While the input buffer is not empty, loop: | - | ||||||||||||||||||
1552 | while (in < end) { | - | ||||||||||||||||||
1553 | - | |||||||||||||||||||
1554 | // otherwise, if the input buffer begins with a prefix of "../" or "./", | - | ||||||||||||||||||
1555 | // then remove that prefix from the input buffer; | - | ||||||||||||||||||
1556 | if (path->size() >= 2 && in[0].unicode() == '.' && in[1].unicode() == '/') | - | ||||||||||||||||||
1557 | in += 2; | - | ||||||||||||||||||
1558 | else if (path->size() >= 3 && in[0].unicode() == '.' | - | ||||||||||||||||||
1559 | && in[1].unicode() == '.' && in[2].unicode() == '/') | - | ||||||||||||||||||
1560 | in += 3; | - | ||||||||||||||||||
1561 | - | |||||||||||||||||||
1562 | // otherwise, if the input buffer begins with a prefix of | - | ||||||||||||||||||
1563 | // "/./" or "/.", where "." is a complete path segment, | - | ||||||||||||||||||
1564 | // then replace that prefix with "/" in the input buffer; | - | ||||||||||||||||||
1565 | if (in <= end - 3 && in[0].unicode() == '/' && in[1].unicode() == '.' | - | ||||||||||||||||||
1566 | && in[2].unicode() == '/') { | - | ||||||||||||||||||
1567 | in += 2; | - | ||||||||||||||||||
1568 | continue; | - | ||||||||||||||||||
1569 | } else if (in == end - 2 && in[0].unicode() == '/' && in[1].unicode() == '.') { | - | ||||||||||||||||||
1570 | *out++ = QLatin1Char('/'); | - | ||||||||||||||||||
1571 | in += 2; | - | ||||||||||||||||||
1572 | break; | - | ||||||||||||||||||
1573 | } | - | ||||||||||||||||||
1574 | - | |||||||||||||||||||
1575 | // otherwise, if the input buffer begins with a prefix | - | ||||||||||||||||||
1576 | // of "/../" or "/..", where ".." is a complete path | - | ||||||||||||||||||
1577 | // segment, then replace that prefix with "/" in the | - | ||||||||||||||||||
1578 | // input buffer and remove the last //segment and its | - | ||||||||||||||||||
1579 | // preceding "/" (if any) from the output buffer; | - | ||||||||||||||||||
1580 | if (in <= end - 4 && in[0].unicode() == '/' && in[1].unicode() == '.' | - | ||||||||||||||||||
1581 | && in[2].unicode() == '.' && in[3].unicode() == '/') { | - | ||||||||||||||||||
1582 | while (out > path->constData() && (--out)->unicode() != '/') | - | ||||||||||||||||||
1583 | ; | - | ||||||||||||||||||
1584 | if (out == path->constData() && out->unicode() != '/') | - | ||||||||||||||||||
1585 | ++in; | - | ||||||||||||||||||
1586 | in += 3; | - | ||||||||||||||||||
1587 | continue; | - | ||||||||||||||||||
1588 | } else if (in == end - 3 && in[0].unicode() == '/' && in[1].unicode() == '.' | - | ||||||||||||||||||
1589 | && in[2].unicode() == '.') { | - | ||||||||||||||||||
1590 | while (out > path->constData() && (--out)->unicode() != '/') | - | ||||||||||||||||||
1591 | ; | - | ||||||||||||||||||
1592 | if (out->unicode() == '/') | - | ||||||||||||||||||
1593 | ++out; | - | ||||||||||||||||||
1594 | in += 3; | - | ||||||||||||||||||
1595 | break; | - | ||||||||||||||||||
1596 | } | - | ||||||||||||||||||
1597 | - | |||||||||||||||||||
1598 | // otherwise move the first path segment in | - | ||||||||||||||||||
1599 | // the input buffer to the end of the output | - | ||||||||||||||||||
1600 | // buffer, including the initial "/" character | - | ||||||||||||||||||
1601 | // (if any) and any subsequent characters up | - | ||||||||||||||||||
1602 | // to, but not including, the next "/" | - | ||||||||||||||||||
1603 | // character or the end of the input buffer. | - | ||||||||||||||||||
1604 | *out++ = *in++; | - | ||||||||||||||||||
1605 | while (in < end && in->unicode() != '/') | - | ||||||||||||||||||
1606 | *out++ = *in++; | - | ||||||||||||||||||
1607 | } | - | ||||||||||||||||||
1608 | path->truncate(out - path->constData()); | - | ||||||||||||||||||
1609 | } | - | ||||||||||||||||||
1610 | - | |||||||||||||||||||
1611 | inline QUrlPrivate::ErrorCode QUrlPrivate::validityError(QString *source, int *position) const | - | ||||||||||||||||||
1612 | { | - | ||||||||||||||||||
1613 | Q_ASSERT(!source == !position); | - | ||||||||||||||||||
1614 | if (error) { | - | ||||||||||||||||||
1615 | if (source) { | - | ||||||||||||||||||
1616 | *source = error->source; | - | ||||||||||||||||||
1617 | *position = error->position; | - | ||||||||||||||||||
1618 | } | - | ||||||||||||||||||
1619 | return error->code; | - | ||||||||||||||||||
1620 | } | - | ||||||||||||||||||
1621 | - | |||||||||||||||||||
1622 | // There are two more cases of invalid URLs that QUrl recognizes and they | - | ||||||||||||||||||
1623 | // are only possible with constructed URLs (setXXX methods), not with | - | ||||||||||||||||||
1624 | // parsing. Therefore, they are tested here. | - | ||||||||||||||||||
1625 | // | - | ||||||||||||||||||
1626 | // The two cases are a non-empty path that doesn't start with a slash and: | - | ||||||||||||||||||
1627 | // - with an authority | - | ||||||||||||||||||
1628 | // - without an authority, without scheme but the path with a colon before | - | ||||||||||||||||||
1629 | // the first slash | - | ||||||||||||||||||
1630 | // Those cases are considered invalid because toString() would produce a URL | - | ||||||||||||||||||
1631 | // that wouldn't be parsed back to the same QUrl. | - | ||||||||||||||||||
1632 | - | |||||||||||||||||||
1633 | if (path.isEmpty() || path.at(0) == QLatin1Char('/')) | - | ||||||||||||||||||
1634 | return NoError; | - | ||||||||||||||||||
1635 | if (sectionIsPresent & QUrlPrivate::Host) { | - | ||||||||||||||||||
1636 | if (source) { | - | ||||||||||||||||||
1637 | *source = path; | - | ||||||||||||||||||
1638 | *position = 0; | - | ||||||||||||||||||
1639 | } | - | ||||||||||||||||||
1640 | return AuthorityPresentAndPathIsRelative; | - | ||||||||||||||||||
1641 | } | - | ||||||||||||||||||
1642 | if (sectionIsPresent & QUrlPrivate::Scheme) | - | ||||||||||||||||||
1643 | return NoError; | - | ||||||||||||||||||
1644 | - | |||||||||||||||||||
1645 | // check for a path of "text:text/" | - | ||||||||||||||||||
1646 | for (int i = 0; i < path.length(); ++i) { | - | ||||||||||||||||||
1647 | ushort c = path.at(i).unicode(); | - | ||||||||||||||||||
1648 | if (c == '/') { | - | ||||||||||||||||||
1649 | // found the slash before the colon | - | ||||||||||||||||||
1650 | return NoError; | - | ||||||||||||||||||
1651 | } | - | ||||||||||||||||||
1652 | if (c == ':') { | - | ||||||||||||||||||
1653 | // found the colon before the slash, it's invalid | - | ||||||||||||||||||
1654 | if (source) { | - | ||||||||||||||||||
1655 | *source = path; | - | ||||||||||||||||||
1656 | *position = i; | - | ||||||||||||||||||
1657 | } | - | ||||||||||||||||||
1658 | return RelativeUrlPathContainsColonBeforeSlash; | - | ||||||||||||||||||
1659 | } | - | ||||||||||||||||||
1660 | } | - | ||||||||||||||||||
1661 | return NoError; | - | ||||||||||||||||||
1662 | } | - | ||||||||||||||||||
1663 | - | |||||||||||||||||||
1664 | bool QUrlPrivate::validateComponent(QUrlPrivate::Section section, const QString &input, | - | ||||||||||||||||||
1665 | int begin, int end) | - | ||||||||||||||||||
1666 | { | - | ||||||||||||||||||
1667 | // What we need to look out for, that the regular parser tolerates: | - | ||||||||||||||||||
1668 | // - percent signs not followed by two hex digits | - | ||||||||||||||||||
1669 | // - forbidden characters, which should always appear encoded | - | ||||||||||||||||||
1670 | // '"' / '<' / '>' / '\' / '^' / '`' / '{' / '|' / '}' / BKSP | - | ||||||||||||||||||
1671 | // control characters | - | ||||||||||||||||||
1672 | // - delimiters not allowed in certain positions | - | ||||||||||||||||||
1673 | // . scheme: parser is already strict | - | ||||||||||||||||||
1674 | // . user info: gen-delims except ":" disallowed ("/" / "?" / "#" / "[" / "]" / "@") | - | ||||||||||||||||||
1675 | // . host: parser is stricter than the standard | - | ||||||||||||||||||
1676 | // . port: parser is stricter than the standard | - | ||||||||||||||||||
1677 | // . path: all delimiters allowed | - | ||||||||||||||||||
1678 | // . fragment: all delimiters allowed | - | ||||||||||||||||||
1679 | // . query: all delimiters allowed | - | ||||||||||||||||||
1680 | static const char forbidden[] = "\"<>\\^`{|}\x7F"; | - | ||||||||||||||||||
1681 | static const char forbiddenUserInfo[] = ":/?#[]@"; | - | ||||||||||||||||||
1682 | - | |||||||||||||||||||
1683 | Q_ASSERT(section != Authority && section != Hierarchy && section != FullUrl); | - | ||||||||||||||||||
1684 | - | |||||||||||||||||||
1685 | const ushort *const data = reinterpret_cast<const ushort *>(input.constData()); | - | ||||||||||||||||||
1686 | for (uint i = uint(begin); i < uint(end); ++i) { | - | ||||||||||||||||||
1687 | uint uc = data[i]; | - | ||||||||||||||||||
1688 | if (uc >= 0x80) | - | ||||||||||||||||||
1689 | continue; | - | ||||||||||||||||||
1690 | - | |||||||||||||||||||
1691 | bool error = false; | - | ||||||||||||||||||
1692 | if ((uc == '%' && (uint(end) < i + 2 || !isHex(data[i + 1]) || !isHex(data[i + 2]))) | - | ||||||||||||||||||
1693 | || uc <= 0x20 || strchr(forbidden, uc)) { | - | ||||||||||||||||||
1694 | // found an error | - | ||||||||||||||||||
1695 | error = true; | - | ||||||||||||||||||
1696 | } else if (section & UserInfo) { | - | ||||||||||||||||||
1697 | if (section == UserInfo && strchr(forbiddenUserInfo + 1, uc)) | - | ||||||||||||||||||
1698 | error = true; | - | ||||||||||||||||||
1699 | else if (section != UserInfo && strchr(forbiddenUserInfo, uc)) | - | ||||||||||||||||||
1700 | error = true; | - | ||||||||||||||||||
1701 | } | - | ||||||||||||||||||
1702 | - | |||||||||||||||||||
1703 | if (!error) | - | ||||||||||||||||||
1704 | continue; | - | ||||||||||||||||||
1705 | - | |||||||||||||||||||
1706 | ErrorCode errorCode = ErrorCode(int(section) << 8); | - | ||||||||||||||||||
1707 | if (section == UserInfo) { | - | ||||||||||||||||||
1708 | // is it the user name or the password? | - | ||||||||||||||||||
1709 | errorCode = InvalidUserNameError; | - | ||||||||||||||||||
1710 | for (uint j = uint(begin); j < i; ++j) | - | ||||||||||||||||||
1711 | if (data[j] == ':') { | - | ||||||||||||||||||
1712 | errorCode = InvalidPasswordError; | - | ||||||||||||||||||
1713 | break; | - | ||||||||||||||||||
1714 | } | - | ||||||||||||||||||
1715 | } | - | ||||||||||||||||||
1716 | - | |||||||||||||||||||
1717 | setError(errorCode, input, i); | - | ||||||||||||||||||
1718 | return false; | - | ||||||||||||||||||
1719 | } | - | ||||||||||||||||||
1720 | - | |||||||||||||||||||
1721 | // no errors | - | ||||||||||||||||||
1722 | return true; | - | ||||||||||||||||||
1723 | } | - | ||||||||||||||||||
1724 | - | |||||||||||||||||||
1725 | #if 0 | - | ||||||||||||||||||
1726 | inline void QUrlPrivate::validate() const | - | ||||||||||||||||||
1727 | { | - | ||||||||||||||||||
1728 | QUrlPrivate *that = (QUrlPrivate *)this; | - | ||||||||||||||||||
1729 | that->encodedOriginal = that->toEncoded(); // may detach | - | ||||||||||||||||||
1730 | parse(ParseOnly); | - | ||||||||||||||||||
1731 | - | |||||||||||||||||||
1732 | QURL_SETFLAG(that->stateFlags, Validated); | - | ||||||||||||||||||
1733 | - | |||||||||||||||||||
1734 | if (!isValid) | - | ||||||||||||||||||
1735 | return; | - | ||||||||||||||||||
1736 | - | |||||||||||||||||||
1737 | QString auth = authority(); // causes the non-encoded forms to be valid | - | ||||||||||||||||||
1738 | - | |||||||||||||||||||
1739 | // authority() calls canonicalHost() which sets this | - | ||||||||||||||||||
1740 | if (!isHostValid) | - | ||||||||||||||||||
1741 | return; | - | ||||||||||||||||||
1742 | - | |||||||||||||||||||
1743 | if (scheme == QLatin1String("mailto")) { | - | ||||||||||||||||||
1744 | if (!host.isEmpty() || port != -1 || !userName.isEmpty() || !password.isEmpty()) { | - | ||||||||||||||||||
1745 | that->isValid = false; | - | ||||||||||||||||||
1746 | that->errorInfo.setParams(0, QT_TRANSLATE_NOOP(QUrl, "expected empty host, username," | - | ||||||||||||||||||
1747 | "port and password"), | - | ||||||||||||||||||
1748 | 0, 0); | - | ||||||||||||||||||
1749 | } | - | ||||||||||||||||||
1750 | } else if (scheme == ftpScheme() || scheme == httpScheme()) { | - | ||||||||||||||||||
1751 | if (host.isEmpty() && !(path.isEmpty() && encodedPath.isEmpty())) { | - | ||||||||||||||||||
1752 | that->isValid = false; | - | ||||||||||||||||||
1753 | that->errorInfo.setParams(0, QT_TRANSLATE_NOOP(QUrl, "the host is empty, but not the path"), | - | ||||||||||||||||||
1754 | 0, 0); | - | ||||||||||||||||||
1755 | } | - | ||||||||||||||||||
1756 | } | - | ||||||||||||||||||
1757 | } | - | ||||||||||||||||||
1758 | #endif | - | ||||||||||||||||||
1759 | - | |||||||||||||||||||
1760 | /*! | - | ||||||||||||||||||
1761 | \macro QT_NO_URL_CAST_FROM_STRING | - | ||||||||||||||||||
1762 | \relates QUrl | - | ||||||||||||||||||
1763 | - | |||||||||||||||||||
1764 | Disables automatic conversions from QString (or char *) to QUrl. | - | ||||||||||||||||||
1765 | - | |||||||||||||||||||
1766 | Compiling your code with this define is useful when you have a lot of | - | ||||||||||||||||||
1767 | code that uses QString for file names and you wish to convert it to | - | ||||||||||||||||||
1768 | use QUrl for network transparency. In any code that uses QUrl, it can | - | ||||||||||||||||||
1769 | help avoid missing QUrl::resolved() calls, and other misuses of | - | ||||||||||||||||||
1770 | QString to QUrl conversions. | - | ||||||||||||||||||
1771 | - | |||||||||||||||||||
1772 | \oldcode | - | ||||||||||||||||||
1773 | url = filename; // probably not what you want | - | ||||||||||||||||||
1774 | \newcode | - | ||||||||||||||||||
1775 | url = QUrl::fromLocalFile(filename); | - | ||||||||||||||||||
1776 | url = baseurl.resolved(QUrl(filename)); | - | ||||||||||||||||||
1777 | \endcode | - | ||||||||||||||||||
1778 | - | |||||||||||||||||||
1779 | \sa QT_NO_CAST_FROM_ASCII | - | ||||||||||||||||||
1780 | */ | - | ||||||||||||||||||
1781 | - | |||||||||||||||||||
1782 | - | |||||||||||||||||||
1783 | /*! | - | ||||||||||||||||||
1784 | Constructs a URL by parsing \a url. QUrl will automatically percent encode | - | ||||||||||||||||||
1785 | all characters that are not allowed in a URL and decode the percent-encoded | - | ||||||||||||||||||
1786 | sequences that represent an unreserved character (letters, digits, hyphens, | - | ||||||||||||||||||
1787 | undercores, dots and tildes). All other characters are left in their | - | ||||||||||||||||||
1788 | original forms. | - | ||||||||||||||||||
1789 | - | |||||||||||||||||||
1790 | Parses the \a url using the parser mode \a parsingMode. In TolerantMode | - | ||||||||||||||||||
1791 | (the default), QUrl will correct certain mistakes, notably the presence of | - | ||||||||||||||||||
1792 | a percent character ('%') not followed by two hexadecimal digits, and it | - | ||||||||||||||||||
1793 | will accept any character in any position. In StrictMode, encoding mistakes | - | ||||||||||||||||||
1794 | will not be tolerated and QUrl will also check that certain forbidden | - | ||||||||||||||||||
1795 | characters are not present in unencoded form. If an error is detected in | - | ||||||||||||||||||
1796 | StrictMode, isValid() will return false. The parsing mode DecodedMode is not | - | ||||||||||||||||||
1797 | permitted in this context. | - | ||||||||||||||||||
1798 | - | |||||||||||||||||||
1799 | Example: | - | ||||||||||||||||||
1800 | - | |||||||||||||||||||
1801 | \snippet code/src_corelib_io_qurl.cpp 0 | - | ||||||||||||||||||
1802 | - | |||||||||||||||||||
1803 | To construct a URL from an encoded string, you can also use fromEncoded(): | - | ||||||||||||||||||
1804 | - | |||||||||||||||||||
1805 | \snippet code/src_corelib_io_qurl.cpp 1 | - | ||||||||||||||||||
1806 | - | |||||||||||||||||||
1807 | Both functions are equivalent and, in Qt 5, both functions accept encoded | - | ||||||||||||||||||
1808 | data. Usually, the choice of the QUrl constructor or setUrl() versus | - | ||||||||||||||||||
1809 | fromEncoded() will depend on the source data: the constructor and setUrl() | - | ||||||||||||||||||
1810 | take a QString, whereas fromEncoded takes a QByteArray. | - | ||||||||||||||||||
1811 | - | |||||||||||||||||||
1812 | \sa setUrl(), fromEncoded(), TolerantMode | - | ||||||||||||||||||
1813 | */ | - | ||||||||||||||||||
1814 | QUrl::QUrl(const QString &url, ParsingMode parsingMode) : d(0) | - | ||||||||||||||||||
1815 | { | - | ||||||||||||||||||
1816 | setUrl(url, parsingMode); | - | ||||||||||||||||||
1817 | } | - | ||||||||||||||||||
1818 | - | |||||||||||||||||||
1819 | /*! | - | ||||||||||||||||||
1820 | Constructs an empty QUrl object. | - | ||||||||||||||||||
1821 | */ | - | ||||||||||||||||||
1822 | QUrl::QUrl() : d(0) | - | ||||||||||||||||||
1823 | { | - | ||||||||||||||||||
1824 | } | - | ||||||||||||||||||
1825 | - | |||||||||||||||||||
1826 | /*! | - | ||||||||||||||||||
1827 | Constructs a copy of \a other. | - | ||||||||||||||||||
1828 | */ | - | ||||||||||||||||||
1829 | QUrl::QUrl(const QUrl &other) : d(other.d) | - | ||||||||||||||||||
1830 | { | - | ||||||||||||||||||
1831 | if (d) | - | ||||||||||||||||||
1832 | d->ref.ref(); | - | ||||||||||||||||||
1833 | } | - | ||||||||||||||||||
1834 | - | |||||||||||||||||||
1835 | /*! | - | ||||||||||||||||||
1836 | Destructor; called immediately before the object is deleted. | - | ||||||||||||||||||
1837 | */ | - | ||||||||||||||||||
1838 | QUrl::~QUrl() | - | ||||||||||||||||||
1839 | { | - | ||||||||||||||||||
1840 | if (d && !d->ref.deref()) | - | ||||||||||||||||||
1841 | delete d; | - | ||||||||||||||||||
1842 | } | - | ||||||||||||||||||
1843 | - | |||||||||||||||||||
1844 | /*! | - | ||||||||||||||||||
1845 | Returns \c true if the URL is non-empty and valid; otherwise returns \c false. | - | ||||||||||||||||||
1846 | - | |||||||||||||||||||
1847 | The URL is run through a conformance test. Every part of the URL | - | ||||||||||||||||||
1848 | must conform to the standard encoding rules of the URI standard | - | ||||||||||||||||||
1849 | for the URL to be reported as valid. | - | ||||||||||||||||||
1850 | - | |||||||||||||||||||
1851 | \snippet code/src_corelib_io_qurl.cpp 2 | - | ||||||||||||||||||
1852 | */ | - | ||||||||||||||||||
1853 | bool QUrl::isValid() const | - | ||||||||||||||||||
1854 | { | - | ||||||||||||||||||
1855 | if (isEmpty()) { | - | ||||||||||||||||||
1856 | // also catches d == 0 | - | ||||||||||||||||||
1857 | return false; | - | ||||||||||||||||||
1858 | } | - | ||||||||||||||||||
1859 | return d->validityError() == QUrlPrivate::NoError; | - | ||||||||||||||||||
1860 | } | - | ||||||||||||||||||
1861 | - | |||||||||||||||||||
1862 | /*! | - | ||||||||||||||||||
1863 | Returns \c true if the URL has no data; otherwise returns \c false. | - | ||||||||||||||||||
1864 | - | |||||||||||||||||||
1865 | \sa clear() | - | ||||||||||||||||||
1866 | */ | - | ||||||||||||||||||
1867 | bool QUrl::isEmpty() const | - | ||||||||||||||||||
1868 | { | - | ||||||||||||||||||
1869 | if (!d) return true; | - | ||||||||||||||||||
1870 | return d->isEmpty(); | - | ||||||||||||||||||
1871 | } | - | ||||||||||||||||||
1872 | - | |||||||||||||||||||
1873 | /*! | - | ||||||||||||||||||
1874 | Resets the content of the QUrl. After calling this function, the | - | ||||||||||||||||||
1875 | QUrl is equal to one that has been constructed with the default | - | ||||||||||||||||||
1876 | empty constructor. | - | ||||||||||||||||||
1877 | - | |||||||||||||||||||
1878 | \sa isEmpty() | - | ||||||||||||||||||
1879 | */ | - | ||||||||||||||||||
1880 | void QUrl::clear() | - | ||||||||||||||||||
1881 | { | - | ||||||||||||||||||
1882 | if (d && !d->ref.deref()) | - | ||||||||||||||||||
1883 | delete d; | - | ||||||||||||||||||
1884 | d = 0; | - | ||||||||||||||||||
1885 | } | - | ||||||||||||||||||
1886 | - | |||||||||||||||||||
1887 | /*! | - | ||||||||||||||||||
1888 | Parses \a url and sets this object to that value. QUrl will automatically | - | ||||||||||||||||||
1889 | percent encode all characters that are not allowed in a URL and decode the | - | ||||||||||||||||||
1890 | percent-encoded sequences that represent an unreserved character (letters, | - | ||||||||||||||||||
1891 | digits, hyphens, undercores, dots and tildes). All other characters are | - | ||||||||||||||||||
1892 | left in their original forms. | - | ||||||||||||||||||
1893 | - | |||||||||||||||||||
1894 | Parses the \a url using the parser mode \a parsingMode. In TolerantMode | - | ||||||||||||||||||
1895 | (the default), QUrl will correct certain mistakes, notably the presence of | - | ||||||||||||||||||
1896 | a percent character ('%') not followed by two hexadecimal digits, and it | - | ||||||||||||||||||
1897 | will accept any character in any position. In StrictMode, encoding mistakes | - | ||||||||||||||||||
1898 | will not be tolerated and QUrl will also check that certain forbidden | - | ||||||||||||||||||
1899 | characters are not present in unencoded form. If an error is detected in | - | ||||||||||||||||||
1900 | StrictMode, isValid() will return false. The parsing mode DecodedMode is | - | ||||||||||||||||||
1901 | not permitted in this context and will produce a run-time warning. | - | ||||||||||||||||||
1902 | - | |||||||||||||||||||
1903 | \sa url(), toString() | - | ||||||||||||||||||
1904 | */ | - | ||||||||||||||||||
1905 | void QUrl::setUrl(const QString &url, ParsingMode parsingMode) | - | ||||||||||||||||||
1906 | { | - | ||||||||||||||||||
1907 | if (parsingMode == DecodedMode) { | - | ||||||||||||||||||
1908 | qWarning("QUrl: QUrl::DecodedMode is not permitted when parsing a full URL"); | - | ||||||||||||||||||
1909 | } else { | - | ||||||||||||||||||
1910 | detach(); | - | ||||||||||||||||||
1911 | d->parse(url, parsingMode); | - | ||||||||||||||||||
1912 | } | - | ||||||||||||||||||
1913 | } | - | ||||||||||||||||||
1914 | - | |||||||||||||||||||
1915 | /*! | - | ||||||||||||||||||
1916 | \fn void QUrl::setEncodedUrl(const QByteArray &encodedUrl, ParsingMode parsingMode) | - | ||||||||||||||||||
1917 | \deprecated | - | ||||||||||||||||||
1918 | Constructs a URL by parsing the contents of \a encodedUrl. | - | ||||||||||||||||||
1919 | - | |||||||||||||||||||
1920 | \a encodedUrl is assumed to be a URL string in percent encoded | - | ||||||||||||||||||
1921 | form, containing only ASCII characters. | - | ||||||||||||||||||
1922 | - | |||||||||||||||||||
1923 | The parsing mode \a parsingMode is used for parsing \a encodedUrl. | - | ||||||||||||||||||
1924 | - | |||||||||||||||||||
1925 | \obsolete Use setUrl(QString::fromUtf8(encodedUrl), parsingMode) | - | ||||||||||||||||||
1926 | - | |||||||||||||||||||
1927 | \sa setUrl() | - | ||||||||||||||||||
1928 | */ | - | ||||||||||||||||||
1929 | - | |||||||||||||||||||
1930 | /*! | - | ||||||||||||||||||
1931 | Sets the scheme of the URL to \a scheme. As a scheme can only | - | ||||||||||||||||||
1932 | contain ASCII characters, no conversion or decoding is done on the | - | ||||||||||||||||||
1933 | input. It must also start with an ASCII letter. | - | ||||||||||||||||||
1934 | - | |||||||||||||||||||
1935 | The scheme describes the type (or protocol) of the URL. It's | - | ||||||||||||||||||
1936 | represented by one or more ASCII characters at the start the URL. | - | ||||||||||||||||||
1937 | - | |||||||||||||||||||
1938 | A scheme is strictly \l {http://www.ietf.org/rfc/rfc3986.txt} {RFC 3986}-compliant: | - | ||||||||||||||||||
1939 | \tt {scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )} | - | ||||||||||||||||||
1940 | - | |||||||||||||||||||
1941 | The following example shows a URL where the scheme is "ftp": | - | ||||||||||||||||||
1942 | - | |||||||||||||||||||
1943 | \image qurl-authority2.png | - | ||||||||||||||||||
1944 | - | |||||||||||||||||||
1945 | To set the scheme, the following call is used: | - | ||||||||||||||||||
1946 | \code | - | ||||||||||||||||||
1947 | QUrl url; | - | ||||||||||||||||||
1948 | url.setScheme("ftp"); | - | ||||||||||||||||||
1949 | \endcode | - | ||||||||||||||||||
1950 | - | |||||||||||||||||||
1951 | The scheme can also be empty, in which case the URL is interpreted | - | ||||||||||||||||||
1952 | as relative. | - | ||||||||||||||||||
1953 | - | |||||||||||||||||||
1954 | \sa scheme(), isRelative() | - | ||||||||||||||||||
1955 | */ | - | ||||||||||||||||||
1956 | void QUrl::setScheme(const QString &scheme) | - | ||||||||||||||||||
1957 | { | - | ||||||||||||||||||
1958 | detach(); | - | ||||||||||||||||||
1959 | d->clearError(); | - | ||||||||||||||||||
1960 | if (scheme.isEmpty()) { | - | ||||||||||||||||||
1961 | // schemes are not allowed to be empty | - | ||||||||||||||||||
1962 | d->sectionIsPresent &= ~QUrlPrivate::Scheme; | - | ||||||||||||||||||
1963 | d->flags &= ~QUrlPrivate::IsLocalFile; | - | ||||||||||||||||||
1964 | d->scheme.clear(); | - | ||||||||||||||||||
1965 | } else { | - | ||||||||||||||||||
1966 | d->setScheme(scheme, scheme.length(), /* do set error */ true); | - | ||||||||||||||||||
1967 | } | - | ||||||||||||||||||
1968 | } | - | ||||||||||||||||||
1969 | - | |||||||||||||||||||
1970 | /*! | - | ||||||||||||||||||
1971 | Returns the scheme of the URL. If an empty string is returned, | - | ||||||||||||||||||
1972 | this means the scheme is undefined and the URL is then relative. | - | ||||||||||||||||||
1973 | - | |||||||||||||||||||
1974 | The scheme can only contain US-ASCII letters or digits, which means it | - | ||||||||||||||||||
1975 | cannot contain any character that would otherwise require encoding. | - | ||||||||||||||||||
1976 | Additionally, schemes are always returned in lowercase form. | - | ||||||||||||||||||
1977 | - | |||||||||||||||||||
1978 | \sa setScheme(), isRelative() | - | ||||||||||||||||||
1979 | */ | - | ||||||||||||||||||
1980 | QString QUrl::scheme() const | - | ||||||||||||||||||
1981 | { | - | ||||||||||||||||||
1982 | if (!d) return QString(); | - | ||||||||||||||||||
1983 | - | |||||||||||||||||||
1984 | return d->scheme; | - | ||||||||||||||||||
1985 | } | - | ||||||||||||||||||
1986 | - | |||||||||||||||||||
1987 | /*! | - | ||||||||||||||||||
1988 | Sets the authority of the URL to \a authority. | - | ||||||||||||||||||
1989 | - | |||||||||||||||||||
1990 | The authority of a URL is the combination of user info, a host | - | ||||||||||||||||||
1991 | name and a port. All of these elements are optional; an empty | - | ||||||||||||||||||
1992 | authority is therefore valid. | - | ||||||||||||||||||
1993 | - | |||||||||||||||||||
1994 | The user info and host are separated by a '@', and the host and | - | ||||||||||||||||||
1995 | port are separated by a ':'. If the user info is empty, the '@' | - | ||||||||||||||||||
1996 | must be omitted; although a stray ':' is permitted if the port is | - | ||||||||||||||||||
1997 | empty. | - | ||||||||||||||||||
1998 | - | |||||||||||||||||||
1999 | The following example shows a valid authority string: | - | ||||||||||||||||||
2000 | - | |||||||||||||||||||
2001 | \image qurl-authority.png | - | ||||||||||||||||||
2002 | - | |||||||||||||||||||
2003 | The \a authority data is interpreted according to \a mode: in StrictMode, | - | ||||||||||||||||||
2004 | any '%' characters must be followed by exactly two hexadecimal characters | - | ||||||||||||||||||
2005 | and some characters (including space) are not allowed in undecoded form. In | - | ||||||||||||||||||
2006 | TolerantMode (the default), all characters are accepted in undecoded form | - | ||||||||||||||||||
2007 | and the tolerant parser will correct stray '%' not followed by two hex | - | ||||||||||||||||||
2008 | characters. | - | ||||||||||||||||||
2009 | - | |||||||||||||||||||
2010 | This function does not allow \a mode to be QUrl::DecodedMode. To set fully | - | ||||||||||||||||||
2011 | decoded data, call setUserName(), setPassword(), setHost() and setPort() | - | ||||||||||||||||||
2012 | individually. | - | ||||||||||||||||||
2013 | - | |||||||||||||||||||
2014 | \sa setUserInfo(), setHost(), setPort() | - | ||||||||||||||||||
2015 | */ | - | ||||||||||||||||||
2016 | void QUrl::setAuthority(const QString &authority, ParsingMode mode) | - | ||||||||||||||||||
2017 | { | - | ||||||||||||||||||
2018 | detach(); | - | ||||||||||||||||||
2019 | d->clearError(); | - | ||||||||||||||||||
2020 | - | |||||||||||||||||||
2021 | if (mode == DecodedMode) { | - | ||||||||||||||||||
2022 | qWarning("QUrl::setAuthority(): QUrl::DecodedMode is not permitted in this function"); | - | ||||||||||||||||||
2023 | return; | - | ||||||||||||||||||
2024 | } | - | ||||||||||||||||||
2025 | - | |||||||||||||||||||
2026 | d->setAuthority(authority, 0, authority.length(), mode); | - | ||||||||||||||||||
2027 | if (authority.isNull()) { | - | ||||||||||||||||||
2028 | // QUrlPrivate::setAuthority cleared almost everything | - | ||||||||||||||||||
2029 | // but it leaves the Host bit set | - | ||||||||||||||||||
2030 | d->sectionIsPresent &= ~QUrlPrivate::Authority; | - | ||||||||||||||||||
2031 | } | - | ||||||||||||||||||
2032 | } | - | ||||||||||||||||||
2033 | - | |||||||||||||||||||
2034 | /*! | - | ||||||||||||||||||
2035 | Returns the authority of the URL if it is defined; otherwise | - | ||||||||||||||||||
2036 | an empty string is returned. | - | ||||||||||||||||||
2037 | - | |||||||||||||||||||
2038 | This function returns an unambiguous value, which may contain that | - | ||||||||||||||||||
2039 | characters still percent-encoded, plus some control sequences not | - | ||||||||||||||||||
2040 | representable in decoded form in QString. | - | ||||||||||||||||||
2041 | - | |||||||||||||||||||
2042 | The \a options argument controls how to format the user info component. The | - | ||||||||||||||||||
2043 | value of QUrl::FullyDecoded is not permitted in this function. If you need | - | ||||||||||||||||||
2044 | to obtain fully decoded data, call userName(), password(), host() and | - | ||||||||||||||||||
2045 | port() individually. | - | ||||||||||||||||||
2046 | - | |||||||||||||||||||
2047 | \sa setAuthority(), userInfo(), userName(), password(), host(), port() | - | ||||||||||||||||||
2048 | */ | - | ||||||||||||||||||
2049 | QString QUrl::authority(ComponentFormattingOptions options) const | - | ||||||||||||||||||
2050 | { | - | ||||||||||||||||||
2051 | QString result; | - | ||||||||||||||||||
2052 | if (!d)
| 1-177 | ||||||||||||||||||
2053 | return QString();result; executed 1 time by 1 test: return result; Executed by:
| 1 | ||||||||||||||||||
2054 | - | |||||||||||||||||||
2055 | if (options == QUrl::FullyDecoded) {
| 0-177 | ||||||||||||||||||
2056 | qWarning("QUrl::authority(): QUrl::FullyDecoded is not permitted in this function"); | - | ||||||||||||||||||
2057 | return QString(); never executed: return result; | 0 | ||||||||||||||||||
} never executed: return result; | ||||||||||||||||||||
QString never executed: result;return result; never executed: return result; | ||||||||||||||||||||
2058 | } | - | ||||||||||||||||||
2059 | - | |||||||||||||||||||
2060 | d->appendAuthority(result, options, QUrlPrivate::Authority); | - | ||||||||||||||||||
2061 | return result; executed 177 times by 3 tests: return result; Executed by:
| 177 | ||||||||||||||||||
2062 | } | - | ||||||||||||||||||
2063 | - | |||||||||||||||||||
2064 | /*! | - | ||||||||||||||||||
2065 | Sets the user info of the URL to \a userInfo. The user info is an | - | ||||||||||||||||||
2066 | optional part of the authority of the URL, as described in | - | ||||||||||||||||||
2067 | setAuthority(). | - | ||||||||||||||||||
2068 | - | |||||||||||||||||||
2069 | The user info consists of a user name and optionally a password, | - | ||||||||||||||||||
2070 | separated by a ':'. If the password is empty, the colon must be | - | ||||||||||||||||||
2071 | omitted. The following example shows a valid user info string: | - | ||||||||||||||||||
2072 | - | |||||||||||||||||||
2073 | \image qurl-authority3.png | - | ||||||||||||||||||
2074 | - | |||||||||||||||||||
2075 | The \a userInfo data is interpreted according to \a mode: in StrictMode, | - | ||||||||||||||||||
2076 | any '%' characters must be followed by exactly two hexadecimal characters | - | ||||||||||||||||||
2077 | and some characters (including space) are not allowed in undecoded form. In | - | ||||||||||||||||||
2078 | TolerantMode (the default), all characters are accepted in undecoded form | - | ||||||||||||||||||
2079 | and the tolerant parser will correct stray '%' not followed by two hex | - | ||||||||||||||||||
2080 | characters. | - | ||||||||||||||||||
2081 | - | |||||||||||||||||||
2082 | This function does not allow \a mode to be QUrl::DecodedMode. To set fully | - | ||||||||||||||||||
2083 | decoded data, call setUserName() and setPassword() individually. | - | ||||||||||||||||||
2084 | - | |||||||||||||||||||
2085 | \sa userInfo(), setUserName(), setPassword(), setAuthority() | - | ||||||||||||||||||
2086 | */ | - | ||||||||||||||||||
2087 | void QUrl::setUserInfo(const QString &userInfo, ParsingMode mode) | - | ||||||||||||||||||
2088 | { | - | ||||||||||||||||||
2089 | detach(); | - | ||||||||||||||||||
2090 | d->clearError(); | - | ||||||||||||||||||
2091 | QString trimmed = userInfo.trimmed(); | - | ||||||||||||||||||
2092 | if (mode == DecodedMode) { | - | ||||||||||||||||||
2093 | qWarning("QUrl::setUserInfo(): QUrl::DecodedMode is not permitted in this function"); | - | ||||||||||||||||||
2094 | return; | - | ||||||||||||||||||
2095 | } | - | ||||||||||||||||||
2096 | - | |||||||||||||||||||
2097 | d->setUserInfo(trimmed, 0, trimmed.length()); | - | ||||||||||||||||||
2098 | if (userInfo.isNull()) { | - | ||||||||||||||||||
2099 | // QUrlPrivate::setUserInfo cleared almost everything | - | ||||||||||||||||||
2100 | // but it leaves the UserName bit set | - | ||||||||||||||||||
2101 | d->sectionIsPresent &= ~QUrlPrivate::UserInfo; | - | ||||||||||||||||||
2102 | } else if (mode == StrictMode && !d->validateComponent(QUrlPrivate::UserInfo, userInfo)) { | - | ||||||||||||||||||
2103 | d->sectionIsPresent &= ~QUrlPrivate::UserInfo; | - | ||||||||||||||||||
2104 | d->userName.clear(); | - | ||||||||||||||||||
2105 | d->password.clear(); | - | ||||||||||||||||||
2106 | } | - | ||||||||||||||||||
2107 | } | - | ||||||||||||||||||
2108 | - | |||||||||||||||||||
2109 | /*! | - | ||||||||||||||||||
2110 | Returns the user info of the URL, or an empty string if the user | - | ||||||||||||||||||
2111 | info is undefined. | - | ||||||||||||||||||
2112 | - | |||||||||||||||||||
2113 | This function returns an unambiguous value, which may contain that | - | ||||||||||||||||||
2114 | characters still percent-encoded, plus some control sequences not | - | ||||||||||||||||||
2115 | representable in decoded form in QString. | - | ||||||||||||||||||
2116 | - | |||||||||||||||||||
2117 | The \a options argument controls how to format the user info component. The | - | ||||||||||||||||||
2118 | value of QUrl::FullyDecoded is not permitted in this function. If you need | - | ||||||||||||||||||
2119 | to obtain fully decoded data, call userName() and password() individually. | - | ||||||||||||||||||
2120 | - | |||||||||||||||||||
2121 | \sa setUserInfo(), userName(), password(), authority() | - | ||||||||||||||||||
2122 | */ | - | ||||||||||||||||||
2123 | QString QUrl::userInfo(ComponentFormattingOptions options) const | - | ||||||||||||||||||
2124 | { | - | ||||||||||||||||||
2125 | QString result; | - | ||||||||||||||||||
2126 | if (!d)
| 1-2348 | ||||||||||||||||||
2127 | return QString();result; executed 1 time by 1 test: return result; Executed by:
| 1 | ||||||||||||||||||
2128 | - | |||||||||||||||||||
2129 | if (options == QUrl::FullyDecoded) {
| 0-2348 | ||||||||||||||||||
2130 | qWarning("QUrl::userInfo(): QUrl::FullyDecoded is not permitted in this function"); | - | ||||||||||||||||||
2131 | return QString(); never executed: return result; | 0 | ||||||||||||||||||
} never executed: return result; | ||||||||||||||||||||
QString never executed: result;return result; never executed: return result; | ||||||||||||||||||||
2132 | } | - | ||||||||||||||||||
2133 | - | |||||||||||||||||||
2134 | d->appendUserInfo(result, options, QUrlPrivate::UserInfo); | - | ||||||||||||||||||
2135 | return result; executed 2348 times by 9 tests: return result; Executed by:
| 2348 | ||||||||||||||||||
2136 | } | - | ||||||||||||||||||
2137 | - | |||||||||||||||||||
2138 | /*! | - | ||||||||||||||||||
2139 | Sets the URL's user name to \a userName. The \a userName is part | - | ||||||||||||||||||
2140 | of the user info element in the authority of the URL, as described | - | ||||||||||||||||||
2141 | in setUserInfo(). | - | ||||||||||||||||||
2142 | - | |||||||||||||||||||
2143 | The \a userName data is interpreted according to \a mode: in StrictMode, | - | ||||||||||||||||||
2144 | any '%' characters must be followed by exactly two hexadecimal characters | - | ||||||||||||||||||
2145 | and some characters (including space) are not allowed in undecoded form. In | - | ||||||||||||||||||
2146 | TolerantMode (the default), all characters are accepted in undecoded form | - | ||||||||||||||||||
2147 | and the tolerant parser will correct stray '%' not followed by two hex | - | ||||||||||||||||||
2148 | characters. In DecodedMode, '%' stand for themselves and encoded characters | - | ||||||||||||||||||
2149 | are not possible. | - | ||||||||||||||||||
2150 | - | |||||||||||||||||||
2151 | QUrl::DecodedMode should be used when setting the user name from a data | - | ||||||||||||||||||
2152 | source which is not a URL, such as a password dialog shown to the user or | - | ||||||||||||||||||
2153 | with a user name obtained by calling userName() with the QUrl::FullyDecoded | - | ||||||||||||||||||
2154 | formatting option. | - | ||||||||||||||||||
2155 | - | |||||||||||||||||||
2156 | \sa userName(), setUserInfo() | - | ||||||||||||||||||
2157 | */ | - | ||||||||||||||||||
2158 | void QUrl::setUserName(const QString &userName, ParsingMode mode) | - | ||||||||||||||||||
2159 | { | - | ||||||||||||||||||
2160 | detach(); | - | ||||||||||||||||||
2161 | d->clearError(); | - | ||||||||||||||||||
2162 | - | |||||||||||||||||||
2163 | QString data = userName; | - | ||||||||||||||||||
2164 | if (mode == DecodedMode) { | - | ||||||||||||||||||
2165 | parseDecodedComponent(data); | - | ||||||||||||||||||
2166 | mode = TolerantMode; | - | ||||||||||||||||||
2167 | } | - | ||||||||||||||||||
2168 | - | |||||||||||||||||||
2169 | d->setUserName(data, 0, data.length()); | - | ||||||||||||||||||
2170 | if (userName.isNull()) | - | ||||||||||||||||||
2171 | d->sectionIsPresent &= ~QUrlPrivate::UserName; | - | ||||||||||||||||||
2172 | else if (mode == StrictMode && !d->validateComponent(QUrlPrivate::UserName, userName)) | - | ||||||||||||||||||
2173 | d->userName.clear(); | - | ||||||||||||||||||
2174 | } | - | ||||||||||||||||||
2175 | - | |||||||||||||||||||
2176 | /*! | - | ||||||||||||||||||
2177 | Returns the user name of the URL if it is defined; otherwise | - | ||||||||||||||||||
2178 | an empty string is returned. | - | ||||||||||||||||||
2179 | - | |||||||||||||||||||
2180 | The \a options argument controls how to format the user name component. All | - | ||||||||||||||||||
2181 | values produce an unambiguous result. With QUrl::FullyDecoded, all | - | ||||||||||||||||||
2182 | percent-encoded sequences are decoded; otherwise, the returned value may | - | ||||||||||||||||||
2183 | contain some percent-encoded sequences for some control sequences not | - | ||||||||||||||||||
2184 | representable in decoded form in QString. | - | ||||||||||||||||||
2185 | - | |||||||||||||||||||
2186 | Note that QUrl::FullyDecoded may cause data loss if those non-representable | - | ||||||||||||||||||
2187 | sequences are present. It is recommended to use that value when the result | - | ||||||||||||||||||
2188 | will be used in a non-URL context, such as setting in QAuthenticator or | - | ||||||||||||||||||
2189 | negotiating a login. | - | ||||||||||||||||||
2190 | - | |||||||||||||||||||
2191 | \sa setUserName(), userInfo() | - | ||||||||||||||||||
2192 | */ | - | ||||||||||||||||||
2193 | QString QUrl::userName(ComponentFormattingOptions options) const | - | ||||||||||||||||||
2194 | { | - | ||||||||||||||||||
2195 | if (!d) return QString();QString result; | - | ||||||||||||||||||
2196 | if (d)
| 2-783 | ||||||||||||||||||
2197 | d->appendUserName(result, options); executed 783 times by 3 tests: d->appendUserName(result, options); Executed by:
| 783 | ||||||||||||||||||
2198 | return result; executed 785 times by 3 tests: return result; Executed by:
| 785 | ||||||||||||||||||
2199 | } | - | ||||||||||||||||||
2200 | - | |||||||||||||||||||
2201 | /*! | - | ||||||||||||||||||
2202 | \fn void QUrl::setEncodedUserName(const QByteArray &userName) | - | ||||||||||||||||||
2203 | \deprecated | - | ||||||||||||||||||
2204 | \since 4.4 | - | ||||||||||||||||||
2205 | - | |||||||||||||||||||
2206 | Sets the URL's user name to the percent-encoded \a userName. The \a | - | ||||||||||||||||||
2207 | userName is part of the user info element in the authority of the | - | ||||||||||||||||||
2208 | URL, as described in setUserInfo(). | - | ||||||||||||||||||
2209 | - | |||||||||||||||||||
2210 | \obsolete Use setUserName(QString::fromUtf8(userName)) | - | ||||||||||||||||||
2211 | - | |||||||||||||||||||
2212 | \sa setUserName(), encodedUserName(), setUserInfo() | - | ||||||||||||||||||
2213 | */ | - | ||||||||||||||||||
2214 | - | |||||||||||||||||||
2215 | /*! | - | ||||||||||||||||||
2216 | \fn QByteArray QUrl::encodedUserName() const | - | ||||||||||||||||||
2217 | \deprecated | - | ||||||||||||||||||
2218 | \since 4.4 | - | ||||||||||||||||||
2219 | - | |||||||||||||||||||
2220 | Returns the user name of the URL if it is defined; otherwise | - | ||||||||||||||||||
2221 | an empty string is returned. The returned value will have its | - | ||||||||||||||||||
2222 | non-ASCII and other control characters percent-encoded, as in | - | ||||||||||||||||||
2223 | toEncoded(). | - | ||||||||||||||||||
2224 | - | |||||||||||||||||||
2225 | \obsolete Use userName(QUrl::FullyEncoded).toLatin1() | - | ||||||||||||||||||
2226 | - | |||||||||||||||||||
2227 | \sa setEncodedUserName() | - | ||||||||||||||||||
2228 | */ | - | ||||||||||||||||||
2229 | - | |||||||||||||||||||
2230 | /*! | - | ||||||||||||||||||
2231 | Sets the URL's password to \a password. The \a password is part of | - | ||||||||||||||||||
2232 | the user info element in the authority of the URL, as described in | - | ||||||||||||||||||
2233 | setUserInfo(). | - | ||||||||||||||||||
2234 | - | |||||||||||||||||||
2235 | The \a password data is interpreted according to \a mode: in StrictMode, | - | ||||||||||||||||||
2236 | any '%' characters must be followed by exactly two hexadecimal characters | - | ||||||||||||||||||
2237 | and some characters (including space) are not allowed in undecoded form. In | - | ||||||||||||||||||
2238 | TolerantMode, all characters are accepted in undecoded form and the | - | ||||||||||||||||||
2239 | tolerant parser will correct stray '%' not followed by two hex characters. | - | ||||||||||||||||||
2240 | In DecodedMode, '%' stand for themselves and encoded characters are not | - | ||||||||||||||||||
2241 | possible. | - | ||||||||||||||||||
2242 | - | |||||||||||||||||||
2243 | QUrl::DecodedMode should be used when setting the password from a data | - | ||||||||||||||||||
2244 | source which is not a URL, such as a password dialog shown to the user or | - | ||||||||||||||||||
2245 | with a password obtained by calling password() with the QUrl::FullyDecoded | - | ||||||||||||||||||
2246 | formatting option. | - | ||||||||||||||||||
2247 | - | |||||||||||||||||||
2248 | \sa password(), setUserInfo() | - | ||||||||||||||||||
2249 | */ | - | ||||||||||||||||||
2250 | void QUrl::setPassword(const QString &password, ParsingMode mode) | - | ||||||||||||||||||
2251 | { | - | ||||||||||||||||||
2252 | detach(); | - | ||||||||||||||||||
2253 | d->clearError(); | - | ||||||||||||||||||
2254 | - | |||||||||||||||||||
2255 | QString data = password; | - | ||||||||||||||||||
2256 | if (mode == DecodedMode) { | - | ||||||||||||||||||
2257 | parseDecodedComponent(data); | - | ||||||||||||||||||
2258 | mode = TolerantMode; | - | ||||||||||||||||||
2259 | } | - | ||||||||||||||||||
2260 | - | |||||||||||||||||||
2261 | d->setPassword(data, 0, data.length()); | - | ||||||||||||||||||
2262 | if (password.isNull()) | - | ||||||||||||||||||
2263 | d->sectionIsPresent &= ~QUrlPrivate::Password; | - | ||||||||||||||||||
2264 | else if (mode == StrictMode && !d->validateComponent(QUrlPrivate::Password, password)) | - | ||||||||||||||||||
2265 | d->password.clear(); | - | ||||||||||||||||||
2266 | } | - | ||||||||||||||||||
2267 | - | |||||||||||||||||||
2268 | /*! | - | ||||||||||||||||||
2269 | Returns the password of the URL if it is defined; otherwise | - | ||||||||||||||||||
2270 | an empty string is returned. | - | ||||||||||||||||||
2271 | - | |||||||||||||||||||
2272 | The \a options argument controls how to format the user name component. All | - | ||||||||||||||||||
2273 | values produce an unambiguous result. With QUrl::FullyDecoded, all | - | ||||||||||||||||||
2274 | percent-encoded sequences are decoded; otherwise, the returned value may | - | ||||||||||||||||||
2275 | contain some percent-encoded sequences for some control sequences not | - | ||||||||||||||||||
2276 | representable in decoded form in QString. | - | ||||||||||||||||||
2277 | - | |||||||||||||||||||
2278 | Note that QUrl::FullyDecoded may cause data loss if those non-representable | - | ||||||||||||||||||
2279 | sequences are present. It is recommended to use that value when the result | - | ||||||||||||||||||
2280 | will be used in a non-URL context, such as setting in QAuthenticator or | - | ||||||||||||||||||
2281 | negotiating a login. | - | ||||||||||||||||||
2282 | - | |||||||||||||||||||
2283 | \sa setPassword() | - | ||||||||||||||||||
2284 | */ | - | ||||||||||||||||||
2285 | QString QUrl::password(ComponentFormattingOptions options) const | - | ||||||||||||||||||
2286 | { | - | ||||||||||||||||||
2287 | if (!d) return QString();QString result; | - | ||||||||||||||||||
2288 | if (d)
| 2-577 | ||||||||||||||||||
2289 | d->appendPassword(result, options); executed 577 times by 6 tests: d->appendPassword(result, options); Executed by:
| 577 | ||||||||||||||||||
2290 | return result; executed 579 times by 6 tests: return result; Executed by:
| 579 | ||||||||||||||||||
2291 | } | - | ||||||||||||||||||
2292 | - | |||||||||||||||||||
2293 | /*! | - | ||||||||||||||||||
2294 | \fn void QUrl::setEncodedPassword(const QByteArray &password) | - | ||||||||||||||||||
2295 | \deprecated | - | ||||||||||||||||||
2296 | \since 4.4 | - | ||||||||||||||||||
2297 | - | |||||||||||||||||||
2298 | Sets the URL's password to the percent-encoded \a password. The \a | - | ||||||||||||||||||
2299 | password is part of the user info element in the authority of the | - | ||||||||||||||||||
2300 | URL, as described in setUserInfo(). | - | ||||||||||||||||||
2301 | - | |||||||||||||||||||
2302 | \obsolete Use setPassword(QString::fromUtf8(password)); | - | ||||||||||||||||||
2303 | - | |||||||||||||||||||
2304 | \sa setPassword(), encodedPassword(), setUserInfo() | - | ||||||||||||||||||
2305 | */ | - | ||||||||||||||||||
2306 | - | |||||||||||||||||||
2307 | /*! | - | ||||||||||||||||||
2308 | \fn QByteArray QUrl::encodedPassword() const | - | ||||||||||||||||||
2309 | \deprecated | - | ||||||||||||||||||
2310 | \since 4.4 | - | ||||||||||||||||||
2311 | - | |||||||||||||||||||
2312 | Returns the password of the URL if it is defined; otherwise an | - | ||||||||||||||||||
2313 | empty string is returned. The returned value will have its | - | ||||||||||||||||||
2314 | non-ASCII and other control characters percent-encoded, as in | - | ||||||||||||||||||
2315 | toEncoded(). | - | ||||||||||||||||||
2316 | - | |||||||||||||||||||
2317 | \obsolete Use password(QUrl::FullyEncoded).toLatin1() | - | ||||||||||||||||||
2318 | - | |||||||||||||||||||
2319 | \sa setEncodedPassword(), toEncoded() | - | ||||||||||||||||||
2320 | */ | - | ||||||||||||||||||
2321 | - | |||||||||||||||||||
2322 | /*! | - | ||||||||||||||||||
2323 | Sets the host of the URL to \a host. The host is part of the | - | ||||||||||||||||||
2324 | authority. | - | ||||||||||||||||||
2325 | - | |||||||||||||||||||
2326 | The \a host data is interpreted according to \a mode: in StrictMode, | - | ||||||||||||||||||
2327 | any '%' characters must be followed by exactly two hexadecimal characters | - | ||||||||||||||||||
2328 | and some characters (including space) are not allowed in undecoded form. In | - | ||||||||||||||||||
2329 | TolerantMode, all characters are accepted in undecoded form and the | - | ||||||||||||||||||
2330 | tolerant parser will correct stray '%' not followed by two hex characters. | - | ||||||||||||||||||
2331 | In DecodedMode, '%' stand for themselves and encoded characters are not | - | ||||||||||||||||||
2332 | possible. | - | ||||||||||||||||||
2333 | - | |||||||||||||||||||
2334 | Note that, in all cases, the result of the parsing must be a valid hostname | - | ||||||||||||||||||
2335 | according to STD 3 rules, as modified by the Internationalized Resource | - | ||||||||||||||||||
2336 | Identifiers specification (RFC 3987). Invalid hostnames are not permitted | - | ||||||||||||||||||
2337 | and will cause isValid() to become false. | - | ||||||||||||||||||
2338 | - | |||||||||||||||||||
2339 | \sa host(), setAuthority() | - | ||||||||||||||||||
2340 | */ | - | ||||||||||||||||||
2341 | void QUrl::setHost(const QString &host, ParsingMode mode) | - | ||||||||||||||||||
2342 | { | - | ||||||||||||||||||
2343 | detach(); | - | ||||||||||||||||||
2344 | d->clearError(); | - | ||||||||||||||||||
2345 | - | |||||||||||||||||||
2346 | QString data = host; | - | ||||||||||||||||||
2347 | if (mode == DecodedMode) { | - | ||||||||||||||||||
2348 | parseDecodedComponent(data); | - | ||||||||||||||||||
2349 | mode = TolerantMode; | - | ||||||||||||||||||
2350 | } | - | ||||||||||||||||||
2351 | - | |||||||||||||||||||
2352 | if (d->setHost(data, 0, data.length(), mode)) { | - | ||||||||||||||||||
2353 | if (host.isNull()) | - | ||||||||||||||||||
2354 | d->sectionIsPresent &= ~QUrlPrivate::Host; | - | ||||||||||||||||||
2355 | } else if (!data.startsWith(QLatin1Char('['))) { | - | ||||||||||||||||||
2356 | // setHost failed, it might be IPv6 or IPvFuture in need of bracketing | - | ||||||||||||||||||
2357 | Q_ASSERT(d->error); | - | ||||||||||||||||||
2358 | - | |||||||||||||||||||
2359 | data.prepend(QLatin1Char('[')); | - | ||||||||||||||||||
2360 | data.append(QLatin1Char(']')); | - | ||||||||||||||||||
2361 | if (!d->setHost(data, 0, data.length(), mode)) { | - | ||||||||||||||||||
2362 | // failed again | - | ||||||||||||||||||
2363 | if (data.contains(QLatin1Char(':'))) { | - | ||||||||||||||||||
2364 | // source data contains ':', so it's an IPv6 error | - | ||||||||||||||||||
2365 | d->error->code = QUrlPrivate::InvalidIPv6AddressError; | - | ||||||||||||||||||
2366 | } | - | ||||||||||||||||||
2367 | } else { | - | ||||||||||||||||||
2368 | // succeeded | - | ||||||||||||||||||
2369 | d->clearError(); | - | ||||||||||||||||||
2370 | } | - | ||||||||||||||||||
2371 | } | - | ||||||||||||||||||
2372 | } | - | ||||||||||||||||||
2373 | - | |||||||||||||||||||
2374 | /*! | - | ||||||||||||||||||
2375 | Returns the host of the URL if it is defined; otherwise | - | ||||||||||||||||||
2376 | an empty string is returned. | - | ||||||||||||||||||
2377 | - | |||||||||||||||||||
2378 | The \a options argument controls how the hostname will be formatted. The | - | ||||||||||||||||||
2379 | QUrl::EncodeUnicode option will cause this function to return the hostname | - | ||||||||||||||||||
2380 | in the ASCII-Compatible Encoding (ACE) form, which is suitable for use in | - | ||||||||||||||||||
2381 | channels that are not 8-bit clean or that require the legacy hostname (such | - | ||||||||||||||||||
2382 | as DNS requests or in HTTP request headers). If that flag is not present, | - | ||||||||||||||||||
2383 | this function returns the International Domain Name (IDN) in Unicode form, | - | ||||||||||||||||||
2384 | according to the list of permissible top-level domains (see | - | ||||||||||||||||||
2385 | idnWhitelist()). | - | ||||||||||||||||||
2386 | - | |||||||||||||||||||
2387 | All other flags are ignored. Host names cannot contain control or percent | - | ||||||||||||||||||
2388 | characters, so the returned value can be considered fully decoded. | - | ||||||||||||||||||
2389 | - | |||||||||||||||||||
2390 | \sa setHost(), idnWhitelist(), setIdnWhitelist(), authority() | - | ||||||||||||||||||
2391 | */ | - | ||||||||||||||||||
2392 | QString QUrl::host(ComponentFormattingOptions options) const | - | ||||||||||||||||||
2393 | { | - | ||||||||||||||||||
2394 | if (!d) return QString();QString result; | - | ||||||||||||||||||
2395 | if (d) {
| 2578-10012 | ||||||||||||||||||
2396 | d->appendHost(result, options); | - | ||||||||||||||||||
2397 | if (result.startsWith(QLatin1Char('[')))
| 53-9959 | ||||||||||||||||||
2398 | returnresult = result.mid(1, result.length() - 2); executed 53 times by 7 tests: result = result.mid(1, result.length() - 2); Executed by:
| 53 | ||||||||||||||||||
2399 | } executed 10012 times by 34 tests: end of block Executed by:
| 10012 | ||||||||||||||||||
2400 | return result; executed 12590 times by 34 tests: return result; Executed by:
| 12590 | ||||||||||||||||||
2401 | } | - | ||||||||||||||||||
2402 | - | |||||||||||||||||||
2403 | /*! | - | ||||||||||||||||||
2404 | \fn void QUrl::setEncodedHost(const QByteArray &host) | - | ||||||||||||||||||
2405 | \deprecated | - | ||||||||||||||||||
2406 | \since 4.4 | - | ||||||||||||||||||
2407 | - | |||||||||||||||||||
2408 | Sets the URL's host to the ACE- or percent-encoded \a host. The \a | - | ||||||||||||||||||
2409 | host is part of the user info element in the authority of the | - | ||||||||||||||||||
2410 | URL, as described in setAuthority(). | - | ||||||||||||||||||
2411 | - | |||||||||||||||||||
2412 | \obsolete Use setHost(QString::fromUtf8(host)). | - | ||||||||||||||||||
2413 | - | |||||||||||||||||||
2414 | \sa setHost(), encodedHost(), setAuthority(), fromAce() | - | ||||||||||||||||||
2415 | */ | - | ||||||||||||||||||
2416 | - | |||||||||||||||||||
2417 | /*! | - | ||||||||||||||||||
2418 | \fn QByteArray QUrl::encodedHost() const | - | ||||||||||||||||||
2419 | \deprecated | - | ||||||||||||||||||
2420 | \since 4.4 | - | ||||||||||||||||||
2421 | - | |||||||||||||||||||
2422 | Returns the host part of the URL if it is defined; otherwise | - | ||||||||||||||||||
2423 | an empty string is returned. | - | ||||||||||||||||||
2424 | - | |||||||||||||||||||
2425 | Note: encodedHost() does not return percent-encoded hostnames. Instead, | - | ||||||||||||||||||
2426 | the ACE-encoded (bare ASCII in Punycode encoding) form will be | - | ||||||||||||||||||
2427 | returned for any non-ASCII hostname. | - | ||||||||||||||||||
2428 | - | |||||||||||||||||||
2429 | This function is equivalent to calling QUrl::toAce() on the return | - | ||||||||||||||||||
2430 | value of host(). | - | ||||||||||||||||||
2431 | - | |||||||||||||||||||
2432 | \obsolete Use host(QUrl::FullyEncoded).toLatin1() or toAce(host()). | - | ||||||||||||||||||
2433 | - | |||||||||||||||||||
2434 | \sa setEncodedHost() | - | ||||||||||||||||||
2435 | */ | - | ||||||||||||||||||
2436 | - | |||||||||||||||||||
2437 | /*! | - | ||||||||||||||||||
2438 | Sets the port of the URL to \a port. The port is part of the | - | ||||||||||||||||||
2439 | authority of the URL, as described in setAuthority(). | - | ||||||||||||||||||
2440 | - | |||||||||||||||||||
2441 | \a port must be between 0 and 65535 inclusive. Setting the | - | ||||||||||||||||||
2442 | port to -1 indicates that the port is unspecified. | - | ||||||||||||||||||
2443 | */ | - | ||||||||||||||||||
2444 | void QUrl::setPort(int port) | - | ||||||||||||||||||
2445 | { | - | ||||||||||||||||||
2446 | detach(); | - | ||||||||||||||||||
2447 | d->clearError(); | - | ||||||||||||||||||
2448 | - | |||||||||||||||||||
2449 | if (port < -1 || port > 65535) { | - | ||||||||||||||||||
2450 | d->setError(QUrlPrivate::InvalidPortError, QString::number(port), 0); | - | ||||||||||||||||||
2451 | port = -1; | - | ||||||||||||||||||
2452 | } | - | ||||||||||||||||||
2453 | - | |||||||||||||||||||
2454 | d->port = port; | - | ||||||||||||||||||
2455 | } | - | ||||||||||||||||||
2456 | - | |||||||||||||||||||
2457 | /*! | - | ||||||||||||||||||
2458 | \since 4.1 | - | ||||||||||||||||||
2459 | - | |||||||||||||||||||
2460 | Returns the port of the URL, or \a defaultPort if the port is | - | ||||||||||||||||||
2461 | unspecified. | - | ||||||||||||||||||
2462 | - | |||||||||||||||||||
2463 | Example: | - | ||||||||||||||||||
2464 | - | |||||||||||||||||||
2465 | \snippet code/src_corelib_io_qurl.cpp 3 | - | ||||||||||||||||||
2466 | */ | - | ||||||||||||||||||
2467 | int QUrl::port(int defaultPort) const | - | ||||||||||||||||||
2468 | { | - | ||||||||||||||||||
2469 | if (!d) return defaultPort; | - | ||||||||||||||||||
2470 | return d->port == -1 ? defaultPort : d->port; | - | ||||||||||||||||||
2471 | } | - | ||||||||||||||||||
2472 | - | |||||||||||||||||||
2473 | /*! | - | ||||||||||||||||||
2474 | Sets the path of the URL to \a path. The path is the part of the | - | ||||||||||||||||||
2475 | URL that comes after the authority but before the query string. | - | ||||||||||||||||||
2476 | - | |||||||||||||||||||
2477 | \image qurl-ftppath.png | - | ||||||||||||||||||
2478 | - | |||||||||||||||||||
2479 | For non-hierarchical schemes, the path will be everything | - | ||||||||||||||||||
2480 | following the scheme declaration, as in the following example: | - | ||||||||||||||||||
2481 | - | |||||||||||||||||||
2482 | \image qurl-mailtopath.png | - | ||||||||||||||||||
2483 | - | |||||||||||||||||||
2484 | The \a path data is interpreted according to \a mode: in StrictMode, | - | ||||||||||||||||||
2485 | any '%' characters must be followed by exactly two hexadecimal characters | - | ||||||||||||||||||
2486 | and some characters (including space) are not allowed in undecoded form. In | - | ||||||||||||||||||
2487 | TolerantMode (the default), all characters are accepted in undecoded form and the | - | ||||||||||||||||||
2488 | tolerant parser will correct stray '%' not followed by two hex characters. | - | ||||||||||||||||||
2489 | In DecodedMode, '%' stand for themselves and encoded characters are not | - | ||||||||||||||||||
2490 | possible. | - | ||||||||||||||||||
2491 | - | |||||||||||||||||||
2492 | QUrl::DecodedMode should be used when setting the path from a data source | - | ||||||||||||||||||
2493 | which is not a URL, such as a dialog shown to the user or with a path | - | ||||||||||||||||||
2494 | obtained by calling path() with the QUrl::FullyDecoded formatting option. | - | ||||||||||||||||||
2495 | - | |||||||||||||||||||
2496 | \sa path() | - | ||||||||||||||||||
2497 | */ | - | ||||||||||||||||||
2498 | void QUrl::setPath(const QString &path, ParsingMode mode) | - | ||||||||||||||||||
2499 | { | - | ||||||||||||||||||
2500 | detach(); | - | ||||||||||||||||||
2501 | d->clearError(); | - | ||||||||||||||||||
2502 | - | |||||||||||||||||||
2503 | QString data = path; | - | ||||||||||||||||||
2504 | if (mode == DecodedMode) { | - | ||||||||||||||||||
2505 | parseDecodedComponent(data); | - | ||||||||||||||||||
2506 | mode = TolerantMode; | - | ||||||||||||||||||
2507 | } | - | ||||||||||||||||||
2508 | - | |||||||||||||||||||
2509 | int from = 0; | - | ||||||||||||||||||
2510 | while (from < data.length() - 2 && data.midRef(from, 2) == QLatin1String("//")) | - | ||||||||||||||||||
2511 | ++from; | - | ||||||||||||||||||
2512 | d->setPath(data, from, data.length()); | - | ||||||||||||||||||
2513 | - | |||||||||||||||||||
2514 | // optimized out, since there is no path delimiter | - | ||||||||||||||||||
2515 | // if (path.isNull()) | - | ||||||||||||||||||
2516 | // d->sectionIsPresent &= ~QUrlPrivate::Path; | - | ||||||||||||||||||
2517 | // else | - | ||||||||||||||||||
2518 | if (mode == StrictMode && !d->validateComponent(QUrlPrivate::Path, path)) | - | ||||||||||||||||||
2519 | d->path.clear(); | - | ||||||||||||||||||
2520 | } | - | ||||||||||||||||||
2521 | - | |||||||||||||||||||
2522 | /*! | - | ||||||||||||||||||
2523 | Returns the path of the URL. | - | ||||||||||||||||||
2524 | - | |||||||||||||||||||
2525 | The \a options argument controls how to format the path component. All | - | ||||||||||||||||||
2526 | values produce an unambiguous result. With QUrl::FullyDecoded, all | - | ||||||||||||||||||
2527 | percent-encoded sequences are decoded; otherwise, the returned value may | - | ||||||||||||||||||
2528 | contain some percent-encoded sequences for some control sequences not | - | ||||||||||||||||||
2529 | representable in decoded form in QString. | - | ||||||||||||||||||
2530 | - | |||||||||||||||||||
2531 | Note that QUrl::FullyDecoded may cause data loss if those non-representable | - | ||||||||||||||||||
2532 | sequences are present. It is recommended to use that value when the result | - | ||||||||||||||||||
2533 | will be used in a non-URL context, such as sending to an FTP server. | - | ||||||||||||||||||
2534 | - | |||||||||||||||||||
2535 | \sa setPath() | - | ||||||||||||||||||
2536 | */ | - | ||||||||||||||||||
2537 | QString QUrl::path(ComponentFormattingOptions options) const | - | ||||||||||||||||||
2538 | { | - | ||||||||||||||||||
2539 | if (!d) return QString();QString result; | - | ||||||||||||||||||
2540 | if (d)
| 7-4771 | ||||||||||||||||||
2541 | d->appendPath(result, options, QUrlPrivate::Path); executed 4771 times by 19 tests: d->appendPath(result, options, QUrlPrivate::Path); Executed by:
| 4771 | ||||||||||||||||||
2542 | return result; executed 4778 times by 20 tests: return result; Executed by:
| 4778 | ||||||||||||||||||
2543 | } | - | ||||||||||||||||||
2544 | - | |||||||||||||||||||
2545 | /*! | - | ||||||||||||||||||
2546 | \fn void QUrl::setEncodedPath(const QByteArray &path) | - | ||||||||||||||||||
2547 | \deprecated | - | ||||||||||||||||||
2548 | \since 4.4 | - | ||||||||||||||||||
2549 | - | |||||||||||||||||||
2550 | Sets the URL's path to the percent-encoded \a path. The path is | - | ||||||||||||||||||
2551 | the part of the URL that comes after the authority but before the | - | ||||||||||||||||||
2552 | query string. | - | ||||||||||||||||||
2553 | - | |||||||||||||||||||
2554 | \image qurl-ftppath.png | - | ||||||||||||||||||
2555 | - | |||||||||||||||||||
2556 | For non-hierarchical schemes, the path will be everything | - | ||||||||||||||||||
2557 | following the scheme declaration, as in the following example: | - | ||||||||||||||||||
2558 | - | |||||||||||||||||||
2559 | \image qurl-mailtopath.png | - | ||||||||||||||||||
2560 | - | |||||||||||||||||||
2561 | \obsolete Use setPath(QString::fromUtf8(path)). | - | ||||||||||||||||||
2562 | - | |||||||||||||||||||
2563 | \sa setPath(), encodedPath(), setUserInfo() | - | ||||||||||||||||||
2564 | */ | - | ||||||||||||||||||
2565 | - | |||||||||||||||||||
2566 | /*! | - | ||||||||||||||||||
2567 | \fn QByteArray QUrl::encodedPath() const | - | ||||||||||||||||||
2568 | \deprecated | - | ||||||||||||||||||
2569 | \since 4.4 | - | ||||||||||||||||||
2570 | - | |||||||||||||||||||
2571 | Returns the path of the URL if it is defined; otherwise an | - | ||||||||||||||||||
2572 | empty string is returned. The returned value will have its | - | ||||||||||||||||||
2573 | non-ASCII and other control characters percent-encoded, as in | - | ||||||||||||||||||
2574 | toEncoded(). | - | ||||||||||||||||||
2575 | - | |||||||||||||||||||
2576 | \obsolete Use path(QUrl::FullyEncoded).toLatin1(). | - | ||||||||||||||||||
2577 | - | |||||||||||||||||||
2578 | \sa setEncodedPath(), toEncoded() | - | ||||||||||||||||||
2579 | */ | - | ||||||||||||||||||
2580 | - | |||||||||||||||||||
2581 | /*! | - | ||||||||||||||||||
2582 | \since 5.2 | - | ||||||||||||||||||
2583 | - | |||||||||||||||||||
2584 | Returns the name of the file, excluding the directory path. | - | ||||||||||||||||||
2585 | - | |||||||||||||||||||
2586 | Note that, if this QUrl object is given a path ending in a slash, the name of the file is considered empty. | - | ||||||||||||||||||
2587 | - | |||||||||||||||||||
2588 | If the path doesn't contain any slash, it is fully returned as the fileName. | - | ||||||||||||||||||
2589 | - | |||||||||||||||||||
2590 | Example: | - | ||||||||||||||||||
2591 | - | |||||||||||||||||||
2592 | \snippet code/src_corelib_io_qurl.cpp 7 | - | ||||||||||||||||||
2593 | - | |||||||||||||||||||
2594 | The \a options argument controls how to format the file name component. All | - | ||||||||||||||||||
2595 | values produce an unambiguous result. With QUrl::FullyDecoded, all | - | ||||||||||||||||||
2596 | percent-encoded sequences are decoded; otherwise, the returned value may | - | ||||||||||||||||||
2597 | contain some percent-encoded sequences for some control sequences not | - | ||||||||||||||||||
2598 | representable in decoded form in QString. | - | ||||||||||||||||||
2599 | - | |||||||||||||||||||
2600 | \sa path() | - | ||||||||||||||||||
2601 | */ | - | ||||||||||||||||||
2602 | QString QUrl::fileName(ComponentFormattingOptions options) const | - | ||||||||||||||||||
2603 | { | - | ||||||||||||||||||
2604 | const QString ourPath = path(options); | - | ||||||||||||||||||
2605 | const int slash = ourPath.lastIndexOf(QLatin1Char('/')); | - | ||||||||||||||||||
2606 | if (slash == -1) | - | ||||||||||||||||||
2607 | return ourPath; | - | ||||||||||||||||||
2608 | return ourPath.mid(slash + 1); | - | ||||||||||||||||||
2609 | } | - | ||||||||||||||||||
2610 | - | |||||||||||||||||||
2611 | /*! | - | ||||||||||||||||||
2612 | \since 4.2 | - | ||||||||||||||||||
2613 | - | |||||||||||||||||||
2614 | Returns \c true if this URL contains a Query (i.e., if ? was seen on it). | - | ||||||||||||||||||
2615 | - | |||||||||||||||||||
2616 | \sa setQuery(), query(), hasFragment() | - | ||||||||||||||||||
2617 | */ | - | ||||||||||||||||||
2618 | bool QUrl::hasQuery() const | - | ||||||||||||||||||
2619 | { | - | ||||||||||||||||||
2620 | if (!d) return false; | - | ||||||||||||||||||
2621 | return d->hasQuery(); | - | ||||||||||||||||||
2622 | } | - | ||||||||||||||||||
2623 | - | |||||||||||||||||||
2624 | /*! | - | ||||||||||||||||||
2625 | Sets the query string of the URL to \a query. | - | ||||||||||||||||||
2626 | - | |||||||||||||||||||
2627 | This function is useful if you need to pass a query string that | - | ||||||||||||||||||
2628 | does not fit into the key-value pattern, or that uses a different | - | ||||||||||||||||||
2629 | scheme for encoding special characters than what is suggested by | - | ||||||||||||||||||
2630 | QUrl. | - | ||||||||||||||||||
2631 | - | |||||||||||||||||||
2632 | Passing a value of QString() to \a query (a null QString) unsets | - | ||||||||||||||||||
2633 | the query completely. However, passing a value of QString("") | - | ||||||||||||||||||
2634 | will set the query to an empty value, as if the original URL | - | ||||||||||||||||||
2635 | had a lone "?". | - | ||||||||||||||||||
2636 | - | |||||||||||||||||||
2637 | The \a query data is interpreted according to \a mode: in StrictMode, | - | ||||||||||||||||||
2638 | any '%' characters must be followed by exactly two hexadecimal characters | - | ||||||||||||||||||
2639 | and some characters (including space) are not allowed in undecoded form. In | - | ||||||||||||||||||
2640 | TolerantMode, all characters are accepted in undecoded form and the | - | ||||||||||||||||||
2641 | tolerant parser will correct stray '%' not followed by two hex characters. | - | ||||||||||||||||||
2642 | In DecodedMode, '%' stand for themselves and encoded characters are not | - | ||||||||||||||||||
2643 | possible. | - | ||||||||||||||||||
2644 | - | |||||||||||||||||||
2645 | Query strings often contain percent-encoded sequences, so use of | - | ||||||||||||||||||
2646 | DecodedMode is discouraged. One special sequence to be aware of is that of | - | ||||||||||||||||||
2647 | the plus character ('+'). QUrl does not convert spaces to plus characters, | - | ||||||||||||||||||
2648 | even though HTML forms posted by web browsers do. In order to represent an | - | ||||||||||||||||||
2649 | actual plus character in a query, the sequence "%2B" is usually used. This | - | ||||||||||||||||||
2650 | function will leave "%2B" sequences untouched in TolerantMode or | - | ||||||||||||||||||
2651 | StrictMode. | - | ||||||||||||||||||
2652 | - | |||||||||||||||||||
2653 | \sa query(), hasQuery() | - | ||||||||||||||||||
2654 | */ | - | ||||||||||||||||||
2655 | void QUrl::setQuery(const QString &query, ParsingMode mode) | - | ||||||||||||||||||
2656 | { | - | ||||||||||||||||||
2657 | detach(); | - | ||||||||||||||||||
2658 | d->clearError(); | - | ||||||||||||||||||
2659 | - | |||||||||||||||||||
2660 | QString data = query; | - | ||||||||||||||||||
2661 | if (mode == DecodedMode) { | - | ||||||||||||||||||
2662 | parseDecodedComponent(data); | - | ||||||||||||||||||
2663 | mode = TolerantMode; | - | ||||||||||||||||||
2664 | } | - | ||||||||||||||||||
2665 | - | |||||||||||||||||||
2666 | d->setQuery(data, 0, data.length()); | - | ||||||||||||||||||
2667 | if (query.isNull()) | - | ||||||||||||||||||
2668 | d->sectionIsPresent &= ~QUrlPrivate::Query; | - | ||||||||||||||||||
2669 | else if (mode == StrictMode && !d->validateComponent(QUrlPrivate::Query, query)) | - | ||||||||||||||||||
2670 | d->query.clear(); | - | ||||||||||||||||||
2671 | } | - | ||||||||||||||||||
2672 | - | |||||||||||||||||||
2673 | /*! | - | ||||||||||||||||||
2674 | \fn void QUrl::setEncodedQuery(const QByteArray &query) | - | ||||||||||||||||||
2675 | \deprecated | - | ||||||||||||||||||
2676 | - | |||||||||||||||||||
2677 | Sets the query string of the URL to \a query. The string is | - | ||||||||||||||||||
2678 | inserted as-is, and no further encoding is performed when calling | - | ||||||||||||||||||
2679 | toEncoded(). | - | ||||||||||||||||||
2680 | - | |||||||||||||||||||
2681 | This function is useful if you need to pass a query string that | - | ||||||||||||||||||
2682 | does not fit into the key-value pattern, or that uses a different | - | ||||||||||||||||||
2683 | scheme for encoding special characters than what is suggested by | - | ||||||||||||||||||
2684 | QUrl. | - | ||||||||||||||||||
2685 | - | |||||||||||||||||||
2686 | Passing a value of QByteArray() to \a query (a null QByteArray) unsets | - | ||||||||||||||||||
2687 | the query completely. However, passing a value of QByteArray("") | - | ||||||||||||||||||
2688 | will set the query to an empty value, as if the original URL | - | ||||||||||||||||||
2689 | had a lone "?". | - | ||||||||||||||||||
2690 | - | |||||||||||||||||||
2691 | \obsolete Use setQuery, which has the same null / empty behavior. | - | ||||||||||||||||||
2692 | - | |||||||||||||||||||
2693 | \sa encodedQuery(), hasQuery() | - | ||||||||||||||||||
2694 | */ | - | ||||||||||||||||||
2695 | - | |||||||||||||||||||
2696 | /*! | - | ||||||||||||||||||
2697 | \overload | - | ||||||||||||||||||
2698 | \since 5.0 | - | ||||||||||||||||||
2699 | Sets the query string of the URL to \a query. | - | ||||||||||||||||||
2700 | - | |||||||||||||||||||
2701 | This function reconstructs the query string from the QUrlQuery object and | - | ||||||||||||||||||
2702 | sets on this QUrl object. This function does not have parsing parameters | - | ||||||||||||||||||
2703 | because the QUrlQuery contains data that is already parsed. | - | ||||||||||||||||||
2704 | - | |||||||||||||||||||
2705 | \sa query(), hasQuery() | - | ||||||||||||||||||
2706 | */ | - | ||||||||||||||||||
2707 | void QUrl::setQuery(const QUrlQuery &query) | - | ||||||||||||||||||
2708 | { | - | ||||||||||||||||||
2709 | detach(); | - | ||||||||||||||||||
2710 | d->clearError(); | - | ||||||||||||||||||
2711 | - | |||||||||||||||||||
2712 | // we know the data is in the right format | - | ||||||||||||||||||
2713 | d->query = query.toString(); | - | ||||||||||||||||||
2714 | if (query.isEmpty()) | - | ||||||||||||||||||
2715 | d->sectionIsPresent &= ~QUrlPrivate::Query; | - | ||||||||||||||||||
2716 | else | - | ||||||||||||||||||
2717 | d->sectionIsPresent |= QUrlPrivate::Query; | - | ||||||||||||||||||
2718 | } | - | ||||||||||||||||||
2719 | - | |||||||||||||||||||
2720 | /*! | - | ||||||||||||||||||
2721 | \fn void QUrl::setQueryItems(const QList<QPair<QString, QString> > &query) | - | ||||||||||||||||||
2722 | \deprecated | - | ||||||||||||||||||
2723 | - | |||||||||||||||||||
2724 | Sets the query string of the URL to an encoded version of \a | - | ||||||||||||||||||
2725 | query. The contents of \a query are converted to a string | - | ||||||||||||||||||
2726 | internally, each pair delimited by the character returned by | - | ||||||||||||||||||
2727 | \l {QUrlQuery::queryPairDelimiter()}{queryPairDelimiter()}, and the key and value are delimited by | - | ||||||||||||||||||
2728 | \l {QUrlQuery::queryValueDelimiter()}{queryValueDelimiter()} | - | ||||||||||||||||||
2729 | - | |||||||||||||||||||
2730 | \note This method does not encode spaces (ASCII 0x20) as plus (+) signs, | - | ||||||||||||||||||
2731 | like HTML forms do. If you need that kind of encoding, you must encode | - | ||||||||||||||||||
2732 | the value yourself and use QUrl::setEncodedQueryItems. | - | ||||||||||||||||||
2733 | - | |||||||||||||||||||
2734 | \obsolete Use QUrlQuery and setQuery(). | - | ||||||||||||||||||
2735 | - | |||||||||||||||||||
2736 | \sa queryItems(), setEncodedQueryItems() | - | ||||||||||||||||||
2737 | */ | - | ||||||||||||||||||
2738 | - | |||||||||||||||||||
2739 | /*! | - | ||||||||||||||||||
2740 | \fn void QUrl::setEncodedQueryItems(const QList<QPair<QByteArray, QByteArray> > &query) | - | ||||||||||||||||||
2741 | \deprecated | - | ||||||||||||||||||
2742 | \since 4.4 | - | ||||||||||||||||||
2743 | - | |||||||||||||||||||
2744 | Sets the query string of the URL to the encoded version of \a | - | ||||||||||||||||||
2745 | query. The contents of \a query are converted to a string | - | ||||||||||||||||||
2746 | internally, each pair delimited by the character returned by | - | ||||||||||||||||||
2747 | \l {QUrlQuery::queryPairDelimiter()}{queryPairDelimiter()}, and the key and value are delimited by | - | ||||||||||||||||||
2748 | \l {QUrlQuery::queryValueDelimiter()}{queryValueDelimiter()}. | - | ||||||||||||||||||
2749 | - | |||||||||||||||||||
2750 | \obsolete Use QUrlQuery and setQuery(). | - | ||||||||||||||||||
2751 | - | |||||||||||||||||||
2752 | \sa encodedQueryItems(), setQueryItems() | - | ||||||||||||||||||
2753 | */ | - | ||||||||||||||||||
2754 | - | |||||||||||||||||||
2755 | /*! | - | ||||||||||||||||||
2756 | \fn void QUrl::addQueryItem(const QString &key, const QString &value) | - | ||||||||||||||||||
2757 | \deprecated | - | ||||||||||||||||||
2758 | - | |||||||||||||||||||
2759 | Inserts the pair \a key = \a value into the query string of the | - | ||||||||||||||||||
2760 | URL. | - | ||||||||||||||||||
2761 | - | |||||||||||||||||||
2762 | The key-value pair is encoded before it is added to the query. The | - | ||||||||||||||||||
2763 | pair is converted into separate strings internally. The \a key and | - | ||||||||||||||||||
2764 | \a value is first encoded into UTF-8 and then delimited by the | - | ||||||||||||||||||
2765 | character returned by \l {QUrlQuery::queryValueDelimiter()}{queryValueDelimiter()}. | - | ||||||||||||||||||
2766 | Each key-value pair is delimited by the character returned by | - | ||||||||||||||||||
2767 | \l {QUrlQuery::queryPairDelimiter()}{queryPairDelimiter()} | - | ||||||||||||||||||
2768 | - | |||||||||||||||||||
2769 | \note This method does not encode spaces (ASCII 0x20) as plus (+) signs, | - | ||||||||||||||||||
2770 | like HTML forms do. If you need that kind of encoding, you must encode | - | ||||||||||||||||||
2771 | the value yourself and use QUrl::addEncodedQueryItem. | - | ||||||||||||||||||
2772 | - | |||||||||||||||||||
2773 | \obsolete Use QUrlQuery and setQuery(). | - | ||||||||||||||||||
2774 | - | |||||||||||||||||||
2775 | \sa addEncodedQueryItem() | - | ||||||||||||||||||
2776 | */ | - | ||||||||||||||||||
2777 | - | |||||||||||||||||||
2778 | /*! | - | ||||||||||||||||||
2779 | \fn void QUrl::addEncodedQueryItem(const QByteArray &key, const QByteArray &value) | - | ||||||||||||||||||
2780 | \deprecated | - | ||||||||||||||||||
2781 | \since 4.4 | - | ||||||||||||||||||
2782 | - | |||||||||||||||||||
2783 | Inserts the pair \a key = \a value into the query string of the | - | ||||||||||||||||||
2784 | URL. | - | ||||||||||||||||||
2785 | - | |||||||||||||||||||
2786 | \obsolete Use QUrlQuery and setQuery(). | - | ||||||||||||||||||
2787 | - | |||||||||||||||||||
2788 | \sa addQueryItem() | - | ||||||||||||||||||
2789 | */ | - | ||||||||||||||||||
2790 | - | |||||||||||||||||||
2791 | /*! | - | ||||||||||||||||||
2792 | \fn QList<QPair<QString, QString> > QUrl::queryItems() const | - | ||||||||||||||||||
2793 | \deprecated | - | ||||||||||||||||||
2794 | - | |||||||||||||||||||
2795 | Returns the query string of the URL, as a map of keys and values. | - | ||||||||||||||||||
2796 | - | |||||||||||||||||||
2797 | \note This method does not decode spaces plus (+) signs as spaces (ASCII | - | ||||||||||||||||||
2798 | 0x20), like HTML forms do. If you need that kind of decoding, you must | - | ||||||||||||||||||
2799 | use QUrl::encodedQueryItems and decode the data yourself. | - | ||||||||||||||||||
2800 | - | |||||||||||||||||||
2801 | \obsolete Use QUrlQuery. | - | ||||||||||||||||||
2802 | - | |||||||||||||||||||
2803 | \sa setQueryItems(), setEncodedQuery() | - | ||||||||||||||||||
2804 | */ | - | ||||||||||||||||||
2805 | - | |||||||||||||||||||
2806 | /*! | - | ||||||||||||||||||
2807 | \fn QList<QPair<QByteArray, QByteArray> > QUrl::encodedQueryItems() const | - | ||||||||||||||||||
2808 | \deprecated | - | ||||||||||||||||||
2809 | \since 4.4 | - | ||||||||||||||||||
2810 | - | |||||||||||||||||||
2811 | Returns the query string of the URL, as a map of encoded keys and values. | - | ||||||||||||||||||
2812 | - | |||||||||||||||||||
2813 | \obsolete Use QUrlQuery. | - | ||||||||||||||||||
2814 | - | |||||||||||||||||||
2815 | \sa setEncodedQueryItems(), setQueryItems(), setEncodedQuery() | - | ||||||||||||||||||
2816 | */ | - | ||||||||||||||||||
2817 | - | |||||||||||||||||||
2818 | /*! | - | ||||||||||||||||||
2819 | \fn bool QUrl::hasQueryItem(const QString &key) const | - | ||||||||||||||||||
2820 | \deprecated | - | ||||||||||||||||||
2821 | - | |||||||||||||||||||
2822 | Returns \c true if there is a query string pair whose key is equal | - | ||||||||||||||||||
2823 | to \a key from the URL. | - | ||||||||||||||||||
2824 | - | |||||||||||||||||||
2825 | \obsolete Use QUrlQuery. | - | ||||||||||||||||||
2826 | - | |||||||||||||||||||
2827 | \sa hasEncodedQueryItem() | - | ||||||||||||||||||
2828 | */ | - | ||||||||||||||||||
2829 | - | |||||||||||||||||||
2830 | /*! | - | ||||||||||||||||||
2831 | \fn bool QUrl::hasEncodedQueryItem(const QByteArray &key) const | - | ||||||||||||||||||
2832 | \deprecated | - | ||||||||||||||||||
2833 | \since 4.4 | - | ||||||||||||||||||
2834 | - | |||||||||||||||||||
2835 | Returns \c true if there is a query string pair whose key is equal | - | ||||||||||||||||||
2836 | to \a key from the URL. | - | ||||||||||||||||||
2837 | - | |||||||||||||||||||
2838 | \obsolete Use QUrlQuery. | - | ||||||||||||||||||
2839 | - | |||||||||||||||||||
2840 | \sa hasQueryItem() | - | ||||||||||||||||||
2841 | */ | - | ||||||||||||||||||
2842 | - | |||||||||||||||||||
2843 | /*! | - | ||||||||||||||||||
2844 | \fn QString QUrl::queryItemValue(const QString &key) const | - | ||||||||||||||||||
2845 | \deprecated | - | ||||||||||||||||||
2846 | - | |||||||||||||||||||
2847 | Returns the first query string value whose key is equal to \a key | - | ||||||||||||||||||
2848 | from the URL. | - | ||||||||||||||||||
2849 | - | |||||||||||||||||||
2850 | \note This method does not decode spaces plus (+) signs as spaces (ASCII | - | ||||||||||||||||||
2851 | 0x20), like HTML forms do. If you need that kind of decoding, you must | - | ||||||||||||||||||
2852 | use QUrl::encodedQueryItemValue and decode the data yourself. | - | ||||||||||||||||||
2853 | - | |||||||||||||||||||
2854 | \obsolete Use QUrlQuery. | - | ||||||||||||||||||
2855 | - | |||||||||||||||||||
2856 | \sa allQueryItemValues() | - | ||||||||||||||||||
2857 | */ | - | ||||||||||||||||||
2858 | - | |||||||||||||||||||
2859 | /*! | - | ||||||||||||||||||
2860 | \fn QByteArray QUrl::encodedQueryItemValue(const QByteArray &key) const | - | ||||||||||||||||||
2861 | \deprecated | - | ||||||||||||||||||
2862 | \since 4.4 | - | ||||||||||||||||||
2863 | - | |||||||||||||||||||
2864 | Returns the first query string value whose key is equal to \a key | - | ||||||||||||||||||
2865 | from the URL. | - | ||||||||||||||||||
2866 | - | |||||||||||||||||||
2867 | \obsolete Use QUrlQuery. | - | ||||||||||||||||||
2868 | - | |||||||||||||||||||
2869 | \sa queryItemValue(), allQueryItemValues() | - | ||||||||||||||||||
2870 | */ | - | ||||||||||||||||||
2871 | - | |||||||||||||||||||
2872 | /*! | - | ||||||||||||||||||
2873 | \fn QStringList QUrl::allQueryItemValues(const QString &key) const | - | ||||||||||||||||||
2874 | \deprecated | - | ||||||||||||||||||
2875 | - | |||||||||||||||||||
2876 | Returns the a list of query string values whose key is equal to | - | ||||||||||||||||||
2877 | \a key from the URL. | - | ||||||||||||||||||
2878 | - | |||||||||||||||||||
2879 | \note This method does not decode spaces plus (+) signs as spaces (ASCII | - | ||||||||||||||||||
2880 | 0x20), like HTML forms do. If you need that kind of decoding, you must | - | ||||||||||||||||||
2881 | use QUrl::allEncodedQueryItemValues and decode the data yourself. | - | ||||||||||||||||||
2882 | - | |||||||||||||||||||
2883 | \obsolete Use QUrlQuery. | - | ||||||||||||||||||
2884 | - | |||||||||||||||||||
2885 | \sa queryItemValue() | - | ||||||||||||||||||
2886 | */ | - | ||||||||||||||||||
2887 | - | |||||||||||||||||||
2888 | /*! | - | ||||||||||||||||||
2889 | \fn QList<QByteArray> QUrl::allEncodedQueryItemValues(const QByteArray &key) const | - | ||||||||||||||||||
2890 | \deprecated | - | ||||||||||||||||||
2891 | \since 4.4 | - | ||||||||||||||||||
2892 | - | |||||||||||||||||||
2893 | Returns the a list of query string values whose key is equal to | - | ||||||||||||||||||
2894 | \a key from the URL. | - | ||||||||||||||||||
2895 | - | |||||||||||||||||||
2896 | \obsolete Use QUrlQuery. | - | ||||||||||||||||||
2897 | - | |||||||||||||||||||
2898 | \sa allQueryItemValues(), queryItemValue(), encodedQueryItemValue() | - | ||||||||||||||||||
2899 | */ | - | ||||||||||||||||||
2900 | - | |||||||||||||||||||
2901 | /*! | - | ||||||||||||||||||
2902 | \fn void QUrl::removeQueryItem(const QString &key) | - | ||||||||||||||||||
2903 | \deprecated | - | ||||||||||||||||||
2904 | - | |||||||||||||||||||
2905 | Removes the first query string pair whose key is equal to \a key | - | ||||||||||||||||||
2906 | from the URL. | - | ||||||||||||||||||
2907 | - | |||||||||||||||||||
2908 | \obsolete Use QUrlQuery. | - | ||||||||||||||||||
2909 | - | |||||||||||||||||||
2910 | \sa removeAllQueryItems() | - | ||||||||||||||||||
2911 | */ | - | ||||||||||||||||||
2912 | - | |||||||||||||||||||
2913 | /*! | - | ||||||||||||||||||
2914 | \fn void QUrl::removeEncodedQueryItem(const QByteArray &key) | - | ||||||||||||||||||
2915 | \deprecated | - | ||||||||||||||||||
2916 | \since 4.4 | - | ||||||||||||||||||
2917 | - | |||||||||||||||||||
2918 | Removes the first query string pair whose key is equal to \a key | - | ||||||||||||||||||
2919 | from the URL. | - | ||||||||||||||||||
2920 | - | |||||||||||||||||||
2921 | \obsolete Use QUrlQuery. | - | ||||||||||||||||||
2922 | - | |||||||||||||||||||
2923 | \sa removeQueryItem(), removeAllQueryItems() | - | ||||||||||||||||||
2924 | */ | - | ||||||||||||||||||
2925 | - | |||||||||||||||||||
2926 | /*! | - | ||||||||||||||||||
2927 | \fn void QUrl::removeAllQueryItems(const QString &key) | - | ||||||||||||||||||
2928 | \deprecated | - | ||||||||||||||||||
2929 | - | |||||||||||||||||||
2930 | Removes all the query string pairs whose key is equal to \a key | - | ||||||||||||||||||
2931 | from the URL. | - | ||||||||||||||||||
2932 | - | |||||||||||||||||||
2933 | \obsolete Use QUrlQuery. | - | ||||||||||||||||||
2934 | - | |||||||||||||||||||
2935 | \sa removeQueryItem() | - | ||||||||||||||||||
2936 | */ | - | ||||||||||||||||||
2937 | - | |||||||||||||||||||
2938 | /*! | - | ||||||||||||||||||
2939 | \fn void QUrl::removeAllEncodedQueryItems(const QByteArray &key) | - | ||||||||||||||||||
2940 | \deprecated | - | ||||||||||||||||||
2941 | \since 4.4 | - | ||||||||||||||||||
2942 | - | |||||||||||||||||||
2943 | Removes all the query string pairs whose key is equal to \a key | - | ||||||||||||||||||
2944 | from the URL. | - | ||||||||||||||||||
2945 | - | |||||||||||||||||||
2946 | \obsolete Use QUrlQuery. | - | ||||||||||||||||||
2947 | - | |||||||||||||||||||
2948 | \sa removeQueryItem() | - | ||||||||||||||||||
2949 | */ | - | ||||||||||||||||||
2950 | - | |||||||||||||||||||
2951 | /*! | - | ||||||||||||||||||
2952 | \fn QByteArray QUrl::encodedQuery() const | - | ||||||||||||||||||
2953 | \deprecated | - | ||||||||||||||||||
2954 | - | |||||||||||||||||||
2955 | Returns the query string of the URL in percent encoded form. | - | ||||||||||||||||||
2956 | - | |||||||||||||||||||
2957 | \obsolete Use query(QUrl::FullyEncoded).toLatin1() | - | ||||||||||||||||||
2958 | - | |||||||||||||||||||
2959 | \sa setEncodedQuery(), query() | - | ||||||||||||||||||
2960 | */ | - | ||||||||||||||||||
2961 | - | |||||||||||||||||||
2962 | /*! | - | ||||||||||||||||||
2963 | Returns the query string of the URL if there's a query string, or an empty | - | ||||||||||||||||||
2964 | result if not. To determine if the parsed URL contained a query string, use | - | ||||||||||||||||||
2965 | hasQuery(). | - | ||||||||||||||||||
2966 | - | |||||||||||||||||||
2967 | The \a options argument controls how to format the query component. All | - | ||||||||||||||||||
2968 | values produce an unambiguous result. With QUrl::FullyDecoded, all | - | ||||||||||||||||||
2969 | percent-encoded sequences are decoded; otherwise, the returned value may | - | ||||||||||||||||||
2970 | contain some percent-encoded sequences for some control sequences not | - | ||||||||||||||||||
2971 | representable in decoded form in QString. | - | ||||||||||||||||||
2972 | - | |||||||||||||||||||
2973 | Note that use of QUrl::FullyDecoded in queries is discouraged, as queries | - | ||||||||||||||||||
2974 | often contain data that is supposed to remain percent-encoded, including | - | ||||||||||||||||||
2975 | the use of the "%2B" sequence to represent a plus character ('+'). | - | ||||||||||||||||||
2976 | - | |||||||||||||||||||
2977 | \sa setQuery(), hasQuery() | - | ||||||||||||||||||
2978 | */ | - | ||||||||||||||||||
2979 | QString QUrl::query(ComponentFormattingOptions options) const | - | ||||||||||||||||||
2980 | { | - | ||||||||||||||||||
2981 | if (!d) return QString();QString result; | - | ||||||||||||||||||
2982 | if (d) {
| 2-189 | ||||||||||||||||||
2983 | d->appendQuery(result, options, QUrlPrivate::Query); | - | ||||||||||||||||||
2984 | if (d->hasQuery() && result.isNull())
| 2-166 | ||||||||||||||||||
2985 | result.detach(); executed 2 times by 1 test: result.detach(); Executed by:
| 2 | ||||||||||||||||||
2986 | } executed 189 times by 3 tests: end of block Executed by:
| 189 | ||||||||||||||||||
2987 | return result; executed 191 times by 3 tests: return result; Executed by:
| 191 | ||||||||||||||||||
2988 | } | - | ||||||||||||||||||
2989 | - | |||||||||||||||||||
2990 | /*! | - | ||||||||||||||||||
2991 | Sets the fragment of the URL to \a fragment. The fragment is the | - | ||||||||||||||||||
2992 | last part of the URL, represented by a '#' followed by a string of | - | ||||||||||||||||||
2993 | characters. It is typically used in HTTP for referring to a | - | ||||||||||||||||||
2994 | certain link or point on a page: | - | ||||||||||||||||||
2995 | - | |||||||||||||||||||
2996 | \image qurl-fragment.png | - | ||||||||||||||||||
2997 | - | |||||||||||||||||||
2998 | The fragment is sometimes also referred to as the URL "reference". | - | ||||||||||||||||||
2999 | - | |||||||||||||||||||
3000 | Passing an argument of QString() (a null QString) will unset the fragment. | - | ||||||||||||||||||
3001 | Passing an argument of QString("") (an empty but not null QString) will set the | - | ||||||||||||||||||
3002 | fragment to an empty string (as if the original URL had a lone "#"). | - | ||||||||||||||||||
3003 | - | |||||||||||||||||||
3004 | The \a fragment data is interpreted according to \a mode: in StrictMode, | - | ||||||||||||||||||
3005 | any '%' characters must be followed by exactly two hexadecimal characters | - | ||||||||||||||||||
3006 | and some characters (including space) are not allowed in undecoded form. In | - | ||||||||||||||||||
3007 | TolerantMode, all characters are accepted in undecoded form and the | - | ||||||||||||||||||
3008 | tolerant parser will correct stray '%' not followed by two hex characters. | - | ||||||||||||||||||
3009 | In DecodedMode, '%' stand for themselves and encoded characters are not | - | ||||||||||||||||||
3010 | possible. | - | ||||||||||||||||||
3011 | - | |||||||||||||||||||
3012 | QUrl::DecodedMode should be used when setting the fragment from a data | - | ||||||||||||||||||
3013 | source which is not a URL or with a fragment obtained by calling | - | ||||||||||||||||||
3014 | fragment() with the QUrl::FullyDecoded formatting option. | - | ||||||||||||||||||
3015 | - | |||||||||||||||||||
3016 | \sa fragment(), hasFragment() | - | ||||||||||||||||||
3017 | */ | - | ||||||||||||||||||
3018 | void QUrl::setFragment(const QString &fragment, ParsingMode mode) | - | ||||||||||||||||||
3019 | { | - | ||||||||||||||||||
3020 | detach(); | - | ||||||||||||||||||
3021 | d->clearError(); | - | ||||||||||||||||||
3022 | - | |||||||||||||||||||
3023 | QString data = fragment; | - | ||||||||||||||||||
3024 | if (mode == DecodedMode) { | - | ||||||||||||||||||
3025 | parseDecodedComponent(data); | - | ||||||||||||||||||
3026 | mode = TolerantMode; | - | ||||||||||||||||||
3027 | } | - | ||||||||||||||||||
3028 | - | |||||||||||||||||||
3029 | d->setFragment(data, 0, data.length()); | - | ||||||||||||||||||
3030 | if (fragment.isNull()) | - | ||||||||||||||||||
3031 | d->sectionIsPresent &= ~QUrlPrivate::Fragment; | - | ||||||||||||||||||
3032 | else if (mode == StrictMode && !d->validateComponent(QUrlPrivate::Fragment, fragment)) | - | ||||||||||||||||||
3033 | d->fragment.clear(); | - | ||||||||||||||||||
3034 | } | - | ||||||||||||||||||
3035 | - | |||||||||||||||||||
3036 | /*! | - | ||||||||||||||||||
3037 | Returns the fragment of the URL. To determine if the parsed URL contained a | - | ||||||||||||||||||
3038 | fragment, use hasFragment(). | - | ||||||||||||||||||
3039 | - | |||||||||||||||||||
3040 | The \a options argument controls how to format the fragment component. All | - | ||||||||||||||||||
3041 | values produce an unambiguous result. With QUrl::FullyDecoded, all | - | ||||||||||||||||||
3042 | percent-encoded sequences are decoded; otherwise, the returned value may | - | ||||||||||||||||||
3043 | contain some percent-encoded sequences for some control sequences not | - | ||||||||||||||||||
3044 | representable in decoded form in QString. | - | ||||||||||||||||||
3045 | - | |||||||||||||||||||
3046 | Note that QUrl::FullyDecoded may cause data loss if those non-representable | - | ||||||||||||||||||
3047 | sequences are present. It is recommended to use that value when the result | - | ||||||||||||||||||
3048 | will be used in a non-URL context. | - | ||||||||||||||||||
3049 | - | |||||||||||||||||||
3050 | \sa setFragment(), hasFragment() | - | ||||||||||||||||||
3051 | */ | - | ||||||||||||||||||
3052 | QString QUrl::fragment(ComponentFormattingOptions options) const | - | ||||||||||||||||||
3053 | { | - | ||||||||||||||||||
3054 | if (!d) return QString();QString result; | - | ||||||||||||||||||
3055 | if (d) {
| 2-128 | ||||||||||||||||||
3056 | d->appendFragment(result, options, QUrlPrivate::Fragment); | - | ||||||||||||||||||
3057 | if (d->hasFragment() && result.isNull())
| 2-69 | ||||||||||||||||||
3058 | result.detach(); executed 2 times by 1 test: result.detach(); Executed by:
| 2 | ||||||||||||||||||
3059 | } executed 128 times by 2 tests: end of block Executed by:
| 128 | ||||||||||||||||||
3060 | return result; executed 130 times by 2 tests: return result; Executed by:
| 130 | ||||||||||||||||||
3061 | } | - | ||||||||||||||||||
3062 | - | |||||||||||||||||||
3063 | /*! | - | ||||||||||||||||||
3064 | \fn void QUrl::setEncodedFragment(const QByteArray &fragment) | - | ||||||||||||||||||
3065 | \deprecated | - | ||||||||||||||||||
3066 | \since 4.4 | - | ||||||||||||||||||
3067 | - | |||||||||||||||||||
3068 | Sets the URL's fragment to the percent-encoded \a fragment. The fragment is the | - | ||||||||||||||||||
3069 | last part of the URL, represented by a '#' followed by a string of | - | ||||||||||||||||||
3070 | characters. It is typically used in HTTP for referring to a | - | ||||||||||||||||||
3071 | certain link or point on a page: | - | ||||||||||||||||||
3072 | - | |||||||||||||||||||
3073 | \image qurl-fragment.png | - | ||||||||||||||||||
3074 | - | |||||||||||||||||||
3075 | The fragment is sometimes also referred to as the URL "reference". | - | ||||||||||||||||||
3076 | - | |||||||||||||||||||
3077 | Passing an argument of QByteArray() (a null QByteArray) will unset the fragment. | - | ||||||||||||||||||
3078 | Passing an argument of QByteArray("") (an empty but not null QByteArray) | - | ||||||||||||||||||
3079 | will set the fragment to an empty string (as if the original URL | - | ||||||||||||||||||
3080 | had a lone "#"). | - | ||||||||||||||||||
3081 | - | |||||||||||||||||||
3082 | \obsolete Use setFragment(), which has the same behavior of null / empty. | - | ||||||||||||||||||
3083 | - | |||||||||||||||||||
3084 | \sa setFragment(), encodedFragment() | - | ||||||||||||||||||
3085 | */ | - | ||||||||||||||||||
3086 | - | |||||||||||||||||||
3087 | /*! | - | ||||||||||||||||||
3088 | \fn QByteArray QUrl::encodedFragment() const | - | ||||||||||||||||||
3089 | \deprecated | - | ||||||||||||||||||
3090 | \since 4.4 | - | ||||||||||||||||||
3091 | - | |||||||||||||||||||
3092 | Returns the fragment of the URL if it is defined; otherwise an | - | ||||||||||||||||||
3093 | empty string is returned. The returned value will have its | - | ||||||||||||||||||
3094 | non-ASCII and other control characters percent-encoded, as in | - | ||||||||||||||||||
3095 | toEncoded(). | - | ||||||||||||||||||
3096 | - | |||||||||||||||||||
3097 | \obsolete Use query(QUrl::FullyEncoded).toLatin1(). | - | ||||||||||||||||||
3098 | - | |||||||||||||||||||
3099 | \sa setEncodedFragment(), toEncoded() | - | ||||||||||||||||||
3100 | */ | - | ||||||||||||||||||
3101 | - | |||||||||||||||||||
3102 | /*! | - | ||||||||||||||||||
3103 | \since 4.2 | - | ||||||||||||||||||
3104 | - | |||||||||||||||||||
3105 | Returns \c true if this URL contains a fragment (i.e., if # was seen on it). | - | ||||||||||||||||||
3106 | - | |||||||||||||||||||
3107 | \sa fragment(), setFragment() | - | ||||||||||||||||||
3108 | */ | - | ||||||||||||||||||
3109 | bool QUrl::hasFragment() const | - | ||||||||||||||||||
3110 | { | - | ||||||||||||||||||
3111 | if (!d) return false; | - | ||||||||||||||||||
3112 | return d->hasFragment(); | - | ||||||||||||||||||
3113 | } | - | ||||||||||||||||||
3114 | - | |||||||||||||||||||
3115 | /*! | - | ||||||||||||||||||
3116 | \since 4.8 | - | ||||||||||||||||||
3117 | - | |||||||||||||||||||
3118 | Returns the TLD (Top-Level Domain) of the URL, (e.g. .co.uk, .net). | - | ||||||||||||||||||
3119 | Note that the return value is prefixed with a '.' unless the | - | ||||||||||||||||||
3120 | URL does not contain a valid TLD, in which case the function returns | - | ||||||||||||||||||
3121 | an empty string. | - | ||||||||||||||||||
3122 | - | |||||||||||||||||||
3123 | Note that this function considers a TLD to be any domain that allows users | - | ||||||||||||||||||
3124 | to register subdomains under, including many home, dynamic DNS websites and | - | ||||||||||||||||||
3125 | blogging providers. This is useful for determining whether two websites | - | ||||||||||||||||||
3126 | belong to the same infrastructure and communication should be allowed, such | - | ||||||||||||||||||
3127 | as browser cookies: two domains should be considered part of the same | - | ||||||||||||||||||
3128 | website if they share at least one label in addition to the value | - | ||||||||||||||||||
3129 | returned by this function. | - | ||||||||||||||||||
3130 | - | |||||||||||||||||||
3131 | \list | - | ||||||||||||||||||
3132 | \li \c{foo.co.uk} and \c{foo.com} do not share a top-level domain | - | ||||||||||||||||||
3133 | \li \c{foo.co.uk} and \c{bar.co.uk} share the \c{.co.uk} domain, but the next label is different | - | ||||||||||||||||||
3134 | \li \c{www.foo.co.uk} and \c{ftp.foo.co.uk} share the same top-level domain and one more label, | - | ||||||||||||||||||
3135 | so they are considered part of the same site | - | ||||||||||||||||||
3136 | \endlist | - | ||||||||||||||||||
3137 | - | |||||||||||||||||||
3138 | If \a options includes EncodeUnicode, the returned string will be in | - | ||||||||||||||||||
3139 | ASCII Compatible Encoding. | - | ||||||||||||||||||
3140 | */ | - | ||||||||||||||||||
3141 | QString QUrl::topLevelDomain(ComponentFormattingOptions options) const | - | ||||||||||||||||||
3142 | { | - | ||||||||||||||||||
3143 | QString tld = qTopLevelDomain(host()); | - | ||||||||||||||||||
3144 | if (options & EncodeUnicode) { | - | ||||||||||||||||||
3145 | return qt_ACE_do(tld, ToAceOnly, AllowLeadingDot); | - | ||||||||||||||||||
3146 | } | - | ||||||||||||||||||
3147 | return tld; | - | ||||||||||||||||||
3148 | } | - | ||||||||||||||||||
3149 | - | |||||||||||||||||||
3150 | /*! | - | ||||||||||||||||||
3151 | Returns the result of the merge of this URL with \a relative. This | - | ||||||||||||||||||
3152 | URL is used as a base to convert \a relative to an absolute URL. | - | ||||||||||||||||||
3153 | - | |||||||||||||||||||
3154 | If \a relative is not a relative URL, this function will return \a | - | ||||||||||||||||||
3155 | relative directly. Otherwise, the paths of the two URLs are | - | ||||||||||||||||||
3156 | merged, and the new URL returned has the scheme and authority of | - | ||||||||||||||||||
3157 | the base URL, but with the merged path, as in the following | - | ||||||||||||||||||
3158 | example: | - | ||||||||||||||||||
3159 | - | |||||||||||||||||||
3160 | \snippet code/src_corelib_io_qurl.cpp 5 | - | ||||||||||||||||||
3161 | - | |||||||||||||||||||
3162 | Calling resolved() with ".." returns a QUrl whose directory is | - | ||||||||||||||||||
3163 | one level higher than the original. Similarly, calling resolved() | - | ||||||||||||||||||
3164 | with "../.." removes two levels from the path. If \a relative is | - | ||||||||||||||||||
3165 | "/", the path becomes "/". | - | ||||||||||||||||||
3166 | - | |||||||||||||||||||
3167 | \sa isRelative() | - | ||||||||||||||||||
3168 | */ | - | ||||||||||||||||||
3169 | QUrl QUrl::resolved(const QUrl &relative) const | - | ||||||||||||||||||
3170 | { | - | ||||||||||||||||||
3171 | if (!d) return relative; | - | ||||||||||||||||||
3172 | if (!relative.d) return *this; | - | ||||||||||||||||||
3173 | - | |||||||||||||||||||
3174 | QUrl t; | - | ||||||||||||||||||
3175 | // Compatibility hack (mostly for qtdeclarative) : treat "file:relative.txt" as relative even though QUrl::isRelative() says false | - | ||||||||||||||||||
3176 | if (!relative.d->scheme.isEmpty() && (!relative.isLocalFile() || QDir::isAbsolutePath(relative.d->path))) { | - | ||||||||||||||||||
3177 | t = relative; | - | ||||||||||||||||||
3178 | t.detach(); | - | ||||||||||||||||||
3179 | } else { | - | ||||||||||||||||||
3180 | if (relative.d->hasAuthority()) { | - | ||||||||||||||||||
3181 | t = relative; | - | ||||||||||||||||||
3182 | t.detach(); | - | ||||||||||||||||||
3183 | } else { | - | ||||||||||||||||||
3184 | t.d = new QUrlPrivate; | - | ||||||||||||||||||
3185 | - | |||||||||||||||||||
3186 | // copy the authority | - | ||||||||||||||||||
3187 | t.d->userName = d->userName; | - | ||||||||||||||||||
3188 | t.d->password = d->password; | - | ||||||||||||||||||
3189 | t.d->host = d->host; | - | ||||||||||||||||||
3190 | t.d->port = d->port; | - | ||||||||||||||||||
3191 | t.d->sectionIsPresent = d->sectionIsPresent & QUrlPrivate::Authority; | - | ||||||||||||||||||
3192 | - | |||||||||||||||||||
3193 | if (relative.d->path.isEmpty()) { | - | ||||||||||||||||||
3194 | t.d->path = d->path; | - | ||||||||||||||||||
3195 | if (relative.d->hasQuery()) { | - | ||||||||||||||||||
3196 | t.d->query = relative.d->query; | - | ||||||||||||||||||
3197 | t.d->sectionIsPresent |= QUrlPrivate::Query; | - | ||||||||||||||||||
3198 | } else if (d->hasQuery()) { | - | ||||||||||||||||||
3199 | t.d->query = d->query; | - | ||||||||||||||||||
3200 | t.d->sectionIsPresent |= QUrlPrivate::Query; | - | ||||||||||||||||||
3201 | } | - | ||||||||||||||||||
3202 | } else { | - | ||||||||||||||||||
3203 | t.d->path = relative.d->path.startsWith(QLatin1Char('/')) | - | ||||||||||||||||||
3204 | ? relative.d->path | - | ||||||||||||||||||
3205 | : d->mergePaths(relative.d->path); | - | ||||||||||||||||||
3206 | if (relative.d->hasQuery()) { | - | ||||||||||||||||||
3207 | t.d->query = relative.d->query; | - | ||||||||||||||||||
3208 | t.d->sectionIsPresent |= QUrlPrivate::Query; | - | ||||||||||||||||||
3209 | } | - | ||||||||||||||||||
3210 | } | - | ||||||||||||||||||
3211 | } | - | ||||||||||||||||||
3212 | t.d->scheme = d->scheme; | - | ||||||||||||||||||
3213 | if (d->hasScheme()) | - | ||||||||||||||||||
3214 | t.d->sectionIsPresent |= QUrlPrivate::Scheme; | - | ||||||||||||||||||
3215 | else | - | ||||||||||||||||||
3216 | t.d->sectionIsPresent &= ~QUrlPrivate::Scheme; | - | ||||||||||||||||||
3217 | t.d->flags |= d->flags & QUrlPrivate::IsLocalFile; | - | ||||||||||||||||||
3218 | } | - | ||||||||||||||||||
3219 | t.d->fragment = relative.d->fragment; | - | ||||||||||||||||||
3220 | if (relative.d->hasFragment()) | - | ||||||||||||||||||
3221 | t.d->sectionIsPresent |= QUrlPrivate::Fragment; | - | ||||||||||||||||||
3222 | else | - | ||||||||||||||||||
3223 | t.d->sectionIsPresent &= ~QUrlPrivate::Fragment; | - | ||||||||||||||||||
3224 | - | |||||||||||||||||||
3225 | removeDotsFromPath(&t.d->path); | - | ||||||||||||||||||
3226 | - | |||||||||||||||||||
3227 | #if defined(QURL_DEBUG) | - | ||||||||||||||||||
3228 | qDebug("QUrl(\"%s\").resolved(\"%s\") = \"%s\"", | - | ||||||||||||||||||
3229 | qPrintable(url()), | - | ||||||||||||||||||
3230 | qPrintable(relative.url()), | - | ||||||||||||||||||
3231 | qPrintable(t.url())); | - | ||||||||||||||||||
3232 | #endif | - | ||||||||||||||||||
3233 | return t; | - | ||||||||||||||||||
3234 | } | - | ||||||||||||||||||
3235 | - | |||||||||||||||||||
3236 | /*! | - | ||||||||||||||||||
3237 | Returns \c true if the URL is relative; otherwise returns \c false. A URL is | - | ||||||||||||||||||
3238 | relative reference if its scheme is undefined; this function is therefore | - | ||||||||||||||||||
3239 | equivalent to calling scheme().isEmpty(). | - | ||||||||||||||||||
3240 | - | |||||||||||||||||||
3241 | Relative references are defined in RFC 3986 section 4.2. | - | ||||||||||||||||||
3242 | */ | - | ||||||||||||||||||
3243 | bool QUrl::isRelative() const | - | ||||||||||||||||||
3244 | { | - | ||||||||||||||||||
3245 | if (!d) return true; | - | ||||||||||||||||||
3246 | return !d->hasScheme(); | - | ||||||||||||||||||
3247 | } | - | ||||||||||||||||||
3248 | - | |||||||||||||||||||
3249 | /*! | - | ||||||||||||||||||
3250 | Returns a string representation of the URL. The output can be customized by | - | ||||||||||||||||||
3251 | passing flags with \a options. The option QUrl::FullyDecoded is not | - | ||||||||||||||||||
3252 | permitted in this function since it would generate ambiguous data. | - | ||||||||||||||||||
3253 | - | |||||||||||||||||||
3254 | The resulting QString can be passed back to a QUrl later on. | - | ||||||||||||||||||
3255 | - | |||||||||||||||||||
3256 | Synonym for toString(options). | - | ||||||||||||||||||
3257 | - | |||||||||||||||||||
3258 | \sa FormattingOptions, toEncoded(), toString() | - | ||||||||||||||||||
3259 | */ | - | ||||||||||||||||||
3260 | QString QUrl::url(FormattingOptions options) const | - | ||||||||||||||||||
3261 | { | - | ||||||||||||||||||
3262 | return toString(options); | - | ||||||||||||||||||
3263 | } | - | ||||||||||||||||||
3264 | - | |||||||||||||||||||
3265 | /*! | - | ||||||||||||||||||
3266 | Returns a string representation of the URL. The output can be customized by | - | ||||||||||||||||||
3267 | passing flags with \a options. The option QUrl::FullyDecoded is not | - | ||||||||||||||||||
3268 | permitted in this function since it would generate ambiguous data. | - | ||||||||||||||||||
3269 | - | |||||||||||||||||||
3270 | The default formatting option is \l{QUrl::FormattingOptions}{PrettyDecoded}. | - | ||||||||||||||||||
3271 | - | |||||||||||||||||||
3272 | \sa FormattingOptions, url(), setUrl() | - | ||||||||||||||||||
3273 | */ | - | ||||||||||||||||||
3274 | QString QUrl::toString(FormattingOptions options) const | - | ||||||||||||||||||
3275 | { | - | ||||||||||||||||||
3276 | QString url; | - | ||||||||||||||||||
3277 | if (!isValid()) {
| 149-9039 | ||||||||||||||||||
3278 | // also catches isEmpty() | - | ||||||||||||||||||
3279 | return QString();url; executed 149 times by 5 tests: return url; Executed by:
| 149 | ||||||||||||||||||
3280 | } | - | ||||||||||||||||||
3281 | if (options == QUrl::FullyDecoded) {
| 0-9039 | ||||||||||||||||||
3282 | qWarning("QUrl: QUrl::FullyDecoded is not permitted when reconstructing the full URL"); | - | ||||||||||||||||||
3283 | options = QUrl::PrettyDecoded; | - | ||||||||||||||||||
3284 | } never executed: end of block | 0 | ||||||||||||||||||
3285 | - | |||||||||||||||||||
3286 | // return just the path if: | - | ||||||||||||||||||
3287 | // - QUrl::PreferLocalFile is passed | - | ||||||||||||||||||
3288 | // - QUrl::RemovePath isn't passed (rather stupid if the user did...) | - | ||||||||||||||||||
3289 | // - there's no query or fragment to return | - | ||||||||||||||||||
3290 | // that is, either they aren't present, or we're removing them | - | ||||||||||||||||||
3291 | // - it's a local file | - | ||||||||||||||||||
3292 | if (options.testFlag(QUrl::PreferLocalFile) && !options.testFlag(QUrl::RemovePath)
| 0-9032 | ||||||||||||||||||
3293 | && (!d->hasQuery() || options.testFlag(QUrl::RemoveQuery))
| 0-7 | ||||||||||||||||||
3294 | && (!d->hasFragment() || options.testFlag(QUrl::RemoveFragment))
| 0-6 | ||||||||||||||||||
3295 | && isLocalFile()) {
| 2-4 | ||||||||||||||||||
3296 | returnurl = d->toLocalFile(options); | - | ||||||||||||||||||
3297 | } executed 4 times by 1 test: return url; Executed by:
| 4 | ||||||||||||||||||
QString executed 4 times by 1 test: return url;return url; Executed by:
executed 4 times by 1 test: return url; Executed by:
| ||||||||||||||||||||
3298 | } | - | ||||||||||||||||||
3299 | - | |||||||||||||||||||
3300 | // for the full URL, we consider that the reserved characters are prettier if encoded | - | ||||||||||||||||||
3301 | if (options & DecodeReserved)
| 35-9000 | ||||||||||||||||||
3302 | options &= ~EncodeReserved; executed 35 times by 1 test: options &= ~EncodeReserved; Executed by:
| 35 | ||||||||||||||||||
3303 | else | - | ||||||||||||||||||
3304 | options |= EncodeReserved; executed 9000 times by 28 tests: options |= EncodeReserved; Executed by:
| 9000 | ||||||||||||||||||
3305 | - | |||||||||||||||||||
3306 | if (!(options & QUrl::RemoveScheme) && d->hasScheme())
| 210-7044 | ||||||||||||||||||
3307 | url += d->scheme + QLatin1Char(':'); executed 6834 times by 25 tests: url += d->scheme + QLatin1Char(':'); Executed by:
| 6834 | ||||||||||||||||||
3308 | - | |||||||||||||||||||
3309 | bool pathIsAbsolute = d->path.startsWith(QLatin1Char('/')); | - | ||||||||||||||||||
3310 | if (!((options & QUrl::RemoveAuthority) == QUrl::RemoveAuthority) && d->hasAuthority()) {
| 1621-7073 | ||||||||||||||||||
3311 | url += QLatin1String("//"); | - | ||||||||||||||||||
3312 | d->appendAuthority(url, options, QUrlPrivate::FullUrl); | - | ||||||||||||||||||
3313 | } else if (isLocalFile() && pathIsAbsolute) { executed 5452 times by 20 tests: end of block Executed by:
| 285-5452 | ||||||||||||||||||
3314 | // Comply with the XDG file URI spec, which requires triple slashes. | - | ||||||||||||||||||
3315 | url += QLatin1String("//"); | - | ||||||||||||||||||
3316 | } executed 1038 times by 9 tests: end of block Executed by:
| 1038 | ||||||||||||||||||
3317 | - | |||||||||||||||||||
3318 | if (!(options & QUrl::RemovePath))
| 1906-7129 | ||||||||||||||||||
3319 | d->appendPath(url, options, QUrlPrivate::FullUrl); executed 7129 times by 28 tests: d->appendPath(url, options, QUrlPrivate::FullUrl); Executed by:
| 7129 | ||||||||||||||||||
3320 | - | |||||||||||||||||||
3321 | if (!(options & QUrl::RemoveQuery) && d->hasQuery()) {
| 535-7121 | ||||||||||||||||||
3322 | url += QLatin1Char('?'); | - | ||||||||||||||||||
3323 | d->appendQuery(url, options, QUrlPrivate::FullUrl); | - | ||||||||||||||||||
3324 | } executed 535 times by 4 tests: end of block Executed by:
| 535 | ||||||||||||||||||
3325 | if (!(options & QUrl::RemoveFragment) && d->hasFragment()) {
| 792-6032 | ||||||||||||||||||
3326 | url += QLatin1Char('#'); | - | ||||||||||||||||||
3327 | d->appendFragment(url, options, QUrlPrivate::FullUrl); | - | ||||||||||||||||||
3328 | } executed 792 times by 4 tests: end of block Executed by:
| 792 | ||||||||||||||||||
3329 | - | |||||||||||||||||||
3330 | return url; executed 9035 times by 28 tests: return url; Executed by:
| 9035 | ||||||||||||||||||
3331 | } | - | ||||||||||||||||||
3332 | - | |||||||||||||||||||
3333 | /*! | - | ||||||||||||||||||
3334 | \since 5.0 | - | ||||||||||||||||||
3335 | - | |||||||||||||||||||
3336 | Returns a human-displayable string representation of the URL. | - | ||||||||||||||||||
3337 | The output can be customized by passing flags with \a options. | - | ||||||||||||||||||
3338 | The option RemovePassword is always enabled, since passwords | - | ||||||||||||||||||
3339 | should never be shown back to users. | - | ||||||||||||||||||
3340 | - | |||||||||||||||||||
3341 | With the default options, the resulting QString can be passed back | - | ||||||||||||||||||
3342 | to a QUrl later on, but any password that was present initially will | - | ||||||||||||||||||
3343 | be lost. | - | ||||||||||||||||||
3344 | - | |||||||||||||||||||
3345 | \sa FormattingOptions, toEncoded(), toString() | - | ||||||||||||||||||
3346 | */ | - | ||||||||||||||||||
3347 | - | |||||||||||||||||||
3348 | QString QUrl::toDisplayString(FormattingOptions options) const | - | ||||||||||||||||||
3349 | { | - | ||||||||||||||||||
3350 | return toString(options | RemovePassword); | - | ||||||||||||||||||
3351 | } | - | ||||||||||||||||||
3352 | - | |||||||||||||||||||
3353 | /*! | - | ||||||||||||||||||
3354 | \since 5.2 | - | ||||||||||||||||||
3355 | - | |||||||||||||||||||
3356 | Returns an adjusted version of the URL. | - | ||||||||||||||||||
3357 | The output can be customized by passing flags with \a options. | - | ||||||||||||||||||
3358 | - | |||||||||||||||||||
3359 | The encoding options from QUrl::ComponentFormattingOption don't make | - | ||||||||||||||||||
3360 | much sense for this method, nor does QUrl::PreferLocalFile. | - | ||||||||||||||||||
3361 | - | |||||||||||||||||||
3362 | This is always equivalent to QUrl(url.toString(options)). | - | ||||||||||||||||||
3363 | - | |||||||||||||||||||
3364 | \sa FormattingOptions, toEncoded(), toString() | - | ||||||||||||||||||
3365 | */ | - | ||||||||||||||||||
3366 | QUrl QUrl::adjusted(QUrl::FormattingOptions options) const | - | ||||||||||||||||||
3367 | { | - | ||||||||||||||||||
3368 | if (!isValid()) { | - | ||||||||||||||||||
3369 | // also catches isEmpty() | - | ||||||||||||||||||
3370 | return QUrl(); | - | ||||||||||||||||||
3371 | } | - | ||||||||||||||||||
3372 | QUrl that = *this; | - | ||||||||||||||||||
3373 | if (options & RemoveScheme) | - | ||||||||||||||||||
3374 | that.setScheme(QString()); | - | ||||||||||||||||||
3375 | if ((options & RemoveAuthority) == RemoveAuthority) { | - | ||||||||||||||||||
3376 | that.setAuthority(QString()); | - | ||||||||||||||||||
3377 | } else { | - | ||||||||||||||||||
3378 | if ((options & RemoveUserInfo) == RemoveUserInfo) | - | ||||||||||||||||||
3379 | that.setUserInfo(QString()); | - | ||||||||||||||||||
3380 | else if (options & RemovePassword) | - | ||||||||||||||||||
3381 | that.setPassword(QString()); | - | ||||||||||||||||||
3382 | if (options & RemovePort) | - | ||||||||||||||||||
3383 | that.setPort(-1); | - | ||||||||||||||||||
3384 | } | - | ||||||||||||||||||
3385 | if (options & RemoveQuery) | - | ||||||||||||||||||
3386 | that.setQuery(QString()); | - | ||||||||||||||||||
3387 | if (options & RemoveFragment) | - | ||||||||||||||||||
3388 | that.setFragment(QString()); | - | ||||||||||||||||||
3389 | if (options & RemovePath) { | - | ||||||||||||||||||
3390 | that.setPath(QString()); | - | ||||||||||||||||||
3391 | } else if (options & (StripTrailingSlash | RemoveFilename | NormalizePathSegments)) { | - | ||||||||||||||||||
3392 | that.detach(); | - | ||||||||||||||||||
3393 | QString path; | - | ||||||||||||||||||
3394 | d->appendPath(path, options | FullyEncoded, QUrlPrivate::Path); | - | ||||||||||||||||||
3395 | that.d->setPath(path, 0, path.length()); | - | ||||||||||||||||||
3396 | } | - | ||||||||||||||||||
3397 | return that; | - | ||||||||||||||||||
3398 | } | - | ||||||||||||||||||
3399 | - | |||||||||||||||||||
3400 | /*! | - | ||||||||||||||||||
3401 | Returns the encoded representation of the URL if it's valid; | - | ||||||||||||||||||
3402 | otherwise an empty QByteArray is returned. The output can be | - | ||||||||||||||||||
3403 | customized by passing flags with \a options. | - | ||||||||||||||||||
3404 | - | |||||||||||||||||||
3405 | The user info, path and fragment are all converted to UTF-8, and | - | ||||||||||||||||||
3406 | all non-ASCII characters are then percent encoded. The host name | - | ||||||||||||||||||
3407 | is encoded using Punycode. | - | ||||||||||||||||||
3408 | */ | - | ||||||||||||||||||
3409 | QByteArray QUrl::toEncoded(FormattingOptions options) const | - | ||||||||||||||||||
3410 | { | - | ||||||||||||||||||
3411 | options &= ~(FullyDecoded | FullyEncoded); | - | ||||||||||||||||||
3412 | QString stringForm = toString(options | FullyEncoded); | - | ||||||||||||||||||
3413 | return stringForm.toLatin1(); | - | ||||||||||||||||||
3414 | } | - | ||||||||||||||||||
3415 | - | |||||||||||||||||||
3416 | /*! | - | ||||||||||||||||||
3417 | \fn QUrl QUrl::fromEncoded(const QByteArray &input, ParsingMode parsingMode) | - | ||||||||||||||||||
3418 | - | |||||||||||||||||||
3419 | Parses \a input and returns the corresponding QUrl. \a input is | - | ||||||||||||||||||
3420 | assumed to be in encoded form, containing only ASCII characters. | - | ||||||||||||||||||
3421 | - | |||||||||||||||||||
3422 | Parses the URL using \a parsingMode. See setUrl() for more information on | - | ||||||||||||||||||
3423 | this parameter. QUrl::DecodedMode is not permitted in this context. | - | ||||||||||||||||||
3424 | - | |||||||||||||||||||
3425 | \sa toEncoded(), setUrl() | - | ||||||||||||||||||
3426 | */ | - | ||||||||||||||||||
3427 | QUrl QUrl::fromEncoded(const QByteArray &input, ParsingMode mode) | - | ||||||||||||||||||
3428 | { | - | ||||||||||||||||||
3429 | return QUrl(QString::fromUtf8(input.constData(), input.size()), mode); | - | ||||||||||||||||||
3430 | } | - | ||||||||||||||||||
3431 | - | |||||||||||||||||||
3432 | /*! | - | ||||||||||||||||||
3433 | Returns a decoded copy of \a input. \a input is first decoded from | - | ||||||||||||||||||
3434 | percent encoding, then converted from UTF-8 to unicode. | - | ||||||||||||||||||
3435 | */ | - | ||||||||||||||||||
3436 | QString QUrl::fromPercentEncoding(const QByteArray &input) | - | ||||||||||||||||||
3437 | { | - | ||||||||||||||||||
3438 | QByteArray ba = QByteArray::fromPercentEncoding(input); | - | ||||||||||||||||||
3439 | return QString::fromUtf8(ba, ba.size()); | - | ||||||||||||||||||
3440 | } | - | ||||||||||||||||||
3441 | - | |||||||||||||||||||
3442 | /*! | - | ||||||||||||||||||
3443 | Returns an encoded copy of \a input. \a input is first converted | - | ||||||||||||||||||
3444 | to UTF-8, and all ASCII-characters that are not in the unreserved group | - | ||||||||||||||||||
3445 | are percent encoded. To prevent characters from being percent encoded | - | ||||||||||||||||||
3446 | pass them to \a exclude. To force characters to be percent encoded pass | - | ||||||||||||||||||
3447 | them to \a include. | - | ||||||||||||||||||
3448 | - | |||||||||||||||||||
3449 | Unreserved is defined as: | - | ||||||||||||||||||
3450 | \tt {ALPHA / DIGIT / "-" / "." / "_" / "~"} | - | ||||||||||||||||||
3451 | - | |||||||||||||||||||
3452 | \snippet code/src_corelib_io_qurl.cpp 6 | - | ||||||||||||||||||
3453 | */ | - | ||||||||||||||||||
3454 | QByteArray QUrl::toPercentEncoding(const QString &input, const QByteArray &exclude, const QByteArray &include) | - | ||||||||||||||||||
3455 | { | - | ||||||||||||||||||
3456 | return input.toUtf8().toPercentEncoding(exclude, include); | - | ||||||||||||||||||
3457 | } | - | ||||||||||||||||||
3458 | - | |||||||||||||||||||
3459 | /*! \fn QUrl QUrl::fromCFURL(CFURLRef url) | - | ||||||||||||||||||
3460 | \since 5.2 | - | ||||||||||||||||||
3461 | - | |||||||||||||||||||
3462 | Constructs a QUrl containing a copy of the CFURL \a url. | - | ||||||||||||||||||
3463 | */ | - | ||||||||||||||||||
3464 | - | |||||||||||||||||||
3465 | /*! \fn CFURLRef QUrl::toCFURL() const | - | ||||||||||||||||||
3466 | \since 5.2 | - | ||||||||||||||||||
3467 | - | |||||||||||||||||||
3468 | Creates a CFURL from a QUrl. The caller owns the CFURL and is | - | ||||||||||||||||||
3469 | responsible for releasing it. | - | ||||||||||||||||||
3470 | */ | - | ||||||||||||||||||
3471 | - | |||||||||||||||||||
3472 | /*! | - | ||||||||||||||||||
3473 | \fn QUrl QUrl::fromNSURL(const NSURL *url) | - | ||||||||||||||||||
3474 | \since 5.2 | - | ||||||||||||||||||
3475 | - | |||||||||||||||||||
3476 | Constructs a QUrl containing a copy of the NSURL \a url. | - | ||||||||||||||||||
3477 | */ | - | ||||||||||||||||||
3478 | - | |||||||||||||||||||
3479 | /*! | - | ||||||||||||||||||
3480 | \fn NSURL* QUrl::toNSURL() const | - | ||||||||||||||||||
3481 | \since 5.2 | - | ||||||||||||||||||
3482 | - | |||||||||||||||||||
3483 | Creates a NSURL from a QUrl. The NSURL is autoreleased. | - | ||||||||||||||||||
3484 | */ | - | ||||||||||||||||||
3485 | - | |||||||||||||||||||
3486 | /*! | - | ||||||||||||||||||
3487 | \internal | - | ||||||||||||||||||
3488 | \since 5.0 | - | ||||||||||||||||||
3489 | Used in the setEncodedXXX compatibility functions. Converts \a ba to | - | ||||||||||||||||||
3490 | QString form. | - | ||||||||||||||||||
3491 | */ | - | ||||||||||||||||||
3492 | QString QUrl::fromEncodedComponent_helper(const QByteArray &ba) | - | ||||||||||||||||||
3493 | { | - | ||||||||||||||||||
3494 | return qt_urlRecodeByteArray(ba); | - | ||||||||||||||||||
3495 | } | - | ||||||||||||||||||
3496 | - | |||||||||||||||||||
3497 | /*! | - | ||||||||||||||||||
3498 | \fn QByteArray QUrl::toPunycode(const QString &uc) | - | ||||||||||||||||||
3499 | \obsolete | - | ||||||||||||||||||
3500 | Returns a \a uc in Punycode encoding. | - | ||||||||||||||||||
3501 | - | |||||||||||||||||||
3502 | Punycode is a Unicode encoding used for internationalized domain | - | ||||||||||||||||||
3503 | names, as defined in RFC3492. If you want to convert a domain name from | - | ||||||||||||||||||
3504 | Unicode to its ASCII-compatible representation, use toAce(). | - | ||||||||||||||||||
3505 | */ | - | ||||||||||||||||||
3506 | - | |||||||||||||||||||
3507 | /*! | - | ||||||||||||||||||
3508 | \fn QString QUrl::fromPunycode(const QByteArray &pc) | - | ||||||||||||||||||
3509 | \obsolete | - | ||||||||||||||||||
3510 | Returns the Punycode decoded representation of \a pc. | - | ||||||||||||||||||
3511 | - | |||||||||||||||||||
3512 | Punycode is a Unicode encoding used for internationalized domain | - | ||||||||||||||||||
3513 | names, as defined in RFC3492. If you want to convert a domain from | - | ||||||||||||||||||
3514 | its ASCII-compatible encoding to the Unicode representation, use | - | ||||||||||||||||||
3515 | fromAce(). | - | ||||||||||||||||||
3516 | */ | - | ||||||||||||||||||
3517 | - | |||||||||||||||||||
3518 | /*! | - | ||||||||||||||||||
3519 | \since 4.2 | - | ||||||||||||||||||
3520 | - | |||||||||||||||||||
3521 | Returns the Unicode form of the given domain name | - | ||||||||||||||||||
3522 | \a domain, which is encoded in the ASCII Compatible Encoding (ACE). | - | ||||||||||||||||||
3523 | The result of this function is considered equivalent to \a domain. | - | ||||||||||||||||||
3524 | - | |||||||||||||||||||
3525 | If the value in \a domain cannot be encoded, it will be converted | - | ||||||||||||||||||
3526 | to QString and returned. | - | ||||||||||||||||||
3527 | - | |||||||||||||||||||
3528 | The ASCII Compatible Encoding (ACE) is defined by RFC 3490, RFC 3491 | - | ||||||||||||||||||
3529 | and RFC 3492. It is part of the Internationalizing Domain Names in | - | ||||||||||||||||||
3530 | Applications (IDNA) specification, which allows for domain names | - | ||||||||||||||||||
3531 | (like \c "example.com") to be written using international | - | ||||||||||||||||||
3532 | characters. | - | ||||||||||||||||||
3533 | */ | - | ||||||||||||||||||
3534 | QString QUrl::fromAce(const QByteArray &domain) | - | ||||||||||||||||||
3535 | { | - | ||||||||||||||||||
3536 | return qt_ACE_do(QString::fromLatin1(domain), NormalizeAce, ForbidLeadingDot /*FIXME: make configurable*/); | - | ||||||||||||||||||
3537 | } | - | ||||||||||||||||||
3538 | - | |||||||||||||||||||
3539 | /*! | - | ||||||||||||||||||
3540 | \since 4.2 | - | ||||||||||||||||||
3541 | - | |||||||||||||||||||
3542 | Returns the ASCII Compatible Encoding of the given domain name \a domain. | - | ||||||||||||||||||
3543 | The result of this function is considered equivalent to \a domain. | - | ||||||||||||||||||
3544 | - | |||||||||||||||||||
3545 | The ASCII-Compatible Encoding (ACE) is defined by RFC 3490, RFC 3491 | - | ||||||||||||||||||
3546 | and RFC 3492. It is part of the Internationalizing Domain Names in | - | ||||||||||||||||||
3547 | Applications (IDNA) specification, which allows for domain names | - | ||||||||||||||||||
3548 | (like \c "example.com") to be written using international | - | ||||||||||||||||||
3549 | characters. | - | ||||||||||||||||||
3550 | - | |||||||||||||||||||
3551 | This function returns an empty QByteArray if \a domain is not a valid | - | ||||||||||||||||||
3552 | hostname. Note, in particular, that IPv6 literals are not valid domain | - | ||||||||||||||||||
3553 | names. | - | ||||||||||||||||||
3554 | */ | - | ||||||||||||||||||
3555 | QByteArray QUrl::toAce(const QString &domain) | - | ||||||||||||||||||
3556 | { | - | ||||||||||||||||||
3557 | QString result = qt_ACE_do(domain, ToAceOnly, ForbidLeadingDot /*FIXME: make configurable*/); | - | ||||||||||||||||||
3558 | return result.toLatin1(); | - | ||||||||||||||||||
3559 | } | - | ||||||||||||||||||
3560 | - | |||||||||||||||||||
3561 | /*! | - | ||||||||||||||||||
3562 | \internal | - | ||||||||||||||||||
3563 | - | |||||||||||||||||||
3564 | Returns \c true if this URL is "less than" the given \a url. This | - | ||||||||||||||||||
3565 | provides a means of ordering URLs. | - | ||||||||||||||||||
3566 | */ | - | ||||||||||||||||||
3567 | bool QUrl::operator <(const QUrl &url) const | - | ||||||||||||||||||
3568 | { | - | ||||||||||||||||||
3569 | if (!d || !url.d) { | - | ||||||||||||||||||
3570 | bool thisIsEmpty = !d || d->isEmpty(); | - | ||||||||||||||||||
3571 | bool thatIsEmpty = !url.d || url.d->isEmpty(); | - | ||||||||||||||||||
3572 | - | |||||||||||||||||||
3573 | // sort an empty URL first | - | ||||||||||||||||||
3574 | return thisIsEmpty && !thatIsEmpty; | - | ||||||||||||||||||
3575 | } | - | ||||||||||||||||||
3576 | - | |||||||||||||||||||
3577 | int cmp; | - | ||||||||||||||||||
3578 | cmp = d->scheme.compare(url.d->scheme); | - | ||||||||||||||||||
3579 | if (cmp != 0) | - | ||||||||||||||||||
3580 | return cmp < 0; | - | ||||||||||||||||||
3581 | - | |||||||||||||||||||
3582 | cmp = d->userName.compare(url.d->userName); | - | ||||||||||||||||||
3583 | if (cmp != 0) | - | ||||||||||||||||||
3584 | return cmp < 0; | - | ||||||||||||||||||
3585 | - | |||||||||||||||||||
3586 | cmp = d->password.compare(url.d->password); | - | ||||||||||||||||||
3587 | if (cmp != 0) | - | ||||||||||||||||||
3588 | return cmp < 0; | - | ||||||||||||||||||
3589 | - | |||||||||||||||||||
3590 | cmp = d->host.compare(url.d->host); | - | ||||||||||||||||||
3591 | if (cmp != 0) | - | ||||||||||||||||||
3592 | return cmp < 0; | - | ||||||||||||||||||
3593 | - | |||||||||||||||||||
3594 | if (d->port != url.d->port) | - | ||||||||||||||||||
3595 | return d->port < url.d->port; | - | ||||||||||||||||||
3596 | - | |||||||||||||||||||
3597 | cmp = d->path.compare(url.d->path); | - | ||||||||||||||||||
3598 | if (cmp != 0) | - | ||||||||||||||||||
3599 | return cmp < 0; | - | ||||||||||||||||||
3600 | - | |||||||||||||||||||
3601 | if (d->hasQuery() != url.d->hasQuery()) | - | ||||||||||||||||||
3602 | return url.d->hasQuery(); | - | ||||||||||||||||||
3603 | - | |||||||||||||||||||
3604 | cmp = d->query.compare(url.d->query); | - | ||||||||||||||||||
3605 | if (cmp != 0) | - | ||||||||||||||||||
3606 | return cmp < 0; | - | ||||||||||||||||||
3607 | - | |||||||||||||||||||
3608 | if (d->hasFragment() != url.d->hasFragment()) | - | ||||||||||||||||||
3609 | return url.d->hasFragment(); | - | ||||||||||||||||||
3610 | - | |||||||||||||||||||
3611 | cmp = d->fragment.compare(url.d->fragment); | - | ||||||||||||||||||
3612 | return cmp < 0; | - | ||||||||||||||||||
3613 | } | - | ||||||||||||||||||
3614 | - | |||||||||||||||||||
3615 | /*! | - | ||||||||||||||||||
3616 | Returns \c true if this URL and the given \a url are equal; | - | ||||||||||||||||||
3617 | otherwise returns \c false. | - | ||||||||||||||||||
3618 | */ | - | ||||||||||||||||||
3619 | bool QUrl::operator ==(const QUrl &url) const | - | ||||||||||||||||||
3620 | { | - | ||||||||||||||||||
3621 | if (!d && !url.d) | - | ||||||||||||||||||
3622 | return true; | - | ||||||||||||||||||
3623 | if (!d) | - | ||||||||||||||||||
3624 | return url.d->isEmpty(); | - | ||||||||||||||||||
3625 | if (!url.d) | - | ||||||||||||||||||
3626 | return d->isEmpty(); | - | ||||||||||||||||||
3627 | - | |||||||||||||||||||
3628 | // First, compare which sections are present, since it speeds up the | - | ||||||||||||||||||
3629 | // processing considerably. We just have to ignore the host-is-present flag | - | ||||||||||||||||||
3630 | // for local files (the "file" protocol), due to the requirements of the | - | ||||||||||||||||||
3631 | // XDG file URI specification. | - | ||||||||||||||||||
3632 | int mask = QUrlPrivate::FullUrl; | - | ||||||||||||||||||
3633 | if (isLocalFile()) | - | ||||||||||||||||||
3634 | mask &= ~QUrlPrivate::Host; | - | ||||||||||||||||||
3635 | return (d->sectionIsPresent & mask) == (url.d->sectionIsPresent & mask) && | - | ||||||||||||||||||
3636 | d->scheme == url.d->scheme && | - | ||||||||||||||||||
3637 | d->userName == url.d->userName && | - | ||||||||||||||||||
3638 | d->password == url.d->password && | - | ||||||||||||||||||
3639 | d->host == url.d->host && | - | ||||||||||||||||||
3640 | d->port == url.d->port && | - | ||||||||||||||||||
3641 | d->path == url.d->path && | - | ||||||||||||||||||
3642 | d->query == url.d->query && | - | ||||||||||||||||||
3643 | d->fragment == url.d->fragment; | - | ||||||||||||||||||
3644 | } | - | ||||||||||||||||||
3645 | - | |||||||||||||||||||
3646 | /*! | - | ||||||||||||||||||
3647 | \since 5.2 | - | ||||||||||||||||||
3648 | - | |||||||||||||||||||
3649 | Returns \c true if this URL and the given \a url are equal after | - | ||||||||||||||||||
3650 | applying \a options to both; otherwise returns \c false. | - | ||||||||||||||||||
3651 | - | |||||||||||||||||||
3652 | This is equivalent to calling adjusted(options) on both URLs | - | ||||||||||||||||||
3653 | and comparing the resulting urls, but faster. | - | ||||||||||||||||||
3654 | - | |||||||||||||||||||
3655 | */ | - | ||||||||||||||||||
3656 | bool QUrl::matches(const QUrl &url, FormattingOptions options) const | - | ||||||||||||||||||
3657 | { | - | ||||||||||||||||||
3658 | if (!d && !url.d) | - | ||||||||||||||||||
3659 | return true; | - | ||||||||||||||||||
3660 | if (!d) | - | ||||||||||||||||||
3661 | return url.d->isEmpty(); | - | ||||||||||||||||||
3662 | if (!url.d) | - | ||||||||||||||||||
3663 | return d->isEmpty(); | - | ||||||||||||||||||
3664 | - | |||||||||||||||||||
3665 | // First, compare which sections are present, since it speeds up the | - | ||||||||||||||||||
3666 | // processing considerably. We just have to ignore the host-is-present flag | - | ||||||||||||||||||
3667 | // for local files (the "file" protocol), due to the requirements of the | - | ||||||||||||||||||
3668 | // XDG file URI specification. | - | ||||||||||||||||||
3669 | int mask = QUrlPrivate::FullUrl; | - | ||||||||||||||||||
3670 | if (isLocalFile()) | - | ||||||||||||||||||
3671 | mask &= ~QUrlPrivate::Host; | - | ||||||||||||||||||
3672 | - | |||||||||||||||||||
3673 | if (options & QUrl::RemoveScheme) | - | ||||||||||||||||||
3674 | mask &= ~QUrlPrivate::Scheme; | - | ||||||||||||||||||
3675 | else if (d->scheme != url.d->scheme) | - | ||||||||||||||||||
3676 | return false; | - | ||||||||||||||||||
3677 | - | |||||||||||||||||||
3678 | if (options & QUrl::RemovePassword) | - | ||||||||||||||||||
3679 | mask &= ~QUrlPrivate::Password; | - | ||||||||||||||||||
3680 | else if (d->password != url.d->password) | - | ||||||||||||||||||
3681 | return false; | - | ||||||||||||||||||
3682 | - | |||||||||||||||||||
3683 | if (options & QUrl::RemoveUserInfo) | - | ||||||||||||||||||
3684 | mask &= ~QUrlPrivate::UserName; | - | ||||||||||||||||||
3685 | else if (d->userName != url.d->userName) | - | ||||||||||||||||||
3686 | return false; | - | ||||||||||||||||||
3687 | - | |||||||||||||||||||
3688 | if (options & QUrl::RemovePort) | - | ||||||||||||||||||
3689 | mask &= ~QUrlPrivate::Port; | - | ||||||||||||||||||
3690 | else if (d->port != url.d->port) | - | ||||||||||||||||||
3691 | return false; | - | ||||||||||||||||||
3692 | - | |||||||||||||||||||
3693 | if (options & QUrl::RemoveAuthority) | - | ||||||||||||||||||
3694 | mask &= ~QUrlPrivate::Host; | - | ||||||||||||||||||
3695 | else if (d->host != url.d->host) | - | ||||||||||||||||||
3696 | return false; | - | ||||||||||||||||||
3697 | - | |||||||||||||||||||
3698 | if (options & QUrl::RemoveQuery) | - | ||||||||||||||||||
3699 | mask &= ~QUrlPrivate::Query; | - | ||||||||||||||||||
3700 | else if (d->query != url.d->query) | - | ||||||||||||||||||
3701 | return false; | - | ||||||||||||||||||
3702 | - | |||||||||||||||||||
3703 | if (options & QUrl::RemoveFragment) | - | ||||||||||||||||||
3704 | mask &= ~QUrlPrivate::Fragment; | - | ||||||||||||||||||
3705 | else if (d->fragment != url.d->fragment) | - | ||||||||||||||||||
3706 | return false; | - | ||||||||||||||||||
3707 | - | |||||||||||||||||||
3708 | if ((d->sectionIsPresent & mask) != (url.d->sectionIsPresent & mask)) | - | ||||||||||||||||||
3709 | return false; | - | ||||||||||||||||||
3710 | - | |||||||||||||||||||
3711 | if (options & QUrl::RemovePath) | - | ||||||||||||||||||
3712 | return true; | - | ||||||||||||||||||
3713 | - | |||||||||||||||||||
3714 | // Compare paths, after applying path-related options | - | ||||||||||||||||||
3715 | QString path1; | - | ||||||||||||||||||
3716 | d->appendPath(path1, options, QUrlPrivate::Path); | - | ||||||||||||||||||
3717 | QString path2; | - | ||||||||||||||||||
3718 | url.d->appendPath(path2, options, QUrlPrivate::Path); | - | ||||||||||||||||||
3719 | return path1 == path2; | - | ||||||||||||||||||
3720 | } | - | ||||||||||||||||||
3721 | - | |||||||||||||||||||
3722 | /*! | - | ||||||||||||||||||
3723 | Returns \c true if this URL and the given \a url are not equal; | - | ||||||||||||||||||
3724 | otherwise returns \c false. | - | ||||||||||||||||||
3725 | */ | - | ||||||||||||||||||
3726 | bool QUrl::operator !=(const QUrl &url) const | - | ||||||||||||||||||
3727 | { | - | ||||||||||||||||||
3728 | return !(*this == url); | - | ||||||||||||||||||
3729 | } | - | ||||||||||||||||||
3730 | - | |||||||||||||||||||
3731 | /*! | - | ||||||||||||||||||
3732 | Assigns the specified \a url to this object. | - | ||||||||||||||||||
3733 | */ | - | ||||||||||||||||||
3734 | QUrl &QUrl::operator =(const QUrl &url) | - | ||||||||||||||||||
3735 | { | - | ||||||||||||||||||
3736 | if (!d) { | - | ||||||||||||||||||
3737 | if (url.d) { | - | ||||||||||||||||||
3738 | url.d->ref.ref(); | - | ||||||||||||||||||
3739 | d = url.d; | - | ||||||||||||||||||
3740 | } | - | ||||||||||||||||||
3741 | } else { | - | ||||||||||||||||||
3742 | if (url.d) | - | ||||||||||||||||||
3743 | qAtomicAssign(d, url.d); | - | ||||||||||||||||||
3744 | else | - | ||||||||||||||||||
3745 | clear(); | - | ||||||||||||||||||
3746 | } | - | ||||||||||||||||||
3747 | return *this; | - | ||||||||||||||||||
3748 | } | - | ||||||||||||||||||
3749 | - | |||||||||||||||||||
3750 | /*! | - | ||||||||||||||||||
3751 | Assigns the specified \a url to this object. | - | ||||||||||||||||||
3752 | */ | - | ||||||||||||||||||
3753 | QUrl &QUrl::operator =(const QString &url) | - | ||||||||||||||||||
3754 | { | - | ||||||||||||||||||
3755 | if (url.isEmpty()) { | - | ||||||||||||||||||
3756 | clear(); | - | ||||||||||||||||||
3757 | } else { | - | ||||||||||||||||||
3758 | detach(); | - | ||||||||||||||||||
3759 | d->parse(url, TolerantMode); | - | ||||||||||||||||||
3760 | } | - | ||||||||||||||||||
3761 | return *this; | - | ||||||||||||||||||
3762 | } | - | ||||||||||||||||||
3763 | - | |||||||||||||||||||
3764 | /*! | - | ||||||||||||||||||
3765 | \fn void QUrl::swap(QUrl &other) | - | ||||||||||||||||||
3766 | \since 4.8 | - | ||||||||||||||||||
3767 | - | |||||||||||||||||||
3768 | Swaps URL \a other with this URL. This operation is very | - | ||||||||||||||||||
3769 | fast and never fails. | - | ||||||||||||||||||
3770 | */ | - | ||||||||||||||||||
3771 | - | |||||||||||||||||||
3772 | /*! | - | ||||||||||||||||||
3773 | \internal | - | ||||||||||||||||||
3774 | - | |||||||||||||||||||
3775 | Forces a detach. | - | ||||||||||||||||||
3776 | */ | - | ||||||||||||||||||
3777 | void QUrl::detach() | - | ||||||||||||||||||
3778 | { | - | ||||||||||||||||||
3779 | if (!d) | - | ||||||||||||||||||
3780 | d = new QUrlPrivate; | - | ||||||||||||||||||
3781 | else | - | ||||||||||||||||||
3782 | qAtomicDetach(d); | - | ||||||||||||||||||
3783 | } | - | ||||||||||||||||||
3784 | - | |||||||||||||||||||
3785 | /*! | - | ||||||||||||||||||
3786 | \internal | - | ||||||||||||||||||
3787 | */ | - | ||||||||||||||||||
3788 | bool QUrl::isDetached() const | - | ||||||||||||||||||
3789 | { | - | ||||||||||||||||||
3790 | return !d || d->ref.load() == 1; | - | ||||||||||||||||||
3791 | } | - | ||||||||||||||||||
3792 | - | |||||||||||||||||||
3793 | - | |||||||||||||||||||
3794 | /*! | - | ||||||||||||||||||
3795 | Returns a QUrl representation of \a localFile, interpreted as a local | - | ||||||||||||||||||
3796 | file. This function accepts paths separated by slashes as well as the | - | ||||||||||||||||||
3797 | native separator for this platform. | - | ||||||||||||||||||
3798 | - | |||||||||||||||||||
3799 | This function also accepts paths with a doubled leading slash (or | - | ||||||||||||||||||
3800 | backslash) to indicate a remote file, as in | - | ||||||||||||||||||
3801 | "//servername/path/to/file.txt". Note that only certain platforms can | - | ||||||||||||||||||
3802 | actually open this file using QFile::open(). | - | ||||||||||||||||||
3803 | - | |||||||||||||||||||
3804 | An empty \a localFile leads to an empty URL (since Qt 5.4). | - | ||||||||||||||||||
3805 | - | |||||||||||||||||||
3806 | \sa toLocalFile(), isLocalFile(), QDir::toNativeSeparators() | - | ||||||||||||||||||
3807 | */ | - | ||||||||||||||||||
3808 | QUrl QUrl::fromLocalFile(const QString &localFile) | - | ||||||||||||||||||
3809 | { | - | ||||||||||||||||||
3810 | QUrl url; | - | ||||||||||||||||||
3811 | if (localFile.isEmpty()) | - | ||||||||||||||||||
3812 | return url; | - | ||||||||||||||||||
3813 | QString scheme = fileScheme(); | - | ||||||||||||||||||
3814 | QString deslashified = QDir::fromNativeSeparators(localFile); | - | ||||||||||||||||||
3815 | - | |||||||||||||||||||
3816 | // magic for drives on windows | - | ||||||||||||||||||
3817 | if (deslashified.length() > 1 && deslashified.at(1) == QLatin1Char(':') && deslashified.at(0) != QLatin1Char('/')) { | - | ||||||||||||||||||
3818 | deslashified.prepend(QLatin1Char('/')); | - | ||||||||||||||||||
3819 | } else if (deslashified.startsWith(QLatin1String("//"))) { | - | ||||||||||||||||||
3820 | // magic for shared drive on windows | - | ||||||||||||||||||
3821 | int indexOfPath = deslashified.indexOf(QLatin1Char('/'), 2); | - | ||||||||||||||||||
3822 | QString hostSpec = deslashified.mid(2, indexOfPath - 2); | - | ||||||||||||||||||
3823 | // Check for Windows-specific WebDAV specification: "//host@SSL/path". | - | ||||||||||||||||||
3824 | if (hostSpec.endsWith(webDavSslTag(), Qt::CaseInsensitive)) { | - | ||||||||||||||||||
3825 | hostSpec.chop(4); | - | ||||||||||||||||||
3826 | scheme = webDavScheme(); | - | ||||||||||||||||||
3827 | } | - | ||||||||||||||||||
3828 | url.setHost(hostSpec); | - | ||||||||||||||||||
3829 | - | |||||||||||||||||||
3830 | if (indexOfPath > 2) | - | ||||||||||||||||||
3831 | deslashified = deslashified.right(deslashified.length() - indexOfPath); | - | ||||||||||||||||||
3832 | else | - | ||||||||||||||||||
3833 | deslashified.clear(); | - | ||||||||||||||||||
3834 | } | - | ||||||||||||||||||
3835 | - | |||||||||||||||||||
3836 | url.setScheme(scheme); | - | ||||||||||||||||||
3837 | url.setPath(deslashified, DecodedMode); | - | ||||||||||||||||||
3838 | return url; | - | ||||||||||||||||||
3839 | } | - | ||||||||||||||||||
3840 | - | |||||||||||||||||||
3841 | /*! | - | ||||||||||||||||||
3842 | Returns the path of this URL formatted as a local file path. The path | - | ||||||||||||||||||
3843 | returned will use forward slashes, even if it was originally created | - | ||||||||||||||||||
3844 | from one with backslashes. | - | ||||||||||||||||||
3845 | - | |||||||||||||||||||
3846 | If this URL contains a non-empty hostname, it will be encoded in the | - | ||||||||||||||||||
3847 | returned value in the form found on SMB networks (for example, | - | ||||||||||||||||||
3848 | "//servername/path/to/file.txt"). | - | ||||||||||||||||||
3849 | - | |||||||||||||||||||
3850 | Note: if the path component of this URL contains a non-UTF-8 binary | - | ||||||||||||||||||
3851 | sequence (such as %80), the behaviour of this function is undefined. | - | ||||||||||||||||||
3852 | - | |||||||||||||||||||
3853 | \sa fromLocalFile(), isLocalFile() | - | ||||||||||||||||||
3854 | */ | - | ||||||||||||||||||
3855 | QString QUrl::toLocalFile() const | - | ||||||||||||||||||
3856 | { | - | ||||||||||||||||||
3857 | // the call to isLocalFile() also ensures that we're parsed | - | ||||||||||||||||||
3858 | if (!isLocalFile()) | - | ||||||||||||||||||
3859 | return QString(); | - | ||||||||||||||||||
3860 | - | |||||||||||||||||||
3861 | return d->toLocalFile(QUrl::FullyDecoded); | - | ||||||||||||||||||
3862 | } | - | ||||||||||||||||||
3863 | - | |||||||||||||||||||
3864 | /*! | - | ||||||||||||||||||
3865 | \since 4.8 | - | ||||||||||||||||||
3866 | Returns \c true if this URL is pointing to a local file path. A URL is a | - | ||||||||||||||||||
3867 | local file path if the scheme is "file". | - | ||||||||||||||||||
3868 | - | |||||||||||||||||||
3869 | Note that this function considers URLs with hostnames to be local file | - | ||||||||||||||||||
3870 | paths, even if the eventual file path cannot be opened with | - | ||||||||||||||||||
3871 | QFile::open(). | - | ||||||||||||||||||
3872 | - | |||||||||||||||||||
3873 | \sa fromLocalFile(), toLocalFile() | - | ||||||||||||||||||
3874 | */ | - | ||||||||||||||||||
3875 | bool QUrl::isLocalFile() const | - | ||||||||||||||||||
3876 | { | - | ||||||||||||||||||
3877 | return d && d->isLocalFile(); | - | ||||||||||||||||||
3878 | } | - | ||||||||||||||||||
3879 | - | |||||||||||||||||||
3880 | /*! | - | ||||||||||||||||||
3881 | Returns \c true if this URL is a parent of \a childUrl. \a childUrl is a child | - | ||||||||||||||||||
3882 | of this URL if the two URLs share the same scheme and authority, | - | ||||||||||||||||||
3883 | and this URL's path is a parent of the path of \a childUrl. | - | ||||||||||||||||||
3884 | */ | - | ||||||||||||||||||
3885 | bool QUrl::isParentOf(const QUrl &childUrl) const | - | ||||||||||||||||||
3886 | { | - | ||||||||||||||||||
3887 | QString childPath = childUrl.path(); | - | ||||||||||||||||||
3888 | - | |||||||||||||||||||
3889 | if (!d) | - | ||||||||||||||||||
3890 | return ((childUrl.scheme().isEmpty()) | - | ||||||||||||||||||
3891 | && (childUrl.authority().isEmpty()) | - | ||||||||||||||||||
3892 | && childPath.length() > 0 && childPath.at(0) == QLatin1Char('/')); | - | ||||||||||||||||||
3893 | - | |||||||||||||||||||
3894 | QString ourPath = path(); | - | ||||||||||||||||||
3895 | - | |||||||||||||||||||
3896 | return ((childUrl.scheme().isEmpty() || d->scheme == childUrl.scheme()) | - | ||||||||||||||||||
3897 | && (childUrl.authority().isEmpty() || authority() == childUrl.authority()) | - | ||||||||||||||||||
3898 | && childPath.startsWith(ourPath) | - | ||||||||||||||||||
3899 | && ((ourPath.endsWith(QLatin1Char('/')) && childPath.length() > ourPath.length()) | - | ||||||||||||||||||
3900 | || (!ourPath.endsWith(QLatin1Char('/')) | - | ||||||||||||||||||
3901 | && childPath.length() > ourPath.length() && childPath.at(ourPath.length()) == QLatin1Char('/')))); | - | ||||||||||||||||||
3902 | } | - | ||||||||||||||||||
3903 | - | |||||||||||||||||||
3904 | - | |||||||||||||||||||
3905 | #ifndef QT_NO_DATASTREAM | - | ||||||||||||||||||
3906 | /*! \relates QUrl | - | ||||||||||||||||||
3907 | - | |||||||||||||||||||
3908 | Writes url \a url to the stream \a out and returns a reference | - | ||||||||||||||||||
3909 | to the stream. | - | ||||||||||||||||||
3910 | - | |||||||||||||||||||
3911 | \sa{Serializing Qt Data Types}{Format of the QDataStream operators} | - | ||||||||||||||||||
3912 | */ | - | ||||||||||||||||||
3913 | QDataStream &operator<<(QDataStream &out, const QUrl &url) | - | ||||||||||||||||||
3914 | { | - | ||||||||||||||||||
3915 | QByteArray u; | - | ||||||||||||||||||
3916 | if (url.isValid()) | - | ||||||||||||||||||
3917 | u = url.toEncoded(); | - | ||||||||||||||||||
3918 | out << u; | - | ||||||||||||||||||
3919 | return out; | - | ||||||||||||||||||
3920 | } | - | ||||||||||||||||||
3921 | - | |||||||||||||||||||
3922 | /*! \relates QUrl | - | ||||||||||||||||||
3923 | - | |||||||||||||||||||
3924 | Reads a url into \a url from the stream \a in and returns a | - | ||||||||||||||||||
3925 | reference to the stream. | - | ||||||||||||||||||
3926 | - | |||||||||||||||||||
3927 | \sa{Serializing Qt Data Types}{Format of the QDataStream operators} | - | ||||||||||||||||||
3928 | */ | - | ||||||||||||||||||
3929 | QDataStream &operator>>(QDataStream &in, QUrl &url) | - | ||||||||||||||||||
3930 | { | - | ||||||||||||||||||
3931 | QByteArray u; | - | ||||||||||||||||||
3932 | in >> u; | - | ||||||||||||||||||
3933 | url.setUrl(QString::fromLatin1(u)); | - | ||||||||||||||||||
3934 | return in; | - | ||||||||||||||||||
3935 | } | - | ||||||||||||||||||
3936 | #endif // QT_NO_DATASTREAM | - | ||||||||||||||||||
3937 | - | |||||||||||||||||||
3938 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||||||||||||||
3939 | QDebug operator<<(QDebug d, const QUrl &url) | - | ||||||||||||||||||
3940 | { | - | ||||||||||||||||||
3941 | QDebugStateSaver saver(d); | - | ||||||||||||||||||
3942 | d.nospace() << "QUrl(" << url.toDisplayString() << ')'; | - | ||||||||||||||||||
3943 | return d; | - | ||||||||||||||||||
3944 | } | - | ||||||||||||||||||
3945 | #endif | - | ||||||||||||||||||
3946 | - | |||||||||||||||||||
3947 | static QString errorMessage(QUrlPrivate::ErrorCode errorCode, const QString &errorSource, int errorPosition) | - | ||||||||||||||||||
3948 | { | - | ||||||||||||||||||
3949 | QChar c = uint(errorPosition) < uint(errorSource.length()) ? | - | ||||||||||||||||||
3950 | errorSource.at(errorPosition) : QChar(QChar::Null); | - | ||||||||||||||||||
3951 | - | |||||||||||||||||||
3952 | switch (errorCode) { | - | ||||||||||||||||||
3953 | case QUrlPrivate::NoError: | - | ||||||||||||||||||
3954 | Q_ASSERT_X(false, "QUrl::errorString", | - | ||||||||||||||||||
3955 | "Impossible: QUrl::errorString should have treated this condition"); | - | ||||||||||||||||||
3956 | Q_UNREACHABLE(); | - | ||||||||||||||||||
3957 | return QString(); | - | ||||||||||||||||||
3958 | - | |||||||||||||||||||
3959 | case QUrlPrivate::InvalidSchemeError: { | - | ||||||||||||||||||
3960 | QString msg = QStringLiteral("Invalid scheme (character '%1' not permitted)"); | - | ||||||||||||||||||
3961 | return msg.arg(c); | - | ||||||||||||||||||
3962 | } | - | ||||||||||||||||||
3963 | - | |||||||||||||||||||
3964 | case QUrlPrivate::InvalidUserNameError: | - | ||||||||||||||||||
3965 | return QString(QStringLiteral("Invalid user name (character '%1' not permitted)")) | - | ||||||||||||||||||
3966 | .arg(c); | - | ||||||||||||||||||
3967 | - | |||||||||||||||||||
3968 | case QUrlPrivate::InvalidPasswordError: | - | ||||||||||||||||||
3969 | return QString(QStringLiteral("Invalid password (character '%1' not permitted)")) | - | ||||||||||||||||||
3970 | .arg(c); | - | ||||||||||||||||||
3971 | - | |||||||||||||||||||
3972 | case QUrlPrivate::InvalidRegNameError: | - | ||||||||||||||||||
3973 | if (errorPosition != -1) | - | ||||||||||||||||||
3974 | return QString(QStringLiteral("Invalid hostname (character '%1' not permitted)")) | - | ||||||||||||||||||
3975 | .arg(c); | - | ||||||||||||||||||
3976 | else | - | ||||||||||||||||||
3977 | return QStringLiteral("Invalid hostname (contains invalid characters)"); | - | ||||||||||||||||||
3978 | case QUrlPrivate::InvalidIPv4AddressError: | - | ||||||||||||||||||
3979 | return QString(); // doesn't happen yet | - | ||||||||||||||||||
3980 | case QUrlPrivate::InvalidIPv6AddressError: | - | ||||||||||||||||||
3981 | return QStringLiteral("Invalid IPv6 address"); | - | ||||||||||||||||||
3982 | case QUrlPrivate::InvalidCharacterInIPv6Error: | - | ||||||||||||||||||
3983 | return QStringLiteral("Invalid IPv6 address (character '%1' not permitted)").arg(c); | - | ||||||||||||||||||
3984 | case QUrlPrivate::InvalidIPvFutureError: | - | ||||||||||||||||||
3985 | return QStringLiteral("Invalid IPvFuture address (character '%1' not permitted)").arg(c); | - | ||||||||||||||||||
3986 | case QUrlPrivate::HostMissingEndBracket: | - | ||||||||||||||||||
3987 | return QStringLiteral("Expected ']' to match '[' in hostname"); | - | ||||||||||||||||||
3988 | - | |||||||||||||||||||
3989 | case QUrlPrivate::InvalidPortError: | - | ||||||||||||||||||
3990 | return QStringLiteral("Invalid port or port number out of range"); | - | ||||||||||||||||||
3991 | case QUrlPrivate::PortEmptyError: | - | ||||||||||||||||||
3992 | return QStringLiteral("Port field was empty"); | - | ||||||||||||||||||
3993 | - | |||||||||||||||||||
3994 | case QUrlPrivate::InvalidPathError: | - | ||||||||||||||||||
3995 | return QString(QStringLiteral("Invalid path (character '%1' not permitted)")) | - | ||||||||||||||||||
3996 | .arg(c); | - | ||||||||||||||||||
3997 | - | |||||||||||||||||||
3998 | case QUrlPrivate::InvalidQueryError: | - | ||||||||||||||||||
3999 | return QString(QStringLiteral("Invalid query (character '%1' not permitted)")) | - | ||||||||||||||||||
4000 | .arg(c); | - | ||||||||||||||||||
4001 | - | |||||||||||||||||||
4002 | case QUrlPrivate::InvalidFragmentError: | - | ||||||||||||||||||
4003 | return QString(QStringLiteral("Invalid fragment (character '%1' not permitted)")) | - | ||||||||||||||||||
4004 | .arg(c); | - | ||||||||||||||||||
4005 | - | |||||||||||||||||||
4006 | case QUrlPrivate::AuthorityPresentAndPathIsRelative: | - | ||||||||||||||||||
4007 | return QStringLiteral("Path component is relative and authority is present"); | - | ||||||||||||||||||
4008 | case QUrlPrivate::RelativeUrlPathContainsColonBeforeSlash: | - | ||||||||||||||||||
4009 | return QStringLiteral("Relative URL's path component contains ':' before any '/'"); | - | ||||||||||||||||||
4010 | } | - | ||||||||||||||||||
4011 | - | |||||||||||||||||||
4012 | Q_ASSERT_X(false, "QUrl::errorString", "Cannot happen, unknown error"); | - | ||||||||||||||||||
4013 | Q_UNREACHABLE(); | - | ||||||||||||||||||
4014 | return QString(); | - | ||||||||||||||||||
4015 | } | - | ||||||||||||||||||
4016 | - | |||||||||||||||||||
4017 | static inline void appendComponentIfPresent(QString &msg, bool present, const char *componentName, | - | ||||||||||||||||||
4018 | const QString &component) | - | ||||||||||||||||||
4019 | { | - | ||||||||||||||||||
4020 | if (present) { | - | ||||||||||||||||||
4021 | msg += QLatin1String(componentName); | - | ||||||||||||||||||
4022 | msg += QLatin1Char('"'); | - | ||||||||||||||||||
4023 | msg += component; | - | ||||||||||||||||||
4024 | msg += QLatin1String("\","); | - | ||||||||||||||||||
4025 | } | - | ||||||||||||||||||
4026 | } | - | ||||||||||||||||||
4027 | - | |||||||||||||||||||
4028 | /*! | - | ||||||||||||||||||
4029 | \since 4.2 | - | ||||||||||||||||||
4030 | - | |||||||||||||||||||
4031 | Returns an error message if the last operation that modified this QUrl | - | ||||||||||||||||||
4032 | object ran into a parsing error. If no error was detected, this function | - | ||||||||||||||||||
4033 | returns an empty string and isValid() returns \c true. | - | ||||||||||||||||||
4034 | - | |||||||||||||||||||
4035 | The error message returned by this function is technical in nature and may | - | ||||||||||||||||||
4036 | not be understood by end users. It is mostly useful to developers trying to | - | ||||||||||||||||||
4037 | understand why QUrl will not accept some input. | - | ||||||||||||||||||
4038 | - | |||||||||||||||||||
4039 | \sa QUrl::ParsingMode | - | ||||||||||||||||||
4040 | */ | - | ||||||||||||||||||
4041 | QString QUrl::errorString() const | - | ||||||||||||||||||
4042 | { | - | ||||||||||||||||||
4043 | QString msg; | - | ||||||||||||||||||
4044 | if (!d)
| 130-213 | ||||||||||||||||||
4045 | return QString();msg; executed 130 times by 6 tests: return msg; Executed by:
| 130 | ||||||||||||||||||
4046 | - | |||||||||||||||||||
4047 | QString errorSource; | - | ||||||||||||||||||
4048 | int errorPosition = 0; | - | ||||||||||||||||||
4049 | QUrlPrivate::ErrorCode errorCode = d->validityError(&errorSource, &errorPosition); | - | ||||||||||||||||||
4050 | if (errorCode == QUrlPrivate::NoError)
| 11-202 | ||||||||||||||||||
4051 | return QString();msg; executed 11 times by 2 tests: return msg; Executed by:
| 11 | ||||||||||||||||||
4052 | - | |||||||||||||||||||
4053 | QString msg =+= errorMessage(errorCode, errorSource, errorPosition); | - | ||||||||||||||||||
4054 | msg += QLatin1String("; source was \""); | - | ||||||||||||||||||
4055 | msg += errorSource; | - | ||||||||||||||||||
4056 | msg += QLatin1String("\";"); | - | ||||||||||||||||||
4057 | appendComponentIfPresent(msg, d->sectionIsPresent & QUrlPrivate::Scheme, | - | ||||||||||||||||||
4058 | " scheme = ", d->scheme); | - | ||||||||||||||||||
4059 | appendComponentIfPresent(msg, d->sectionIsPresent & QUrlPrivate::UserInfo, | - | ||||||||||||||||||
4060 | " userinfo = ", userInfo()); | - | ||||||||||||||||||
4061 | appendComponentIfPresent(msg, d->sectionIsPresent & QUrlPrivate::Host, | - | ||||||||||||||||||
4062 | " host = ", d->host); | - | ||||||||||||||||||
4063 | appendComponentIfPresent(msg, d->port != -1, | - | ||||||||||||||||||
4064 | " port = ", QString::number(d->port)); | - | ||||||||||||||||||
4065 | appendComponentIfPresent(msg, !d->path.isEmpty(), | - | ||||||||||||||||||
4066 | " path = ", d->path); | - | ||||||||||||||||||
4067 | appendComponentIfPresent(msg, d->sectionIsPresent & QUrlPrivate::Query, | - | ||||||||||||||||||
4068 | " query = ", d->query); | - | ||||||||||||||||||
4069 | appendComponentIfPresent(msg, d->sectionIsPresent & QUrlPrivate::Fragment, | - | ||||||||||||||||||
4070 | " fragment = ", d->fragment); | - | ||||||||||||||||||
4071 | if (msg.endsWith(QLatin1Char(',')))
| 1-201 | ||||||||||||||||||
4072 | msg.chop(1); executed 201 times by 1 test: msg.chop(1); Executed by:
| 201 | ||||||||||||||||||
4073 | return msg; executed 202 times by 1 test: return msg; Executed by:
| 202 | ||||||||||||||||||
4074 | } | - | ||||||||||||||||||
4075 | - | |||||||||||||||||||
4076 | /*! | - | ||||||||||||||||||
4077 | \since 5.1 | - | ||||||||||||||||||
4078 | - | |||||||||||||||||||
4079 | Converts a list of \a urls into a list of QString objects, using toString(\a options). | - | ||||||||||||||||||
4080 | */ | - | ||||||||||||||||||
4081 | QStringList QUrl::toStringList(const QList<QUrl> &urls, FormattingOptions options) | - | ||||||||||||||||||
4082 | { | - | ||||||||||||||||||
4083 | QStringList lst; | - | ||||||||||||||||||
4084 | lst.reserve(urls.size()); | - | ||||||||||||||||||
4085 | foreachfor (const QUrl &url, : urls) | - | ||||||||||||||||||
4086 | lst.append(url.toString(options)); executed 465 times by 5 tests: lst.append(url.toString(options)); Executed by:
| 465 | ||||||||||||||||||
4087 | return lst; executed 235 times by 5 tests: return lst; Executed by:
| 235 | ||||||||||||||||||
4088 | - | |||||||||||||||||||
4089 | } | - | ||||||||||||||||||
4090 | - | |||||||||||||||||||
4091 | /*! | - | ||||||||||||||||||
4092 | \since 5.1 | - | ||||||||||||||||||
4093 | - | |||||||||||||||||||
4094 | Converts a list of strings representing \a urls into a list of urls, using QUrl(str, \a mode). | - | ||||||||||||||||||
4095 | Note that this means all strings must be urls, not for instance local paths. | - | ||||||||||||||||||
4096 | */ | - | ||||||||||||||||||
4097 | QList<QUrl> QUrl::fromStringList(const QStringList &urls, ParsingMode mode) | - | ||||||||||||||||||
4098 | { | - | ||||||||||||||||||
4099 | QList<QUrl> lst; | - | ||||||||||||||||||
4100 | lst.reserve(urls.size()); | - | ||||||||||||||||||
4101 | foreachfor (const QString &str, : urls) { | - | ||||||||||||||||||
4102 | lst.append(QUrl(str, mode)); executed 507 times by 5 tests: lst.append(QUrl(str, mode)); Executed by:
| 507 | ||||||||||||||||||
} executed 507 times by 5 tests: lst.append(QUrl(str, mode)); Executed by:
| ||||||||||||||||||||
4103 | return lst; executed 255 times by 5 tests: return lst; Executed by:
| 255 | ||||||||||||||||||
4104 | } | - | ||||||||||||||||||
4105 | - | |||||||||||||||||||
4106 | /*! | - | ||||||||||||||||||
4107 | \typedef QUrl::DataPtr | - | ||||||||||||||||||
4108 | \internal | - | ||||||||||||||||||
4109 | */ | - | ||||||||||||||||||
4110 | - | |||||||||||||||||||
4111 | /*! | - | ||||||||||||||||||
4112 | \fn DataPtr &QUrl::data_ptr() | - | ||||||||||||||||||
4113 | \internal | - | ||||||||||||||||||
4114 | */ | - | ||||||||||||||||||
4115 | - | |||||||||||||||||||
4116 | /*! | - | ||||||||||||||||||
4117 | Returns the hash value for the \a url. If specified, \a seed is used to | - | ||||||||||||||||||
4118 | initialize the hash. | - | ||||||||||||||||||
4119 | - | |||||||||||||||||||
4120 | \relates QHash | - | ||||||||||||||||||
4121 | \since 5.0 | - | ||||||||||||||||||
4122 | */ | - | ||||||||||||||||||
4123 | uint qHash(const QUrl &url, uint seed) Q_DECL_NOTHROW | - | ||||||||||||||||||
4124 | { | - | ||||||||||||||||||
4125 | if (!url.d)
| 3-7 | ||||||||||||||||||
4126 | return qHash(-1, seed); // the hash of an unset port (-1) executed 3 times by 1 test: return qHash(-1, seed); Executed by:
| 3 | ||||||||||||||||||
4127 | - | |||||||||||||||||||
4128 | 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 | ||||||||||||||||||
4129 | 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 | ||||||||||||||||||
4130 | 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 | ||||||||||||||||||
4131 | 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 | ||||||||||||||||||
4132 | 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 | ||||||||||||||||||
4133 | 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 | ||||||||||||||||||
4134 | 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 | ||||||||||||||||||
4135 | 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 | ||||||||||||||||||
4136 | } | - | ||||||||||||||||||
4137 | - | |||||||||||||||||||
4138 | static QUrl adjustFtpPath(QUrl url) | - | ||||||||||||||||||
4139 | { | - | ||||||||||||||||||
4140 | if (url.scheme() == ftpScheme()) { | - | ||||||||||||||||||
4141 | QString path = url.path(QUrl::PrettyDecoded); | - | ||||||||||||||||||
4142 | if (path.startsWith(QLatin1String("//"))) | - | ||||||||||||||||||
4143 | url.setPath(QLatin1String("/%2F") + path.midRef(2), QUrl::TolerantMode); | - | ||||||||||||||||||
4144 | } | - | ||||||||||||||||||
4145 | return url; | - | ||||||||||||||||||
4146 | } | - | ||||||||||||||||||
4147 | - | |||||||||||||||||||
4148 | static bool isIp6(const QString &text) | - | ||||||||||||||||||
4149 | { | - | ||||||||||||||||||
4150 | QIPAddressUtils::IPv6Address address; | - | ||||||||||||||||||
4151 | return !text.isEmpty() && QIPAddressUtils::parseIp6(address, text.begin(), text.end()) == 0; | - | ||||||||||||||||||
4152 | } | - | ||||||||||||||||||
4153 | - | |||||||||||||||||||
4154 | // The following code has the following copyright: | - | ||||||||||||||||||
4155 | /* | - | ||||||||||||||||||
4156 | Copyright (C) Research In Motion Limited 2009. All rights reserved. | - | ||||||||||||||||||
4157 | - | |||||||||||||||||||
4158 | Redistribution and use in source and binary forms, with or without | - | ||||||||||||||||||
4159 | modification, are permitted provided that the following conditions are met: | - | ||||||||||||||||||
4160 | * Redistributions of source code must retain the above copyright | - | ||||||||||||||||||
4161 | notice, this list of conditions and the following disclaimer. | - | ||||||||||||||||||
4162 | * Redistributions in binary form must reproduce the above copyright | - | ||||||||||||||||||
4163 | notice, this list of conditions and the following disclaimer in the | - | ||||||||||||||||||
4164 | documentation and/or other materials provided with the distribution. | - | ||||||||||||||||||
4165 | * Neither the name of Research In Motion Limited nor the | - | ||||||||||||||||||
4166 | contributors may be used to endorse or promote products derived | - | ||||||||||||||||||
4167 | derived from this software without specific prior written permission. | - | ||||||||||||||||||
4168 | - | |||||||||||||||||||
4169 | THIS SOFTWARE IS PROVIDED BY Research In Motion Limited ''AS IS'' AND ANY | - | ||||||||||||||||||
4170 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | - | ||||||||||||||||||
4171 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | - | ||||||||||||||||||
4172 | DISCLAIMED. IN NO EVENT SHALL Research In Motion Limited BE LIABLE FOR ANY | - | ||||||||||||||||||
4173 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | - | ||||||||||||||||||
4174 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | - | ||||||||||||||||||
4175 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | - | ||||||||||||||||||
4176 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | - | ||||||||||||||||||
4177 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | - | ||||||||||||||||||
4178 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | - | ||||||||||||||||||
4179 | - | |||||||||||||||||||
4180 | */ | - | ||||||||||||||||||
4181 | - | |||||||||||||||||||
4182 | - | |||||||||||||||||||
4183 | /*! | - | ||||||||||||||||||
4184 | Returns a valid URL from a user supplied \a userInput string if one can be | - | ||||||||||||||||||
4185 | deducted. In the case that is not possible, an invalid QUrl() is returned. | - | ||||||||||||||||||
4186 | - | |||||||||||||||||||
4187 | This overload takes a \a workingDirectory path, in order to be able to | - | ||||||||||||||||||
4188 | handle relative paths. This is especially useful when handling command | - | ||||||||||||||||||
4189 | line arguments. | - | ||||||||||||||||||
4190 | If \a workingDirectory is empty, no handling of relative paths will be done, | - | ||||||||||||||||||
4191 | so this method will behave like its one argument overload. | - | ||||||||||||||||||
4192 | - | |||||||||||||||||||
4193 | By default, an input string that looks like a relative path will only be treated | - | ||||||||||||||||||
4194 | as such if the file actually exists in the given working directory. | - | ||||||||||||||||||
4195 | - | |||||||||||||||||||
4196 | If the application can handle files that don't exist yet, it should pass the | - | ||||||||||||||||||
4197 | flag AssumeLocalFile in \a options. | - | ||||||||||||||||||
4198 | - | |||||||||||||||||||
4199 | \since 5.4 | - | ||||||||||||||||||
4200 | */ | - | ||||||||||||||||||
4201 | QUrl QUrl::fromUserInput(const QString &userInput, const QString &workingDirectory, | - | ||||||||||||||||||
4202 | UserInputResolutionOptions options) | - | ||||||||||||||||||
4203 | { | - | ||||||||||||||||||
4204 | QString trimmedString = userInput.trimmed(); | - | ||||||||||||||||||
4205 | - | |||||||||||||||||||
4206 | if (trimmedString.isEmpty()) | - | ||||||||||||||||||
4207 | return QUrl(); | - | ||||||||||||||||||
4208 | - | |||||||||||||||||||
4209 | - | |||||||||||||||||||
4210 | // Check for IPv6 addresses, since a path starting with ":" is absolute (a resource) | - | ||||||||||||||||||
4211 | // and IPv6 addresses can start with "c:" too | - | ||||||||||||||||||
4212 | if (isIp6(trimmedString)) { | - | ||||||||||||||||||
4213 | QUrl url; | - | ||||||||||||||||||
4214 | url.setHost(trimmedString); | - | ||||||||||||||||||
4215 | url.setScheme(QStringLiteral("http")); | - | ||||||||||||||||||
4216 | return url; | - | ||||||||||||||||||
4217 | } | - | ||||||||||||||||||
4218 | - | |||||||||||||||||||
4219 | QUrl url = QUrl(trimmedString, QUrl::TolerantMode); | - | ||||||||||||||||||
4220 | // Check both QUrl::isRelative (to detect full URLs) and QDir::isAbsolutePath (since on Windows drive letters can be interpreted as schemes) | - | ||||||||||||||||||
4221 | if (url.isRelative() && !QDir::isAbsolutePath(trimmedString)) { | - | ||||||||||||||||||
4222 | QFileInfo fileInfo(QDir(workingDirectory), trimmedString); | - | ||||||||||||||||||
4223 | if ((options & AssumeLocalFile) || fileInfo.exists()) | - | ||||||||||||||||||
4224 | return QUrl::fromLocalFile(fileInfo.absoluteFilePath()); | - | ||||||||||||||||||
4225 | } | - | ||||||||||||||||||
4226 | - | |||||||||||||||||||
4227 | return fromUserInput(trimmedString); | - | ||||||||||||||||||
4228 | } | - | ||||||||||||||||||
4229 | - | |||||||||||||||||||
4230 | /*! | - | ||||||||||||||||||
4231 | Returns a valid URL from a user supplied \a userInput string if one can be | - | ||||||||||||||||||
4232 | deducted. In the case that is not possible, an invalid QUrl() is returned. | - | ||||||||||||||||||
4233 | - | |||||||||||||||||||
4234 | \since 4.6 | - | ||||||||||||||||||
4235 | - | |||||||||||||||||||
4236 | Most applications that can browse the web, allow the user to input a URL | - | ||||||||||||||||||
4237 | in the form of a plain string. This string can be manually typed into | - | ||||||||||||||||||
4238 | a location bar, obtained from the clipboard, or passed in via command | - | ||||||||||||||||||
4239 | line arguments. | - | ||||||||||||||||||
4240 | - | |||||||||||||||||||
4241 | When the string is not already a valid URL, a best guess is performed, | - | ||||||||||||||||||
4242 | making various web related assumptions. | - | ||||||||||||||||||
4243 | - | |||||||||||||||||||
4244 | In the case the string corresponds to a valid file path on the system, | - | ||||||||||||||||||
4245 | a file:// URL is constructed, using QUrl::fromLocalFile(). | - | ||||||||||||||||||
4246 | - | |||||||||||||||||||
4247 | If that is not the case, an attempt is made to turn the string into a | - | ||||||||||||||||||
4248 | http:// or ftp:// URL. The latter in the case the string starts with | - | ||||||||||||||||||
4249 | 'ftp'. The result is then passed through QUrl's tolerant parser, and | - | ||||||||||||||||||
4250 | in the case or success, a valid QUrl is returned, or else a QUrl(). | - | ||||||||||||||||||
4251 | - | |||||||||||||||||||
4252 | \section1 Examples: | - | ||||||||||||||||||
4253 | - | |||||||||||||||||||
4254 | \list | - | ||||||||||||||||||
4255 | \li qt-project.org becomes http://qt-project.org | - | ||||||||||||||||||
4256 | \li ftp.qt-project.org becomes ftp://ftp.qt-project.org | - | ||||||||||||||||||
4257 | \li hostname becomes http://hostname | - | ||||||||||||||||||
4258 | \li /home/user/test.html becomes file:///home/user/test.html | - | ||||||||||||||||||
4259 | \endlist | - | ||||||||||||||||||
4260 | */ | - | ||||||||||||||||||
4261 | QUrl QUrl::fromUserInput(const QString &userInput) | - | ||||||||||||||||||
4262 | { | - | ||||||||||||||||||
4263 | QString trimmedString = userInput.trimmed(); | - | ||||||||||||||||||
4264 | - | |||||||||||||||||||
4265 | // Check for IPv6 addresses, since a path starting with ":" is absolute (a resource) | - | ||||||||||||||||||
4266 | // and IPv6 addresses can start with "c:" too | - | ||||||||||||||||||
4267 | if (isIp6(trimmedString)) {
| 6-54 | ||||||||||||||||||
4268 | QUrl url; | - | ||||||||||||||||||
4269 | url.setHost(trimmedString); | - | ||||||||||||||||||
4270 | url.setScheme(QStringLiteral("http")); | - | ||||||||||||||||||
4271 | return url; executed 6 times by 1 test: return url; Executed by:
| 6 | ||||||||||||||||||
4272 | } | - | ||||||||||||||||||
4273 | - | |||||||||||||||||||
4274 | // Check first for files, since on Windows drive letters can be interpretted as schemes | - | ||||||||||||||||||
4275 | if (QDir::isAbsolutePath(trimmedString))
| 19-35 | ||||||||||||||||||
4276 | return QUrl::fromLocalFile(trimmedString); executed 19 times by 1 test: return QUrl::fromLocalFile(trimmedString); Executed by:
| 19 | ||||||||||||||||||
4277 | - | |||||||||||||||||||
4278 | QUrl url = QUrl(trimmedString, QUrl::TolerantMode); | - | ||||||||||||||||||
4279 | QUrl urlPrepended = QUrl(QStringLiteralQLatin1String("http://") + trimmedString, QUrl::TolerantMode); | - | ||||||||||||||||||
4280 | - | |||||||||||||||||||
4281 | // Check the most common case of a valid url with a scheme | - | ||||||||||||||||||
4282 | // We check if the port would be valid by adding the scheme to handle the case host:port | - | ||||||||||||||||||
4283 | // where the host would be interpretted as the scheme | - | ||||||||||||||||||
4284 | if (url.isValid()
| 1-34 | ||||||||||||||||||
4285 | && !url.scheme().isEmpty()
| 16-18 | ||||||||||||||||||
4286 | && urlPrepended.port() == -1)
| 3-15 | ||||||||||||||||||
4287 | return adjustFtpPath(url); executed 15 times by 2 tests: return adjustFtpPath(url); Executed by:
| 15 | ||||||||||||||||||
4288 | - | |||||||||||||||||||
4289 | // Else, try the prepended one and adjust the scheme from the host name | - | ||||||||||||||||||
4290 | if (urlPrepended.isValid() && (!urlPrepended.host().isEmpty() || !urlPrepended.path().isEmpty()))
| 0-20 | ||||||||||||||||||
4291 | { | - | ||||||||||||||||||
4292 | int dotIndex = trimmedString.indexOf(QLatin1Char('.')); | - | ||||||||||||||||||
4293 | const QString hostscheme = trimmedString.left(dotIndex).toLower(); | - | ||||||||||||||||||
4294 | if (hostscheme == ftpScheme())
| 2-17 | ||||||||||||||||||
4295 | urlPrepended.setScheme(ftpScheme()); executed 2 times by 1 test: urlPrepended.setScheme(ftpScheme()); Executed by:
| 2 | ||||||||||||||||||
4296 | return adjustFtpPath(urlPrepended); executed 19 times by 1 test: return adjustFtpPath(urlPrepended); Executed by:
| 19 | ||||||||||||||||||
4297 | } | - | ||||||||||||||||||
4298 | - | |||||||||||||||||||
4299 | return QUrl(); executed 1 time by 1 test: return QUrl(); Executed by:
| 1 | ||||||||||||||||||
4300 | } | - | ||||||||||||||||||
4301 | // end of BSD code | - | ||||||||||||||||||
4302 | - | |||||||||||||||||||
4303 | QT_END_NAMESPACE | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |