Artifactspublic-v0

curl

master
ply4 git calls32 ms304 KiB3 cachedprotocol v2
2681 lines91 KiBRaw
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
25/*
26 * Note:
27 *
28 * Since the URL parser by default only accepts schemes that *this instance*
29 * of libcurl supports, make sure that the test1560 file lists all the schemes
30 * that this test assumes to be present!
31 */
33#include "first.h"
34#if defined(USE_LIBIDN2) || defined(USE_WIN32_IDN) || defined(USE_APPLE_IDN)
35#define USE_IDN
36#endif
38static int checkparts(CURLU *u, const char *in, const char *wanted,
39 unsigned int getflags)
41 int i;
42 CURLUcode rc;
43 char buf[256];
44 char *bufp = &buf[0];
45 size_t len = sizeof(buf);
47 struct part {
48 CURLUPart part;
49 const char *name;
50 };
52 struct part parts[] = {
53 { CURLUPART_SCHEME, "scheme" },
54 { CURLUPART_USER, "user" },
55 { CURLUPART_PASSWORD, "password" },
56 { CURLUPART_OPTIONS, "options" },
57 { CURLUPART_HOST, "host" },
58 { CURLUPART_PORT, "port" },
59 { CURLUPART_PATH, "path" },
60 { CURLUPART_QUERY, "query" },
61 { CURLUPART_FRAGMENT, "fragment" },
62 { CURLUPART_URL, NULL }
63 };
64 memset(buf, 0, sizeof(buf));
66 for(i = 0; parts[i].name; i++) {
67 char *p = NULL;
68 char *z = NULL;
69 size_t n;
70 rc = curl_url_get(u, parts[i].part, &p, getflags);
71 if(!rc && p) {
72 if((parts[i].part == CURLUPART_HOST) && (p[0] == '['))
73 /* an IPv6 numerical address host, get the zone */
74 (void)curl_url_get(u, CURLUPART_ZONEID, &z, getflags);
75 curl_msnprintf(bufp, len, "%s%s%s%s", buf[0] ? " | " : "", p,
76 z ? " " : "", z ? z : "");
77 }
78 else
79 curl_msnprintf(bufp, len, "%s[%d]", buf[0] ? " | " : "", (int)rc);
81 n = strlen(bufp);
82 bufp += n;
83 len -= n;
84 curl_free(p);
85 curl_free(z);
86 }
87 if(strcmp(buf, wanted)) {
88 curl_mfprintf(stderr, "in: %s\nwanted: %s\ngot: %s\n", in, wanted, buf);
89 return 1;
90 }
91 return 0;
94struct redircase {
95 const char *in;
96 const char *set;
97 const char *out;
98 unsigned int urlflags;
99 unsigned int setflags;
100 CURLUcode ucode;
101};
103struct setcase {
104 const char *in;
105 const char *set;
106 const char *out;
107 unsigned int urlflags;
108 unsigned int setflags;
109 CURLUcode ucode; /* for the main URL set */
110 CURLUcode pcode; /* for updating parts */
111};
113struct setgetcase {
114 const char *in;
115 const char *set;
116 const char *out;
117 unsigned int urlflags; /* for setting the URL */
118 unsigned int setflags; /* for updating parts */
119 unsigned int getflags; /* for getting parts */
120 CURLUcode pcode; /* for updating parts */
121};
123struct testcase {
124 const char *in;
125 const char *out;
126 unsigned int urlflags;
127 unsigned int getflags;
128 CURLUcode ucode;
129};
131struct urltestcase {
132 const char *in;
133 const char *out;
134 unsigned int urlflags; /* pass to curl_url() */
135 unsigned int getflags; /* pass to curl_url_get() */
136 CURLUcode ucode;
137};
139struct querycase {
140 const char *in;
141 const char *q;
142 const char *out;
143 unsigned int urlflags; /* pass to curl_url() */
144 unsigned int qflags; /* pass to curl_url_get() */
145 CURLUcode ucode;
146};
148struct clearurlcase {
149 CURLUPart part;
150 const char *in;
151 const char *out;
152 CURLUcode ucode;
153};
155static const struct testcase get_parts_list[] = {
156 { "https://@example.com",
157 "https | | [12] | [13] | example.com | [15] | / | [16] | [17]",
158 0, CURLU_URLENCODE, CURLUE_OK },
159 { "https://@example.com",
160 "https | | [12] | [13] | example.com | [15] | / | [16] | [17]",
161 0, 0, CURLUE_OK },
162 /* backslash mistakes */
163 {"http:\\\\hostname", "",
164 CURLU_GUESS_SCHEME, 0, CURLUE_BACKSLASH },
165 {"http:\\\\hostname:1234", "",
166 CURLU_GUESS_SCHEME, 0, CURLUE_BACKSLASH },
167 {"http://hostname:1111\\path", "",
168 0, 0, CURLUE_BACKSLASH },
170 /* non-supported URL without hostname */
171 {"weird:///path",
172 "weird | [11] | [12] | [13] | | [15] | /path | [16] | [17]",
173 CURLU_NON_SUPPORT_SCHEME|CURLU_NO_AUTHORITY, 0, CURLUE_OK},
174 /* non-supported URL without hostname, using path with multiple leading
175 slashes */
176 {"weird:////path",
177 "weird | [11] | [12] | [13] | | [15] | //path | [16] | [17]",
178 CURLU_NON_SUPPORT_SCHEME|CURLU_NO_AUTHORITY, 0, CURLUE_OK},
180 /* RFC 4291 IPv4-Mapped IPv6 Addresses */
181 {"https://[0:0:0:0:0:FFFF:129.144.52.38]:1234",
182 "https | [11] | [12] | [13] | [::ffff:129.144.52.38] | 1234 "
183 "| / | [16] | [17]", CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
184 {"https://[::FFFF:127.0.0.1]:1234",
185 "https | [11] | [12] | [13] | [::ffff:127.0.0.1] | 1234 "
186 "| / | [16] | [17]", CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
187 {"https://[::13.1.68.3]:1234",
188 "https | [11] | [12] | [13] | [::13.1.68.3] | 1234 "
189 "| / | [16] | [17]", CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
190 {"https://[0:0:0:0:0:FFFF:7f00:0001]:1234",
191 "https | [11] | [12] | [13] | [::ffff:127.0.0.1] | 1234 "
192 "| / | [16] | [17]", CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
193 {"https://[::FFFF:7f00:0001]:1234",
194 "https | [11] | [12] | [13] | [::ffff:127.0.0.1] | 1234 "
195 "| / | [16] | [17]", CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
196 {"https://[%3A%3A13%2e1%2e68%2e3%25eth0]:1234",
197 "https | [11] | [12] | [13] | [::13.1.68.3] eth0 | 1234 "
198 "| / | [16] | [17]", CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
199 {"https://[%3A%3A13%2e1%2e68%2e3%2525eth0]:1234",
200 "https | [11] | [12] | [13] | [::13.1.68.3] 25eth0 | 1234 "
201 "| / | [16] | [17]", CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
202 {"https://[0:0:0:0:0:0:0d01:4403]:1234",
203 "https | [11] | [12] | [13] | [::13.1.68.3] | 1234 "
204 "| / | [16] | [17]", CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
205 { /* query and fragments with control characters */
206 "http://host/path/?a\001#b\002",
207 "http | [11] | [12] | [13] | host | [15] | /path/ | a%01 | b%02",
208 CURLU_URLENCODE, 0, CURLUE_OK },
209 { /* Control code in port number is never okay, even when URL encoding */
210 "http://host:\x1f""80/path/",
211 "", CURLU_URLENCODE, 0, CURLUE_BAD_PORT_NUMBER },
212 { /* Control code in scheme never okay, even when URL encoding */
213 "http\x1f://host/path/",
214 "", CURLU_URLENCODE, 0, CURLUE_BAD_SCHEME },
215 { /* Control code in separator never okay, even when URL encoding */
216 "http:/%1f/host/path/",
217 "", CURLU_URLENCODE, 0, CURLUE_BAD_HOSTNAME },
218 { /* Path with control characters */
219 "http://host/path\001with\002ctrl/",
220 "http | [11] | [12] | [13] | host | [15] | /path%01with%02ctrl/ | [16] |"
221 " [17]",
222 CURLU_URLENCODE, 0, CURLUE_OK },
223 { /* Path with control characters and space! */
224 "http://host/path\x7fwith space/",
225 "http | [11] | [12] | [13] | host | [15] | /path%7Fwith%20space/ | [16] "
226 "| [17]", CURLU_URLENCODE, 0, CURLUE_OK },
227 { /* Ensure %2f is NOT normalized to / even if path-as-is is NOT set */
228 "http://host/path%2f..%2f/",
229 "http | [11] | [12] | [13] | host | [15] | /path%2f..%2f/ | [16] | [17]",
230 0, 0, CURLUE_OK },
231 { /* Set without scheme using guess, then get without it */
232 "example.com/path",
233 "[10] | [11] | [12] | [13] | example.com | [15] | /path | [16] | [17]",
234 CURLU_GUESS_SCHEME, CURLU_NO_GUESS_SCHEME, CURLUE_OK
235 },
236 { /* CURLU_GET_EMPTY: ensures empty query/fragments are returned as "" not
237 NULL */
238 "http://host/path?#",
239 "http | [11] | [12] | [13] | host | [15] | /path | | ",
240 0, CURLU_GET_EMPTY, CURLUE_OK },
241 { /* Port number overflow ( > 65535 ) */
242 "http://host:65536/",
243 "", 0, 0, CURLUE_BAD_PORT_NUMBER },
244 { /* Port zero - often discouraged/invalid in URLs */
245 "http://host:0/",
246 "http | [11] | [12] | [13] | host | 0 | / | [16] | [17]",
247 0, 0, CURLUE_OK },
248 { /* Leading zeros in port */
249 "http://host:00080/",
250 "http | [11] | [12] | [13] | host | 80 | / | [16] | [17]",
251 0, 0, CURLUE_OK },
252 { /* Single dot host - not ok */
253 "http://./",
254 "",
255 0, 0, CURLUE_BAD_HOSTNAME },
256 { /* Host starting with a dash (RFC 1123 technically allows it, but many
257 parsers do not) */
258 "http://-atest/",
259 "http | [11] | [12] | [13] | -atest | [15] | / | [16] | [17]",
260 0, 0, CURLUE_OK },
261 { /* Multiple trailing dots is not okay */
262 "http://example.com../",
263 "",
264 0, 0, CURLUE_BAD_HOSTNAME },
265 { /* Empty IPv6 Zone ID */
266 "http://[fe80::1%]/",
267 "", 0, 0, CURLUE_BAD_IPV6 },
268 { /* Zone ID with escaped characters */
269 "http://[fe80::1%25eth0]/",
270 "http | [11] | [12] | [13] | [fe80::1] eth0 | [15] | / | [16] | [17]",
271 0, 0, CURLUE_OK },
272 { "curl.se",
273 "[10] | [11] | [12] | [13] | curl.se | [15] | / | [16] | [17]",
274 CURLU_GUESS_SCHEME, CURLU_NO_GUESS_SCHEME, CURLUE_OK },
275 { "https://curl.se:0/#",
276 "https | [11] | [12] | [13] | curl.se | 0 | / | [16] | ",
277 0, CURLU_GET_EMPTY, CURLUE_OK },
278 { "https://curl.se/#",
279 "https | [11] | [12] | [13] | curl.se | [15] | / | [16] | ",
280 0, CURLU_GET_EMPTY, CURLUE_OK },
281 { "https://curl.se/?#",
282 "https | [11] | [12] | [13] | curl.se | [15] | / | | ",
283 0, CURLU_GET_EMPTY, CURLUE_OK },
284 { "https://curl.se/?",
285 "https | [11] | [12] | [13] | curl.se | [15] | / | | [17]",
286 0, CURLU_GET_EMPTY, CURLUE_OK },
287 { "https://curl.se/?",
288 "https | [11] | [12] | [13] | curl.se | [15] | / | [16] | [17]",
289 0, 0, CURLUE_OK },
290 { "https://curl.se/?#",
291 "https | [11] | [12] | [13] | curl.se | [15] | / | [16] | [17]",
292 0, 0, CURLUE_OK },
293 { "https://curl.se/# ",
294 "https | [11] | [12] | [13] | curl.se | [15] | / | [16] | %20%20",
295 CURLU_URLENCODE | CURLU_ALLOW_SPACE, 0, CURLUE_OK },
296 { "", "", 0, 0, CURLUE_MALFORMED_INPUT },
297 { " ", "", 0, 0, CURLUE_BAD_SCHEME },
298 { "1h://example.net", "", 0, 0, CURLUE_BAD_SCHEME },
299 { "..://example.net", "", 0, 0, CURLUE_BAD_SCHEME },
300 { "-ht://example.net", "", 0, 0, CURLUE_BAD_SCHEME },
301 { "+ftp://example.net", "", 0, 0, CURLUE_BAD_SCHEME },
302 { "hej.hej://example.net",
303 "hej.hej | [11] | [12] | [13] | example.net | [15] | / | [16] | [17]",
304 CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_OK },
305 { "ht-tp://example.net",
306 "ht-tp | [11] | [12] | [13] | example.net | [15] | / | [16] | [17]",
307 CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_OK },
308 { "ftp+more://example.net",
309 "ftp+more | [11] | [12] | [13] | example.net | [15] | / | [16] | [17]",
310 CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_OK },
311 { "f1337://example.net",
312 "f1337 | [11] | [12] | [13] | example.net | [15] | / | [16] | [17]",
313 CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_OK },
314 { "https://user@example.net?hello# space ",
315 "https | user | [12] | [13] | example.net | [15] | / | hello | "
316 "%20space%20",
317 CURLU_ALLOW_SPACE | CURLU_URLENCODE, 0, CURLUE_OK },
318 { "https://test%test", "", 0, 0, CURLUE_BAD_HOSTNAME },
319 { "https://example.com%252f%40@example.net",
320 "https | example.com%2f@ | [12] | [13] | example.net | [15] | / "
321 "| [16] | [17]",
322 0, CURLU_URLDECODE, CURLUE_OK },
323#ifdef USE_IDN
324 /* https://sv.wikipedia.org/wiki/R%c3%a4ksm%c3%b6rg%c3%a5s
325 U+00E4 Latin Small Letter A with Diaeresis
326 U+00F6 Latin Small Letter O with Diaeresis
327 U+00E5 Latin Small Letter A with Ring Above
328 */
329 { "https://r\xc3\xa4ksm\xc3\xb6rg\xc3\xa5s.se",
330 "https | [11] | [12] | [13] | xn--rksmrgs-5wao1o.se | "
331 "[15] | / | [16] | [17]", 0, CURLU_PUNYCODE, CURLUE_OK },
332 { "https://xn--rksmrgs-5wao1o.se",
333 "https | [11] | [12] | [13] | r\xc3\xa4ksm\xc3\xb6rg\xc3\xa5s.se | "
334 "[15] | / | [16] | [17]", 0, CURLU_PUNY2IDN, CURLUE_OK },
335 { "https://www.xn--rksmrgs-5wao1o.se",
336 "https | [11] | [12] | [13] | www.r\xc3\xa4ksm\xc3\xb6rg\xc3\xa5s.se | "
337 "[15] | / | [16] | [17]", 0, CURLU_PUNY2IDN, CURLUE_OK },
338 { "https://www.r\xc3\xa4ksm\xc3\xb6rg\xc3\xa5s.se",
339 "https | [11] | [12] | [13] | www.r\xc3\xa4ksm\xc3\xb6rg\xc3\xa5s.se | "
340 "[15] | / | [16] | [17]", 0, CURLU_PUNY2IDN, CURLUE_OK },
341 /* U+FF20 FULLWIDTH COMMERCIAL AT, decodes to '@' */
342 { "https://trusted.example\xef\xbc\xa0"
343 "evil.example/x",
344 "https | [11] | [12] | [13] | [21] | "
345 "[15] | /x | [16] | [17]", 0, CURLU_PUNYCODE, CURLUE_OK },
346#else
347 { "https://r\xc3\xa4ksm\xc3\xb6rg\xc3\xa5s.se",
348 "https | [11] | [12] | [13] | [30] | [15] | / | [16] | [17]",
349 0, CURLU_PUNYCODE, CURLUE_OK },
350#endif
351 /* U+2102 Double-Struck Capital C
352 U+1D64 Latin Subscript Small Letter U
353 U+24C7 Circled Latin Capital Letter R
354 U+2112 Script Capital L
355 U+3002 Ideographic Full Stop
356 U+1D412 Mathematical Bold Capital S
357 U+1F134 Squared Latin Capital Letter E
358 */
359 {"https://"
360 "%e2%84%82%e1%b5%a4%e2%93%87%e2%84%92%e3%80%82%f0%9d%90%92%f0%9f%84%b4",
361 "https | [11] | [12] | [13] | "
362 "\xe2\x84\x82\xe1\xb5\xa4\xe2\x93\x87\xe2\x84\x92"
363 "\xe3\x80\x82\xf0\x9d\x90\x92\xf0\x9f\x84\xb4"
364 " | [15] | / | [16] | [17]",
365 0, 0, CURLUE_OK},
366 {"https://"
367 "%e2%84%82%e1%b5%a4%e2%93%87%e2%84%92%e3%80%82%f0%9d%90%92%f0%9f%84%b4",
368 "https | [11] | [12] | [13] | "
369 "%E2%84%82%E1%B5%A4%E2%93%87%E2%84%92%E3%80%82%F0%9D%90%92%F0%9F%84%B4 "
370 "| [15] | / | [16] | [17]",
371 0, CURLU_URLENCODE, CURLUE_OK},
372 {"https://"
373 "\xe2\x84\x82\xe1\xb5\xa4\xe2\x93\x87\xe2\x84\x92"
374 "\xe3\x80\x82\xf0\x9d\x90\x92\xf0\x9f\x84\xb4",
375 "https | [11] | [12] | [13] | "
376 "%E2%84%82%E1%B5%A4%E2%93%87%E2%84%92%E3%80%82%F0%9D%90%92%F0%9F%84%B4 "
377 "| [15] | / | [16] | [17]",
378 0, CURLU_URLENCODE, CURLUE_OK},
379 {"https://user@example.net?he l lo",
380 "https | user | [12] | [13] | example.net | [15] | / | he+l+lo | [17]",
381 CURLU_ALLOW_SPACE, CURLU_URLENCODE, CURLUE_OK},
382 {"https://user@example.net?he l lo",
383 "https | user | [12] | [13] | example.net | [15] | / | he l lo | [17]",
384 CURLU_ALLOW_SPACE, 0, CURLUE_OK},
385 {"https://exam|ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
386 {"https://exam{}[]ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
387 {"https://exam{ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
388 {"https://exam}ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
389 {"https://exam]ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
390 {"https://exam\\ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
391 {"https://exam$ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
392 {"https://exam'ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
393 {"https://exam\"ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
394 {"https://exam^ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
395 {"https://exam`ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
396 {"https://exam*ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
397 {"https://exam<ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
398 {"https://exam>ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
399 {"https://exam=ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
400 {"https://exam;ple.net", "", 0, 0, CURLUE_BAD_HOSTNAME},
401 {"https://example,net", "", 0, 0, CURLUE_BAD_HOSTNAME},
402 {"https://example&net", "", 0, 0, CURLUE_BAD_HOSTNAME},
403 {"https://example+net", "", 0, 0, CURLUE_BAD_HOSTNAME},
404 {"https://example(net", "", 0, 0, CURLUE_BAD_HOSTNAME},
405 {"https://example)net", "", 0, 0, CURLUE_BAD_HOSTNAME},
406 {"https://example.net/}",
407 "https | [11] | [12] | [13] | example.net | [15] | /} | [16] | [17]",
408 0, 0, CURLUE_OK},
410 /* blank user is blank */
411 {"https://:password@example.net",
412 "https | | password | [13] | example.net | [15] | / | [16] | [17]",
413 0, 0, CURLUE_OK},
414 /* blank user + blank password */
415 {"https://:@example.net",
416 "https | | | [13] | example.net | [15] | / | [16] | [17]",
417 0, 0, CURLUE_OK},
418 /* user-only (no password) */
419 {"https://user@example.net",
420 "https | user | [12] | [13] | example.net | [15] | / | [16] | [17]",
421 0, 0, CURLUE_OK},
422#ifndef CURL_DISABLE_WEBSOCKETS
423 {"ws://example.com/color/?green",
424 "ws | [11] | [12] | [13] | example.com | [15] | /color/ | green |"
425 " [17]",
426 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK },
427 {"wss://example.com/color/?green",
428 "wss | [11] | [12] | [13] | example.com | [15] | /color/ | green |"
429 " [17]",
430 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK },
431#endif
433 {"https://user:password@example.net/get?this=and#but frag then", "",
434 CURLU_DEFAULT_SCHEME, 0, CURLUE_BAD_FRAGMENT},
435 {"https://user:password@example.net/get?this=and what", "",
436 CURLU_DEFAULT_SCHEME, 0, CURLUE_BAD_QUERY},
437 {"https://user:password@example.net/ge t?this=and-what", "",
438 CURLU_DEFAULT_SCHEME, 0, CURLUE_BAD_PATH},
439 {"https://user:pass word@example.net/get?this=and-what", "",
440 CURLU_DEFAULT_SCHEME, 0, CURLUE_BAD_PASSWORD},
441 {"https://u ser:password@example.net/get?this=and-what", "",
442 CURLU_DEFAULT_SCHEME, 0, CURLUE_BAD_USER},
443 {"imap://user:pass;opt ion@server/path", "",
444 CURLU_DEFAULT_SCHEME, 0, CURLUE_MALFORMED_INPUT},
445 /* no space allowed in scheme */
446 {"htt ps://user:password@example.net/get?this=and-what", "",
447 CURLU_NON_SUPPORT_SCHEME | CURLU_ALLOW_SPACE, 0, CURLUE_BAD_SCHEME},
448 {"https://user:password@example.net/get?this=and what",
449 "https | user | password | [13] | example.net | [15] | /get | "
450 "this=and what | [17]",
451 CURLU_ALLOW_SPACE, 0, CURLUE_OK},
452 {"https://user:password@example.net/ge t?this=and-what",
453 "https | user | password | [13] | example.net | [15] | /ge t | "
454 "this=and-what | [17]",
455 CURLU_ALLOW_SPACE, 0, CURLUE_OK},
456 {"https://user:pass word@example.net/get?this=and-what",
457 "https | user | pass word | [13] | example.net | [15] | /get | "
458 "this=and-what | [17]",
459 CURLU_ALLOW_SPACE, 0, CURLUE_OK},
460 {"https://u ser:password@example.net/get?this=and-what",
461 "https | u ser | password | [13] | example.net | [15] | /get | "
462 "this=and-what | [17]",
463 CURLU_ALLOW_SPACE, 0, CURLUE_OK},
464 {"https://user:password@example.net/ge t?this=and-what",
465 "https | user | password | [13] | example.net | [15] | /ge%20t | "
466 "this=and-what | [17]",
467 CURLU_ALLOW_SPACE | CURLU_URLENCODE, 0, CURLUE_OK},
468 {"[0:0:0:0:0:0:0:1]",
469 "http | [11] | [12] | [13] | [::1] | [15] | / | [16] | [17]",
470 CURLU_GUESS_SCHEME, 0, CURLUE_OK },
471 {"[::1]",
472 "http | [11] | [12] | [13] | [::1] | [15] | / | [16] | [17]",
473 CURLU_GUESS_SCHEME, 0, CURLUE_OK },
474 {"[::]",
475 "http | [11] | [12] | [13] | [::] | [15] | / | [16] | [17]",
476 CURLU_GUESS_SCHEME, 0, CURLUE_OK },
477 {"https://[::1]",
478 "https | [11] | [12] | [13] | [::1] | [15] | / | [16] | [17]",
479 0, 0, CURLUE_OK },
480 {"user:moo@ftp.example.com/color/#green?no-red",
481 "ftp | user | moo | [13] | ftp.example.com | [15] | /color/ | [16] | "
482 "green?no-red",
483 CURLU_GUESS_SCHEME, 0, CURLUE_OK },
484 {"ftp.user:moo@example.com/color/#green?no-red",
485 "http | ftp.user | moo | [13] | example.com | [15] | /color/ | [16] | "
486 "green?no-red",
487 CURLU_GUESS_SCHEME, 0, CURLUE_OK },
488#ifdef _WIN32
489 {"file:/C:\\programs\\foo",
490 "file | [11] | [12] | [13] | [14] | [15] | C:\\programs\\foo | [16] | [17]",
491 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
492 {"file://C:\\programs\\foo",
493 "file | [11] | [12] | [13] | [14] | [15] | C:\\programs\\foo | [16] | [17]",
494 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
495 {"file:///C:\\programs\\foo",
496 "file | [11] | [12] | [13] | [14] | [15] | C:\\programs\\foo | [16] | [17]",
497 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
498#endif
499 {"file://host.example.com/Share/path/to/file.txt", "",
500 CURLU_DEFAULT_SCHEME, 0, CURLUE_BAD_FILE_URL},
501 {"https://example.com/color/#green?no-red",
502 "https | [11] | [12] | [13] | example.com | [15] | /color/ | [16] | "
503 "green?no-red",
504 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK },
505 {"https://example.com/color/#green#no-red",
506 "https | [11] | [12] | [13] | example.com | [15] | /color/ | [16] | "
507 "green#no-red",
508 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK },
509 {"https://example.com/color/?green#no-red",
510 "https | [11] | [12] | [13] | example.com | [15] | /color/ | green | "
511 "no-red",
512 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK },
513 {"https://example.com/#color/?green#no-red",
514 "https | [11] | [12] | [13] | example.com | [15] | / | [16] | "
515 "color/?green#no-red",
516 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK },
517 {"https://example.#com/color/?green#no-red",
518 "https | [11] | [12] | [13] | example. | [15] | / | [16] | "
519 "com/color/?green#no-red",
520 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK },
521 {"http://[ab.be:1]/x", "",
522 CURLU_DEFAULT_SCHEME, 0, CURLUE_BAD_IPV6},
523 {"http://[ab.be]/x", "",
524 CURLU_DEFAULT_SCHEME, 0, CURLUE_BAD_IPV6},
525 /* URL without hostname */
526 {"http://a:b@/x", "",
527 CURLU_DEFAULT_SCHEME, 0, CURLUE_NO_HOST},
528 {"boing:80",
529 "https | [11] | [12] | [13] | boing | 80 | / | [16] | [17]",
530 CURLU_DEFAULT_SCHEME | CURLU_GUESS_SCHEME, 0, CURLUE_OK},
531 {"http://[fd00:a41::50]:8080",
532 "http | [11] | [12] | [13] | [fd00:a41::50] | 8080 | / | [16] | [17]",
533 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
534 {"http://[fd00:a41::50]/",
535 "http | [11] | [12] | [13] | [fd00:a41::50] | [15] | / | [16] | [17]",
536 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
537 {"http://[fd00:a41::50]",
538 "http | [11] | [12] | [13] | [fd00:a41::50] | [15] | / | [16] | [17]",
539 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
540 {"https://[::1%252]:1234",
541 "https | [11] | [12] | [13] | [::1] 2 | 1234 | / | [16] | [17]",
542 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
544 /* non-RFC6874 (unescaped '%') zone id, still accepted/normalized */
545 {"https://[fe80::20c:29ff:fe9c:409b%eth0]:1234",
546 "https | [11] | [12] | [13] | [fe80::20c:29ff:fe9c:409b] eth0 | 1234 "
547 "| / | [16] | [17]",
548 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
549 {"https://127.0.0.1:443",
550 "https | [11] | [12] | [13] | 127.0.0.1 | [15] | / | [16] | [17]",
551 0, CURLU_NO_DEFAULT_PORT, CURLUE_OK},
552 {"http://%3a:%3a@ex4mple/%3f+?+%3f+%23#+%23%3f%g7",
553 "http | : | : | [13] | ex4mple | [15] | /?+ | ? # | +#?%g7",
554 0, CURLU_URLDECODE, CURLUE_OK},
555 {"http://%3a:%3a@ex4mple/%3f?%3f%35#%35%3f%g7",
556 "http | %3a | %3a | [13] | ex4mple | [15] | /%3f | %3f%35 | %35%3f%g7",
557 0, 0, CURLUE_OK},
558 {"http://HO0_-st%41/",
559 "http | [11] | [12] | [13] | HO0_-stA | [15] | / | [16] | [17]",
560 0, 0, CURLUE_OK},
561 {"file://hello.html",
562 "",
563 0, 0, CURLUE_BAD_FILE_URL},
564 {"http://HO0_-st/",
565 "http | [11] | [12] | [13] | HO0_-st | [15] | / | [16] | [17]",
566 0, 0, CURLUE_OK},
567 {"imap://user:pass;option@server/path",
568 "imap | user | pass | option | server | [15] | /path | [16] | [17]",
569 0, 0, CURLUE_OK},
570 {"http://user:pass;option@server/path",
571 "http | user | pass;option | [13] | server | [15] | /path | [16] | [17]",
572 0, 0, CURLUE_OK},
573 {"file:/hello.html",
574 "file | [11] | [12] | [13] | [14] | [15] | /hello.html | [16] | [17]",
575 0, 0, CURLUE_OK},
576 {"file:/h",
577 "file | [11] | [12] | [13] | [14] | [15] | /h | [16] | [17]",
578 0, 0, CURLUE_OK},
579 {"file:/",
580 "file | [11] | [12] | [13] | [14] | [15] | | [16] | [17]",
581 0, 0, CURLUE_BAD_FILE_URL},
582 {"file://127.0.0.1/hello.html",
583 "file | [11] | [12] | [13] | [14] | [15] | /hello.html | [16] | [17]",
584 0, 0, CURLUE_OK},
585 {"file:////hello.html",
586 "file | [11] | [12] | [13] | [14] | [15] | //hello.html | [16] | [17]",
587 0, 0, CURLUE_OK},
588 {"file:///hello.html",
589 "file | [11] | [12] | [13] | [14] | [15] | /hello.html | [16] | [17]",
590 0, 0, CURLUE_OK},
592 /* verify that we get the right default ports */
593 {"https://127.0.0.1",
594 "https | [11] | [12] | [13] | 127.0.0.1 | 443 | / | [16] | [17]",
595 0, CURLU_DEFAULT_PORT, CURLUE_OK},
596 {"http://127.0.0.1",
597 "http | [11] | [12] | [13] | 127.0.0.1 | 80 | / | [16] | [17]",
598 0, CURLU_DEFAULT_PORT, CURLUE_OK},
599 {"ftp://127.0.0.1",
600 "ftp | [11] | [12] | [13] | 127.0.0.1 | 21 | / | [16] | [17]",
601 0, CURLU_DEFAULT_PORT, CURLUE_OK},
602 {"ftps://127.0.0.1",
603 "ftps | [11] | [12] | [13] | 127.0.0.1 | 990 | / | [16] | [17]",
604 0, CURLU_DEFAULT_PORT, CURLUE_OK},
605 {"scp://127.0.0.1",
606 "scp | [11] | [12] | [13] | 127.0.0.1 | 22 | / | [16] | [17]",
607 0, CURLU_DEFAULT_PORT, CURLUE_OK},
608 {"sftp://127.0.0.1",
609 "sftp | [11] | [12] | [13] | 127.0.0.1 | 22 | / | [16] | [17]",
610 0, CURLU_DEFAULT_PORT, CURLUE_OK},
611 {"imap://127.0.0.1",
612 "imap | [11] | [12] | [13] | 127.0.0.1 | 143 | / | [16] | [17]",
613 0, CURLU_DEFAULT_PORT, CURLUE_OK},
614 {"imaps://127.0.0.1",
615 "imaps | [11] | [12] | [13] | 127.0.0.1 | 993 | / | [16] | [17]",
616 0, CURLU_DEFAULT_PORT, CURLUE_OK},
617 {"smtp://127.0.0.1",
618 "smtp | [11] | [12] | [13] | 127.0.0.1 | 25 | / | [16] | [17]",
619 0, CURLU_DEFAULT_PORT, CURLUE_OK},
620 {"smtps://127.0.0.1",
621 "smtps | [11] | [12] | [13] | 127.0.0.1 | 465 | / | [16] | [17]",
622 0, CURLU_DEFAULT_PORT, CURLUE_OK},
623 {"pop3://127.0.0.1",
624 "pop3 | [11] | [12] | [13] | 127.0.0.1 | 110 | / | [16] | [17]",
625 0, CURLU_DEFAULT_PORT, CURLUE_OK},
626 {"pop3s://127.0.0.1",
627 "pop3s | [11] | [12] | [13] | 127.0.0.1 | 995 | / | [16] | [17]",
628 0, CURLU_DEFAULT_PORT, CURLUE_OK},
629#ifndef CURL_DISABLE_WEBSOCKETS
630 {"ws://127.0.0.1",
631 "ws | [11] | [12] | [13] | 127.0.0.1 | 80 | / | [16] | [17]",
632 0, CURLU_DEFAULT_PORT, CURLUE_OK},
633 {"wss://127.0.0.1",
634 "wss | [11] | [12] | [13] | 127.0.0.1 | 443 | / | [16] | [17]",
635 0, CURLU_DEFAULT_PORT, CURLUE_OK},
636#endif
637 {"telnet://127.0.0.1",
638 "telnet | [11] | [12] | [13] | 127.0.0.1 | 23 | / | [16] | [17]",
639 0, CURLU_DEFAULT_PORT, CURLUE_OK},
640 {"gopher://127.0.0.1",
641 "gopher | [11] | [12] | [13] | 127.0.0.1 | 70 | / | [16] | [17]",
642 0, CURLU_DEFAULT_PORT, CURLUE_OK},
643 {"gophers://127.0.0.1",
644 "gophers | [11] | [12] | [13] | 127.0.0.1 | 70 | / | [16] | [17]",
645 0, CURLU_DEFAULT_PORT, CURLUE_OK},
646#ifndef CURL_DISABLE_LDAP
647 {"ldap://127.0.0.1",
648 "ldap | [11] | [12] | [13] | 127.0.0.1 | 389 | / | [16] | [17]",
649 0, CURLU_DEFAULT_PORT, CURLUE_OK},
650 {"ldaps://127.0.0.1",
651 "ldaps | [11] | [12] | [13] | 127.0.0.1 | 636 | / | [16] | [17]",
652 0, CURLU_DEFAULT_PORT, CURLUE_OK},
653#endif
655 {"https://127.0.0.1",
656 "https | [11] | [12] | [13] | 127.0.0.1 | [15] | / | [16] | [17]",
657 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
658 {"https://[::1]:1234",
659 "https | [11] | [12] | [13] | [::1] | 1234 | / | [16] | [17]",
660 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
661 {"https://127abc.com",
662 "https | [11] | [12] | [13] | 127abc.com | [15] | / | [16] | [17]",
663 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
664 {"https:// example.com?check", "",
665 CURLU_DEFAULT_SCHEME, 0, CURLUE_BAD_HOSTNAME},
666 {"https://e x a m p l e.com?check", "",
667 CURLU_DEFAULT_SCHEME, 0, CURLUE_BAD_HOSTNAME},
668 {"https://example.com?check",
669 "https | [11] | [12] | [13] | example.com | [15] | / | check | [17]",
670 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
671 {"https://example.com:65536",
672 "",
673 CURLU_DEFAULT_SCHEME, 0, CURLUE_BAD_PORT_NUMBER},
674 {"https://example.com:-1#moo",
675 "",
676 CURLU_DEFAULT_SCHEME, 0, CURLUE_BAD_PORT_NUMBER},
677 {"https://example.com:0#moo",
678 "https | [11] | [12] | [13] | example.com | 0 | / | "
679 "[16] | moo",
680 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
681 {"https://example.com:01#moo",
682 "https | [11] | [12] | [13] | example.com | 1 | / | "
683 "[16] | moo",
684 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
685 {"https://example.com:1#moo",
686 "https | [11] | [12] | [13] | example.com | 1 | / | "
687 "[16] | moo",
688 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
689 {"http://example.com#moo",
690 "http | [11] | [12] | [13] | example.com | [15] | / | "
691 "[16] | moo",
692 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
693 {"http://example.com",
694 "http | [11] | [12] | [13] | example.com | [15] | / | "
695 "[16] | [17]",
696 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
697 {"http://example.com/path/html",
698 "http | [11] | [12] | [13] | example.com | [15] | /path/html | "
699 "[16] | [17]",
700 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
701 {"http://example.com/path/html?query=name",
702 "http | [11] | [12] | [13] | example.com | [15] | /path/html | "
703 "query=name | [17]",
704 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
705 {"http://example.com/path/html?query=name#anchor",
706 "http | [11] | [12] | [13] | example.com | [15] | /path/html | "
707 "query=name | anchor",
708 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
709 {"http://example.com:1234/path/html?query=name#anchor",
710 "http | [11] | [12] | [13] | example.com | 1234 | /path/html | "
711 "query=name | anchor",
712 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
713 {"http:///user:password@example.com:1234/path/html?query=name#anchor",
714 "http | user | password | [13] | example.com | 1234 | /path/html | "
715 "query=name | anchor",
716 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
717 {"https://user:password@example.com:1234/path/html?query=name#anchor",
718 "https | user | password | [13] | example.com | 1234 | /path/html | "
719 "query=name | anchor",
720 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
721 {"http://user:password@example.com:1234/path/html?query=name#anchor",
722 "http | user | password | [13] | example.com | 1234 | /path/html | "
723 "query=name | anchor",
724 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
725 {"http:/user:password@example.com:1234/path/html?query=name#anchor",
726 "http | user | password | [13] | example.com | 1234 | /path/html | "
727 "query=name | anchor",
728 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
729 {"http:////user:password@example.com:1234/path/html?query=name#anchor",
730 "",
731 CURLU_DEFAULT_SCHEME, 0, CURLUE_BAD_SLASHES},
732 { /* CURLU_DISALLOW_USER with user */
733 "https://user@example.com", "", CURLU_DISALLOW_USER, 0,
734 CURLUE_USER_NOT_ALLOWED },
735 { /* CURLU_DISALLOW_USER with user:password */
736 "https://user:password@example.com", "", CURLU_DISALLOW_USER, 0,
737 CURLUE_USER_NOT_ALLOWED },
738 { /* Hostname with trailing dot */
739 "https://example.com./",
740 "https | [11] | [12] | [13] | example.com. | [15] | / | [16] | [17]",
741 0, 0, CURLUE_OK },
742 {NULL, NULL, 0, 0, CURLUE_OK},
743};
745static const struct urltestcase get_url_list[] = {
746 /* percent-encoded IP addresses */
747 {"https://127.0.0.%31.", "https://127.0.0.1/", 0, 0, CURLUE_OK},
748 {"https://127.0.0.0%78f%46.", "https://127.0.0.255/", 0, 0, CURLUE_OK},
749 {"https://%30%31%37%37%2e%31", "https://127.0.0.1/", 0, 0, CURLUE_OK},
750 {"https://[fe80%3A%3A20c%3A29ff%3Afe9c%3A409b]/",
751 "https://[fe80::20c:29ff:fe9c:409b]/", 0, 0, CURLUE_OK },
753 /* URL encoded [brackets] */
754 {"https://%5bfe80%3A%3A20c%3A29ff%3Afe9c%3A409b%5c/",
755 "", 0, 0, CURLUE_BAD_HOSTNAME },
757 /* IPvFuture format */
758 {"http://[v1.fe80::abcd]/", "", 0, 0, CURLUE_BAD_IPV6},
760 /* trailing dot on valid host */
761 {"http://example.com./", "http://example.com./", 0, 0, CURLUE_OK},
763 /* the exact upper valid port boundary */
764 {"http://host:65535/", "http://host:65535/", 0, 0, CURLUE_OK},
766 /* Internationalized path (not host). */
767 {"https://example.com/r\xc3\xa4ksm\xc3\xb6rg\xc3\xa5s",
768 "https://example.com/r%C3%A4ksm%C3%B6rg%C3%A5s",
769 CURLU_URLENCODE, 0, CURLUE_OK},
771 /* weird fragments */
772 {"http://host/#a#b", "http://host/#a#b", 0, 0, CURLUE_OK},
774 /* Empty query parameter values */
775 {"http://host/?a=", "http://host/?a=", 0, 0, CURLUE_OK},
776 {"http://host/?a=&b=", "http://host/?a=&b=", 0, 0, CURLUE_OK},
778 /* Percent-encoded userinfo */
779 {"https://user%20name@example.com/", "https://user%20name@example.com/",
780 0, 0, CURLUE_OK},
781 {"https://user:pa%3Ass@example.com/", "https://user:pa%3Ass@example.com/",
782 0, 0, CURLUE_OK},
784 /* malformed unbracketed IPv6 */
785 {"https://fe80:8080::1/", "", 0, 0, CURLUE_BAD_PORT_NUMBER},
786 {"https://::1/", "", 0, 0, CURLUE_NO_HOST},
788 /* Empty host with standard schemes */
789 {"http:///", "", 0, 0, CURLUE_NO_HOST},
790 {"https://?q=1", "", 0, 0, CURLUE_NO_HOST},
792 /* Empty path segment normalization */
793 {"http://example.com//", "http://example.com//", 0, 0, CURLUE_OK},
794 {"http://example.com///foo", "http://example.com///foo", 0, 0, CURLUE_OK},
796 /* Empty user and password combinations */
797 {"http://@example.com/", "http://@example.com/", 0, 0, CURLUE_OK},
798 {"http://user:@example.com/", "http://user:@example.com/", 0, 0, CURLUE_OK},
799 {"http://:password@example.com/", "http://:password@example.com/",
800 0, 0, CURLUE_OK},
802 {"https://127.1.0x", "https://127.1.0x/", 0, 0, CURLUE_OK},
803 {"https://127.0x", "https://127.0x/", 0, 0, CURLUE_OK},
804 {"https://127.0x.1", "https://127.0x.1/", 0, 0, CURLUE_OK},
805 {"https://127.1.1.0x", "https://127.1.1.0x/", 0, 0, CURLUE_OK},
806 {"https://127.1.", "https://127.0.0.1/", 0, 0, CURLUE_OK},
807 {"https://127.1.:443", "https://127.0.0.1:443/", 0, 0, CURLUE_OK},
808 {"https://127.1.?moo", "https://127.0.0.1/?moo", 0, 0, CURLUE_OK},
809 {"https://127.1.#moo", "https://127.0.0.1/#moo", 0, 0, CURLUE_OK},
810 {"https://127.1.a", "https://127.1.a/", 0, 0, CURLUE_OK},
811 {"https://127.1..", "", 0, 0, CURLUE_BAD_HOSTNAME},
812 {"https://127.1..:443", "", 0, 0, CURLUE_BAD_HOSTNAME},
813 {"https://127.1..?moo", "", 0, 0, CURLUE_BAD_HOSTNAME},
814 {"https://127.1..#moo", "", 0, 0, CURLUE_BAD_HOSTNAME},
815 {"https://127.1.1.", "https://127.1.0.1/", 0, 0, CURLUE_OK},
816 {"https://127.1.1./foo", "https://127.1.0.1/foo", 0, 0, CURLUE_OK},
817 {"https://127.1.1.1.", "https://127.1.1.1/", 0, 0, CURLUE_OK},
818 {"https://127.1", "https://127.0.0.1/", 0, 0, CURLUE_OK},
819 {"https://127.0.0.1.", "https://127.0.0.1/", 0, 0, CURLUE_OK},
820 {"https://127.0.0.0xff.", "https://127.0.0.255/", 0, 0, CURLUE_OK},
821 {"https://127.0.0.1..", "", 0, 0, CURLUE_BAD_HOSTNAME},
822 {"https://127.0.0.256..", "", 0, 0, CURLUE_BAD_HOSTNAME},
823 {"http://hej./", "http://hej./", 0, 0, CURLUE_OK},
824 {"http://hej../", "", 0, 0, CURLUE_BAD_HOSTNAME},
825 {"http://hej.../", "", 0, 0, CURLUE_BAD_HOSTNAME},
826 {"http://hej..../index.html", "", 0, 0, CURLUE_BAD_HOSTNAME},
827 {"http://.", "", 0, 0, CURLUE_BAD_HOSTNAME},
828 {"http://..", "", 0, 0, CURLUE_BAD_HOSTNAME},
829 {"http://...", "", 0, 0, CURLUE_BAD_HOSTNAME},
830 {"018.0.0.0", "http://018.0.0.0/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
831 {"08", "http://08/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
832 {"0", "http://0.0.0.0/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
833 {"01", "http://0.0.0.1/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
834 {"02", "http://0.0.0.2/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
835 {"03", "http://0.0.0.3/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
836 {"04", "http://0.0.0.4/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
837 {"05", "http://0.0.0.5/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
838 {"06", "http://0.0.0.6/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
839 {"07", "http://0.0.0.7/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
840 {"07.1", "http://7.0.0.1/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
841 {"7.1", "http://7.0.0.1/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
842 {"0x7.1", "http://7.0.0.1/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
843 {"0x", "http://0x/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
844 {"0x1", "http://0.0.0.1/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
845 {"0x2", "http://0.0.0.2/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
846 {"0x3", "http://0.0.0.3/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
847 {"0x4", "http://0.0.0.4/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
848 {"0x5", "http://0.0.0.5/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
849 {"0x6", "http://0.0.0.6/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
850 {"0x7", "http://0.0.0.7/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
851 {"0x8", "http://0.0.0.8/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
852 {"0x9", "http://0.0.0.9/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
853 {"0xa", "http://0.0.0.10/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
854 {"0xb", "http://0.0.0.11/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
855 {"0xc", "http://0.0.0.12/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
856 {"0xd", "http://0.0.0.13/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
857 {"0xe", "http://0.0.0.14/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
858 {"0xf", "http://0.0.0.15/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
859 {"0xg", "http://0xg/", CURLU_GUESS_SCHEME, 0, CURLUE_OK},
860 {"https://0/", "https://0.0.0.0/", 0, 0, CURLUE_OK},
861 {"https://0.0x0/", "https://0.0.0.0/", 0, 0, CURLUE_OK},
862 {"https://0.000/", "https://0.0.0.0/", 0, 0, CURLUE_OK},
863 {"example.com",
864 "example.com/",
865 CURLU_GUESS_SCHEME, CURLU_NO_GUESS_SCHEME, CURLUE_OK},
866 {"http://user@example.com?#",
867 "http://user@example.com/?#",
868 0, CURLU_GET_EMPTY, CURLUE_OK},
869 /* WHATWG disagrees, it wants "https:/0.0.0.0/" */
870 {"https://0x.0x.0", "https://0x.0x.0/", 0, 0, CURLUE_OK},
872 {"https://example.com:000000000000000000000443/foo",
873 "https://example.com/foo",
874 0, CURLU_NO_DEFAULT_PORT, CURLUE_OK},
875 {"https://example.com:000000000000000000000/foo",
876 "https://example.com:0/foo",
877 0, CURLU_NO_DEFAULT_PORT, CURLUE_OK},
878 {"https://192.0x0000A80001", "https://192.168.0.1/", 0, 0, CURLUE_OK},
879 {"https://0xffffffff", "https://255.255.255.255/", 0, 0, CURLUE_OK},
880 {"https://1.0x1000000", "https://1.0x1000000/", 0, 0, CURLUE_OK},
881 {"https://0x7f.1", "https://127.0.0.1/", 0, 0, CURLUE_OK},
882 {"https://0X7F.1", "https://127.0.0.1/", 0, 0, CURLUE_OK},
883 {"https://1.2.3.256.com", "https://1.2.3.256.com/", 0, 0, CURLUE_OK},
884 {"https://10.com", "https://10.com/", 0, 0, CURLUE_OK},
885 {"https://1.2.com", "https://1.2.com/", 0, 0, CURLUE_OK},
886 {"https://1.2.3.com", "https://1.2.3.com/", 0, 0, CURLUE_OK},
887 {"https://1.2.com.99", "https://1.2.com.99/", 0, 0, CURLUE_OK},
888 {"https://[fe80::0000:20c:29ff:fe9c:409b]:80/moo",
889 "https://[fe80::20c:29ff:fe9c:409b]:80/moo",
890 0, 0, CURLUE_OK},
891 {"https://[fe80::020c:29ff:fe9c:409b]:80/moo",
892 "https://[fe80::20c:29ff:fe9c:409b]:80/moo",
893 0, 0, CURLUE_OK},
894 {"https://[fe80:0000:0000:0000:020c:29ff:fe9c:409b]:80/moo",
895 "https://[fe80::20c:29ff:fe9c:409b]:80/moo",
896 0, 0, CURLUE_OK},
897 {"https://[fe80:0:0:0:409b::]:80/moo",
898 "https://[fe80::409b:0:0:0]:80/moo",
899 0, 0, CURLUE_OK},
900 /* normalize to lower case */
901 {"https://[FE80:0:A:0:409B:0:0:0]:80/moo",
902 "https://[fe80:0:a:0:409b::]:80/moo",
903 0, 0, CURLUE_OK},
904 {"https://[::%25fakeit];80/moo",
905 "",
906 0, 0, CURLUE_BAD_PORT_NUMBER},
907 {"https://[::%25fa keit]:80/moo",
908 "",
909 0, 0, CURLUE_BAD_IPV6},
910 {"https://[::%25fa%\x7fkeit]:80/moo",
911 "",
912 0, 0, CURLUE_BAD_IPV6},
913 {"https://[::%25fa keit]:80/moo",
914 "",
915 CURLU_ALLOW_SPACE, 0, CURLUE_BAD_IPV6},
916 {"https://[::%25fake\tit]:80/moo",
917 "",
918 0, 0, CURLUE_BAD_HOSTNAME},
919 {"https://[fe80::20c:29ff:fe9c:409b]-80/moo",
920 "",
921 0, 0, CURLUE_BAD_PORT_NUMBER},
922#ifdef USE_IDN
923 {"https://r\xc3\xa4ksm\xc3\xb6rg\xc3\xa5s.se/path?q#frag",
924 "https://xn--rksmrgs-5wao1o.se/path?q#frag", 0, CURLU_PUNYCODE, CURLUE_OK},
925#endif
926 /* unsupported schemes with no guessing enabled */
927 {"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIEhUTUw+PG1ldGEgY",
928 "", 0, 0, CURLUE_UNSUPPORTED_SCHEME},
929 {"d:anything-really", "", 0, 0, CURLUE_UNSUPPORTED_SCHEME},
930 {"about:config", "", 0, 0, CURLUE_UNSUPPORTED_SCHEME},
931 {"example://foo", "", 0, 0, CURLUE_UNSUPPORTED_SCHEME},
932 {"mailto:infobot@example.com?body=send%20current-issue", "", 0, 0,
933 CURLUE_UNSUPPORTED_SCHEME},
934 {"about:80", "https://about:80/", CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
935 /* percent encoded hostnames */
936 {"http://example.com%40127.0.0.1/", "", 0, 0, CURLUE_BAD_HOSTNAME},
937 {"http://example.com%21127.0.0.1/", "", 0, 0, CURLUE_BAD_HOSTNAME},
938 {"http://example.com%3f127.0.0.1/", "", 0, 0, CURLUE_BAD_HOSTNAME},
939 {"http://example.com%23127.0.0.1/", "", 0, 0, CURLUE_BAD_HOSTNAME},
940 {"http://example.com%3a127.0.0.1/", "", 0, 0, CURLUE_BAD_HOSTNAME},
941 {"http://example.com%09127.0.0.1/", "", 0, 0, CURLUE_BAD_HOSTNAME},
942 {"http://example.com%2F127.0.0.1/", "", 0, 0, CURLUE_BAD_HOSTNAME},
943 {"https://%41", "https://A/", 0, 0, CURLUE_OK},
944 {"https://%20", "", 0, 0, CURLUE_BAD_HOSTNAME},
945 {"https://%41%0D", "", 0, 0, CURLUE_BAD_HOSTNAME},
946 {"https://%25", "", 0, 0, CURLUE_BAD_HOSTNAME},
947 {"https://_%c0_", "https://_\xC0_/", 0, 0, CURLUE_OK},
948 {"https://_%c0_", "https://_%C0_/", 0, CURLU_URLENCODE, CURLUE_OK},
950 /* IPv4 trickeries */
951 {"https://16843009", "https://1.1.1.1/", 0, 0, CURLUE_OK},
952 {"https://0177.1", "https://127.0.0.1/", 0, 0, CURLUE_OK},
953 {"https://0111.02.0x3", "https://73.2.0.3/", 0, 0, CURLUE_OK},
954 {"https://0111.02.0X3", "https://73.2.0.3/", 0, 0, CURLUE_OK},
955 {"https://0111.02.0x3.", "https://73.2.0.3/", 0, 0, CURLUE_OK},
956 {"https://0111.02.030", "https://73.2.0.24/", 0, 0, CURLUE_OK},
957 {"https://0111.02.030.", "https://73.2.0.24/", 0, 0, CURLUE_OK},
958 {"https://0xff.0xff.0377.255", "https://255.255.255.255/", 0, 0, CURLUE_OK},
959 {"https://0XFF.0XFF.0377.255", "https://255.255.255.255/", 0, 0, CURLUE_OK},
960 {"https://1.0xffffff", "https://1.255.255.255/", 0, 0, CURLUE_OK},
961 /* IPv4 numerical overflows or syntax errors do not normalize */
962 {"https://a127.0.0.1", "https://a127.0.0.1/", 0, 0, CURLUE_OK},
963 {"https://\xff.127.0.0.1", "https://%FF.127.0.0.1/", 0, CURLU_URLENCODE,
964 CURLUE_OK},
965 {"https://127.-0.0.1", "https://127.-0.0.1/", 0, 0, CURLUE_OK},
966 {"https://127.0. 1", "https://127.0.0.1/", 0, 0, CURLUE_BAD_HOSTNAME},
967 {"https://1.2.3.256", "https://1.2.3.256/", 0, 0, CURLUE_OK},
968 {"https://1.2.3.256.", "https://1.2.3.256./", 0, 0, CURLUE_OK},
969 {"https://1.2.3.4.5", "https://1.2.3.4.5/", 0, 0, CURLUE_OK},
970 {"https://1.2.0x100.3", "https://1.2.0x100.3/", 0, 0, CURLUE_OK},
971 {"https://4294967296", "https://4294967296/", 0, 0, CURLUE_OK},
972 {"https://123host", "https://123host/", 0, 0, CURLUE_OK},
973 /* 40 bytes scheme is the max allowed */
974 {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA://hostname/path",
975 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa://hostname/path",
976 CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_OK},
977 /* 41 bytes scheme is not allowed */
978 {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA://hostname/path",
979 "",
980 CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_BAD_SCHEME},
981 {"https://[fe80::20c:29ff:fe9c:409b%]:1234",
982 "",
983 0, 0, CURLUE_BAD_IPV6},
984 {"https://[fe80::20c:29ff:fe9c:409b%25]:1234",
985 "",
986 0, 0, CURLUE_BAD_IPV6},
987 {"https://[fe80::20c:29ff:fe9c:409b%eth0]:1234",
988 "https://[fe80::20c:29ff:fe9c:409b%25eth0]:1234/",
989 0, 0, CURLUE_OK},
990 {"https://[::%25fakeit]/moo",
991 "https://[::%25fakeit]/moo",
992 0, 0, CURLUE_OK},
993 {"smtp.example.com/path/html",
994 "smtp://smtp.example.com/path/html",
995 CURLU_GUESS_SCHEME, 0, CURLUE_OK},
996 {"https.example.com/path/html",
997 "http://https.example.com/path/html",
998 CURLU_GUESS_SCHEME, 0, CURLUE_OK},
999 {"dict.example.com/path/html",
1000 "dict://dict.example.com/path/html",
1001 CURLU_GUESS_SCHEME, 0, CURLUE_OK},
1002 {"pop3.example.com/path/html",
1003 "pop3://pop3.example.com/path/html",
1004 CURLU_GUESS_SCHEME, 0, CURLUE_OK},
1005#ifndef CURL_DISABLE_LDAP
1006 {"ldap.example.com/path/html",
1007 "ldap://ldap.example.com/path/html",
1008 CURLU_GUESS_SCHEME, 0, CURLUE_OK},
1009#endif
1010 {"imap.example.com/path/html",
1011 "imap://imap.example.com/path/html",
1012 CURLU_GUESS_SCHEME, 0, CURLUE_OK},
1013 {"ftp.example.com/path/html",
1014 "ftp://ftp.example.com/path/html",
1015 CURLU_GUESS_SCHEME, 0, CURLUE_OK},
1016 {"example.com/path/html",
1017 "http://example.com/path/html",
1018 CURLU_GUESS_SCHEME, 0, CURLUE_OK},
1019 {"smtp.com/path/html",
1020 "smtp://smtp.com/path/html",
1021 CURLU_GUESS_SCHEME, 0, CURLUE_OK},
1022 {"dict.com/path/html",
1023 "dict://dict.com/path/html",
1024 CURLU_GUESS_SCHEME, 0, CURLUE_OK},
1025 {"pop3.com/path/html",
1026 "pop3://pop3.com/path/html",
1027 CURLU_GUESS_SCHEME, 0, CURLUE_OK},
1028#ifndef CURL_DISABLE_LDAP
1029 {"ldap.com/path/html",
1030 "ldap://ldap.com/path/html",
1031 CURLU_GUESS_SCHEME, 0, CURLUE_OK},
1032#endif
1033 {"imap.com/path/html",
1034 "imap://imap.com/path/html",
1035 CURLU_GUESS_SCHEME, 0, CURLUE_OK},
1036 {"ftp.com/path/html",
1037 "ftp://ftp.com/path/html",
1038 CURLU_GUESS_SCHEME, 0, CURLUE_OK},
1039 {"smtp/path/html",
1040 "http://smtp/path/html",
1041 CURLU_GUESS_SCHEME, 0, CURLUE_OK},
1042 {"dict/path/html",
1043 "http://dict/path/html",
1044 CURLU_GUESS_SCHEME, 0, CURLUE_OK},
1045 {"pop3/path/html",
1046 "http://pop3/path/html",
1047 CURLU_GUESS_SCHEME, 0, CURLUE_OK},
1048#ifndef CURL_DISABLE_LDAP
1049 {"ldap/path/html",
1050 "http://ldap/path/html",
1051 CURLU_GUESS_SCHEME, 0, CURLUE_OK},
1052#endif
1053 {"imap/path/html",
1054 "http://imap/path/html",
1055 CURLU_GUESS_SCHEME, 0, CURLUE_OK},
1056 {"ftp/path/html",
1057 "http://ftp/path/html",
1058 CURLU_GUESS_SCHEME, 0, CURLUE_OK},
1059 {"HTTP://test/", "http://test/", 0, 0, CURLUE_OK},
1060 {"http://HO0_-st..~./", "http://HO0_-st..~./", 0, 0, CURLUE_OK},
1061 {"http:/@example.com: 123/", "", 0, 0, CURLUE_BAD_PORT_NUMBER},
1062 {"http:/@example.com:123 /", "", 0, 0, CURLUE_BAD_PORT_NUMBER},
1063 {"http:/@example.com:123a/", "", 0, 0, CURLUE_BAD_PORT_NUMBER},
1064 {"http://host/file\r", "", 0, 0, CURLUE_BAD_PATH},
1065 {"http://host/file?\r", "", 0, 0, CURLUE_BAD_QUERY},
1066 {"http://host/file?hello#\r", "", 0, 0, CURLUE_BAD_FRAGMENT},
1067 {"http://\r:hej@host/file", "", 0, 0, CURLUE_BAD_USER},
1068 {"http://hej:\r@host/file", "", 0, 0, CURLUE_BAD_PASSWORD},
1069 {"http://host/file\n\x03", "", 0, 0, CURLUE_BAD_PATH},
1070 {"htt\x02://host/file", "",
1071 CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_BAD_SCHEME},
1072 {" http://host/file", "", 0, 0, CURLUE_BAD_SCHEME},
1073 /* here the password ends at the semicolon and options is 'word' */
1074 {"imap://user:pass;word@host/file",
1075 "imap://user:pass;word@host/file",
1076 0, 0, CURLUE_OK},
1077 /* here the password has the semicolon */
1078 {"http://user:pass;word@host/file",
1079 "http://user:pass;word@host/file", 0, 0, CURLUE_OK},
1080 {"file:///file.txt#moo", "file:///file.txt#moo", 0, 0, CURLUE_OK},
1081 {"file:////file.txt", "file:////file.txt", 0, 0, CURLUE_OK},
1082 {"file:///file.txt", "file:///file.txt", 0, 0, CURLUE_OK},
1083 {"file:///", "file:///", 0, 0, CURLUE_OK},
1084 {"file:///.", "file:///", 0, 0, CURLUE_OK},
1085 {"file:///./", "file:///", 0, 0, CURLUE_OK},
1086 {"file:///a", "file:///a", 0, 0, CURLUE_OK},
1087 {"file:./", "", 0, 0, CURLUE_BAD_FILE_URL},
1088 {"file:foo", "", 0, 0, CURLUE_BAD_FILE_URL},
1089 {"file:foo/bar", "", 0, 0, CURLUE_BAD_FILE_URL},
1090 {"file:?q", "", 0, 0, CURLUE_BAD_FILE_URL},
1091 {"file:#f", "", 0, 0, CURLUE_BAD_FILE_URL},
1092 {"http://example.com/hello/../here",
1093 "http://example.com/hello/../here",
1094 CURLU_PATH_AS_IS, 0, CURLUE_OK},
1095 {"http://example.com/hello/../here",
1096 "http://example.com/here",
1097 0, 0, CURLUE_OK},
1098 {"http://example.com:80",
1099 "http://example.com/",
1100 0, CURLU_NO_DEFAULT_PORT, CURLUE_OK},
1101 {"tp://example.com/path/html",
1102 "",
1103 0, 0, CURLUE_UNSUPPORTED_SCHEME},
1104 {"http://hello:fool@example.com",
1105 "",
1106 CURLU_DISALLOW_USER, 0, CURLUE_USER_NOT_ALLOWED},
1107 {"http:/@example.com:123",
1108 "http://@example.com:123/",
1109 0, 0, CURLUE_OK},
1110 {"http:/:password@example.com",
1111 "http://:password@example.com/",
1112 0, 0, CURLUE_OK},
1113 {"http://user@example.com?#",
1114 "http://user@example.com/",
1115 0, 0, CURLUE_OK},
1116 {"http://user@example.com?",
1117 "http://user@example.com/",
1118 0, 0, CURLUE_OK},
1119 {"http://user@example.com#anchor",
1120 "http://user@example.com/#anchor",
1121 0, 0, CURLUE_OK},
1122 {"example.com/path/html",
1123 "https://example.com/path/html",
1124 CURLU_DEFAULT_SCHEME, 0, CURLUE_OK},
1125 {"example.com/path/html",
1126 "",
1127 0, 0, CURLUE_BAD_SCHEME},
1128 {"http://user:password@example.com:1234/path/html?query=name#anchor",
1129 "http://user:password@example.com:1234/path/html?query=name#anchor",
1130 0, 0, CURLUE_OK},
1131 {"http://example.com:1234/path/html?query=name#anchor",
1132 "http://example.com:1234/path/html?query=name#anchor",
1133 0, 0, CURLUE_OK},
1134 {"http://example.com/path/html?query=name#anchor",
1135 "http://example.com/path/html?query=name#anchor",
1136 0, 0, CURLUE_OK},
1137 {"http://example.com/path/html?query=name",
1138 "http://example.com/path/html?query=name",
1139 0, 0, CURLUE_OK},
1140 {"http://example.com/path/html",
1141 "http://example.com/path/html",
1142 0, 0, CURLUE_OK},
1143 {"tp://example.com/path/html",
1144 "tp://example.com/path/html",
1145 CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_OK},
1146 {"custom-scheme://host?expected=test-good",
1147 "custom-scheme://host/?expected=test-good",
1148 CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_OK},
1149 {"custom-scheme://?expected=test-bad",
1150 "",
1151 CURLU_NON_SUPPORT_SCHEME, 0, CURLUE_NO_HOST},
1152 {"custom-scheme://?expected=test-new-good",
1153 "custom-scheme:///?expected=test-new-good",
1154 CURLU_NON_SUPPORT_SCHEME | CURLU_NO_AUTHORITY, 0, CURLUE_OK},
1155 {"custom-scheme://host?expected=test-still-good",
1156 "custom-scheme://host/?expected=test-still-good",
1157 CURLU_NON_SUPPORT_SCHEME | CURLU_NO_AUTHORITY, 0, CURLUE_OK},
1158 {"https://%41%0D%0A%42/", "", 0, 0, CURLUE_BAD_HOSTNAME},
1159 {"https://[fe80::1]:0/foo", "https://[fe80::1]:0/foo", 0, 0, CURLUE_OK},
1160 {NULL, NULL, 0, 0, CURLUE_OK}
1163static int checkurl(const char *org, const char *url, const char *out)
1165 if(strcmp(out, url)) {
1166 curl_mfprintf(stderr,
1167 "Org: %s\n"
1168 "Wanted: %s\n"
1169 "Got : %s\n",
1170 org, out, url);
1171 return 1;
1173 return 0;
1176/* 1. Set the URL
1177 2. Set components
1178 3. Extract all components (not URL)
1179 */
1180static const struct setgetcase setget_parts_list[] = {
1181 {"https://example.com/",
1182 "query=\"\",",
1183 "https | [11] | [12] | [13] | example.com | [15] | / | | [17]",
1184 0, 0, CURLU_GET_EMPTY, CURLUE_OK},
1185 {"https://example.com/",
1186 "fragment=\"\",",
1187 "https | [11] | [12] | [13] | example.com | [15] | / | [16] | ",
1188 0, 0, CURLU_GET_EMPTY, CURLUE_OK},
1189 {"https://example.com/",
1190 "query=\"\",",
1191 "https | [11] | [12] | [13] | example.com | [15] | / | [16] | [17]",
1192 0, 0, 0, CURLUE_OK},
1193 {"https://example.com",
1194 "path=get,",
1195 "https | [11] | [12] | [13] | example.com | [15] | /get | [16] | [17]",
1196 0, 0, 0, CURLUE_OK},
1197 {"https://example.com",
1198 "path=/get,",
1199 "https | [11] | [12] | [13] | example.com | [15] | /get | [16] | [17]",
1200 0, 0, 0, CURLUE_OK},
1201 {"https://example.com",
1202 "path=g e t,",
1203 "https | [11] | [12] | [13] | example.com | [15] | /g%20e%20t | "
1204 "[16] | [17]",
1205 0, CURLU_URLENCODE, 0, CURLUE_OK},
1206 {NULL, NULL, NULL, 0, 0, 0, CURLUE_OK}
1209/* !checksrc! disable SPACEBEFORECOMMA 1 */
1210static const struct setcase set_parts_list[] = {
1211 {"https://example.com/",
1212 "path=one /$!$&'()*+;=:@{}[]%,",
1213 "https://example.com/one%20/$!$&'()*+;=:@{}[]%25",
1214 0, CURLU_URLENCODE, CURLUE_OK, CURLUE_OK},
1215 {NULL, /* start fresh! */
1216 "scheme=https,path=/,url=\"\",", /* incomplete URL, redirect to "" */
1217 "https://example.com/",
1218 0, 0, CURLUE_OK, CURLUE_MALFORMED_INPUT},
1219 {NULL, /* start fresh! */
1220 "scheme=https,host=example.com,path=/,url=\"\",", /* redirect to "" */
1221 "https://example.com/",
1222 0, 0, CURLUE_OK, CURLUE_OK},
1223 {NULL, /* start fresh! */
1224 "scheme=file,", /* no path set */
1225 "file:///",
1226 0, 0, CURLUE_OK, CURLUE_OK},
1227 {"https://example.com/",
1228 "path=one\ntwo,",
1229 "https://example.com/one\ntwo",
1230 0, 0, CURLUE_OK, CURLUE_OK},
1231 {"https://example.com/",
1232 "path=one\rtwo,",
1233 "https://example.com/one\rtwo",
1234 0, 0, CURLUE_OK, CURLUE_OK},
1235 {"https://example.com/",
1236 "path=one\ntwo,",
1237 "https://example.com/one%0Atwo",
1238 0, CURLU_URLENCODE, CURLUE_OK, CURLUE_OK},
1239 {"https://example.com/",
1240 "path=one\rtwo,",
1241 "https://example.com/one%0Dtwo",
1242 0, CURLU_URLENCODE, CURLUE_OK, CURLUE_OK},
1243 {"https://example.com/",
1244 "host=%43url.se,",
1245 "https://%43url.se/",
1246 0, 0, CURLUE_OK, CURLUE_OK},
1247 {"https://example.com/",
1248 "host=%25url.se,",
1249 "",
1250 0, 0, CURLUE_OK, CURLUE_BAD_HOSTNAME},
1251 {"https://example.com/?param=value",
1252 "query=\"\",",
1253 "https://example.com/",
1254 0, CURLU_APPENDQUERY | CURLU_URLENCODE, CURLUE_OK, CURLUE_OK},
1255 {"https://example.com/",
1256 "host=\"\",",
1257 "https://example.com/",
1258 0, CURLU_URLENCODE, CURLUE_OK, CURLUE_BAD_HOSTNAME},
1259 {"https://example.com/",
1260 "host=\"\",",
1261 "https://example.com/",
1262 0, 0, CURLUE_OK, CURLUE_BAD_HOSTNAME},
1263 {"https://example.com",
1264 "path=get,",
1265 "https://example.com/get",
1266 0, 0, CURLUE_OK, CURLUE_OK},
1267 {"https://example.com/",
1268 "scheme=ftp+-.123,",
1269 "ftp+-.123://example.com/",
1270 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_OK},
1271 {"https://example.com/",
1272 "scheme=1234,",
1273 "https://example.com/",
1274 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
1275 {"https://example.com/",
1276 "scheme=1http,",
1277 "https://example.com/",
1278 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
1279 {"https://example.com/",
1280 "scheme=-ftp,",
1281 "https://example.com/",
1282 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
1283 {"https://example.com/",
1284 "scheme=+ftp,",
1285 "https://example.com/",
1286 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
1287 {"https://example.com/",
1288 "scheme=.ftp,",
1289 "https://example.com/",
1290 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
1291 {"https://example.com/",
1292 "host=example.com%2fmoo,",
1293 "",
1294 0, /* get */
1295 0, /* set */
1296 CURLUE_OK, CURLUE_BAD_HOSTNAME},
1297 {"https://example.com/",
1298 "host=http://fake,",
1299 "",
1300 0, /* get */
1301 0, /* set */
1302 CURLUE_OK, CURLUE_BAD_HOSTNAME},
1303 {"https://example.com/",
1304 "host=test%,",
1305 "",
1306 0, /* get */
1307 0, /* set */
1308 CURLUE_OK, CURLUE_BAD_HOSTNAME},
1309 {"https://example.com/",
1310 "host=te st,",
1311 "",
1312 0, /* get */
1313 0, /* set */
1314 CURLUE_OK, CURLUE_BAD_HOSTNAME},
1315 {"https://example.com/",
1316 "host=0xff,", /* '++' there is no automatic URL decode when setting this
1317 part */
1318 "https://0.0.0.255/",
1319 0, /* get */
1320 0, /* set */
1321 CURLUE_OK, CURLUE_OK},
1323 {"https://example.com/",
1324 "query=Al2cO3tDkcDZ3EWE5Lh+LX8TPHs,", /* contains '+' */
1325 "https://example.com/?Al2cO3tDkcDZ3EWE5Lh%2BLX8TPHs",
1326 CURLU_URLDECODE, /* decode on get */
1327 CURLU_URLENCODE, /* encode on set */
1328 CURLUE_OK, CURLUE_OK},
1330 {"https://example.com/",
1331 /* Set a bad scheme *including* :// */
1332 "scheme=https://,",
1333 "https://example.com/",
1334 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
1335 {"https://example.com/",
1336 /* Set a 41 bytes scheme. That is too long so the old scheme remains set. */
1337 "scheme=bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc,",
1338 "https://example.com/",
1339 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_BAD_SCHEME},
1340 {"https://example.com/",
1341 /* set a 40 bytes scheme */
1342 "scheme=bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,",
1343 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb://example.com/",
1344 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_OK},
1345 {"https://[::1%25fake]:1234/",
1346 "zoneid=NULL,",
1347 "https://[::1]:1234/",
1348 0, 0, CURLUE_OK, CURLUE_OK},
1349 {"https://example.com/",
1350 "host=[fe80::1%25eth0],",
1351 "https://[fe80::1%25eth0]/",
1352 0, 0, CURLUE_OK, CURLUE_OK},
1353 {"https://example.com/",
1354 "host=[fe80::1%25eth0],zoneid=NULL,",
1355 "https://[fe80::1]/",
1356 0, 0, CURLUE_OK, CURLUE_OK},
1357 {"https://host:1234/",
1358 "port=NULL,",
1359 "https://host/",
1360 0, 0, CURLUE_OK, CURLUE_OK},
1361 {"https://host:1234/",
1362 "port=\"\",",
1363 "https://host:1234/",
1364 0, 0, CURLUE_OK, CURLUE_BAD_PORT_NUMBER},
1365 {"https://host:1234/",
1366 "port=56 78,",
1367 "https://host:1234/",
1368 0, 0, CURLUE_OK, CURLUE_BAD_PORT_NUMBER},
1369 {"https://host:1234/",
1370 "port=0,",
1371 "https://host:0/",
1372 0, 0, CURLUE_OK, CURLUE_OK},
1373 {"https://host:1234/",
1374 "port=65535,",
1375 "https://host:65535/",
1376 0, 0, CURLUE_OK, CURLUE_OK},
1377 {"https://host:1234/",
1378 "port=65536,",
1379 "https://host:1234/",
1380 0, 0, CURLUE_OK, CURLUE_BAD_PORT_NUMBER},
1381 {"https://host/",
1382 "path=%4A%4b%4C,",
1383 "https://host/%4A%4B%4C",
1384 0, 0, CURLUE_OK, CURLUE_OK},
1385 {"https://host/mooo?q#f",
1386 "path=NULL,query=NULL,fragment=NULL,",
1387 "https://host/",
1388 0, 0, CURLUE_OK, CURLUE_OK},
1389 {"https://user:secret@host/",
1390 "user=NULL,password=NULL,",
1391 "https://host/",
1392 0, 0, CURLUE_OK, CURLUE_OK},
1393 {NULL,
1394 "scheme=https,user= @:,host=foobar,",
1395 "https://%20%20%20%40%3A@foobar/",
1396 0, CURLU_URLENCODE, CURLUE_OK, CURLUE_OK},
1397 /* Setting a hostname with spaces is not OK: */
1398 {NULL,
1399 "scheme=https,host= ,path= ,user= ,password= ,query= ,fragment= ,",
1400 "[nothing]",
1401 0, CURLU_URLENCODE, CURLUE_OK, CURLUE_BAD_HOSTNAME},
1402 {NULL,
1403 "scheme=https,host=foobar,path=/this /path /is /here,",
1404 "https://foobar/this%20/path%20/is%20/here",
1405 0, CURLU_URLENCODE, CURLUE_OK, CURLUE_OK},
1406 {NULL,
1407 "scheme=https,host=foobar,path=\xc3\xa4\xc3\xb6\xc3\xbc,",
1408 "https://foobar/%C3%A4%C3%B6%C3%BC",
1409 0, CURLU_URLENCODE, CURLUE_OK, CURLUE_OK},
1410 {"imap://user:secret;opt@host/",
1411 "options=updated,scheme=imaps,password=p4ssw0rd,",
1412 "imaps://user:p4ssw0rd;updated@host/",
1413 0, 0, CURLUE_NO_HOST, CURLUE_OK},
1414 {"imap://user:secret;optit@host/",
1415 "scheme=https,",
1416 "https://user:secret@host/",
1417 0, 0, CURLUE_NO_HOST, CURLUE_OK},
1418 {"file:///file#anchor",
1419 "scheme=https,host=example,",
1420 "https://example/file#anchor",
1421 0, 0, CURLUE_NO_HOST, CURLUE_OK},
1422 {NULL, /* start fresh! */
1423 "scheme=file,host=127.0.0.1,path=/no,user=anonymous,",
1424 "file:///no",
1425 0, 0, CURLUE_OK, CURLUE_OK},
1426 {NULL, /* start fresh! */
1427 "scheme=ftp,host=127.0.0.1,path=/no,user=anonymous,",
1428 "ftp://anonymous@127.0.0.1/no",
1429 0, 0, CURLUE_OK, CURLUE_OK},
1430 {NULL, /* start fresh! */
1431 "scheme=https,host=example.com,",
1432 "https://example.com/",
1433 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_OK},
1434 {"http://user:foo@example.com/path?query#frag",
1435 "fragment=changed,",
1436 "http://user:foo@example.com/path?query#changed",
1437 0, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK, CURLUE_OK},
1438 {"http://example.com/",
1439 "scheme=foo,", /* not accepted */
1440 "http://example.com/",
1441 0, 0, CURLUE_OK, CURLUE_UNSUPPORTED_SCHEME},
1442 {"http://example.com/",
1443 "scheme=https,path=/hello,fragment=snippet,",
1444 "https://example.com/hello#snippet",
1445 0, 0, CURLUE_OK, CURLUE_OK},
1446 {"http://example.com:80",
1447 "user=foo,port=1922,",
1448 "http://foo@example.com:1922/",
1449 0, 0, CURLUE_OK, CURLUE_OK},
1450 {"http://example.com:80",
1451 "user=foo,password=bar,",
1452 "http://foo:bar@example.com:80/",
1453 0, 0, CURLUE_OK, CURLUE_OK},
1454 {"http://example.com:80",
1455 "user=foo,",
1456 "http://foo@example.com:80/",
1457 0, 0, CURLUE_OK, CURLUE_OK},
1458 {"http://example.com",
1459 "host=www.example.com,",
1460 "http://www.example.com/",
1461 0, 0, CURLUE_OK, CURLUE_OK},
1462 {"http://example.com:80",
1463 "scheme=ftp,",
1464 "ftp://example.com:80/",
1465 0, 0, CURLUE_OK, CURLUE_OK},
1466 {"custom-scheme://host",
1467 "host=\"\",",
1468 "custom-scheme://host/",
1469 CURLU_NON_SUPPORT_SCHEME, CURLU_NON_SUPPORT_SCHEME, CURLUE_OK,
1470 CURLUE_BAD_HOSTNAME},
1471 {"custom-scheme://host",
1472 "host=\"\",",
1473 "custom-scheme:///",
1474 CURLU_NON_SUPPORT_SCHEME, CURLU_NON_SUPPORT_SCHEME | CURLU_NO_AUTHORITY,
1475 CURLUE_OK, CURLUE_OK},
1476 {"https://example.com/",
1477 "port=0,",
1478 "https://example.com:0/",
1479 0, 0, CURLUE_OK, CURLUE_OK},
1480 {"https://example.com/",
1481 "port=65535,",
1482 "https://example.com:65535/",
1483 0, 0, CURLUE_OK, CURLUE_OK},
1484 {"https://example.com/",
1485 "query=foo=bar,",
1486 "https://example.com/?foo=bar",
1487 0, CURLU_APPENDQUERY, CURLUE_OK, CURLUE_OK},
1488 {NULL, NULL, NULL, 0, 0, CURLUE_OK, CURLUE_OK}
1491static CURLUPart part2id(const char *part)
1493 if(!strcmp("url", part))
1494 return CURLUPART_URL;
1495 if(!strcmp("scheme", part))
1496 return CURLUPART_SCHEME;
1497 if(!strcmp("user", part))
1498 return CURLUPART_USER;
1499 if(!strcmp("password", part))
1500 return CURLUPART_PASSWORD;
1501 if(!strcmp("options", part))
1502 return CURLUPART_OPTIONS;
1503 if(!strcmp("host", part))
1504 return CURLUPART_HOST;
1505 if(!strcmp("port", part))
1506 return CURLUPART_PORT;
1507 if(!strcmp("path", part))
1508 return CURLUPART_PATH;
1509 if(!strcmp("query", part))
1510 return CURLUPART_QUERY;
1511 if(!strcmp("fragment", part))
1512 return CURLUPART_FRAGMENT;
1513 if(!strcmp("zoneid", part))
1514 return CURLUPART_ZONEID;
1515 /* NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange) */
1516 return (CURLUPart)9999; /* bad input => bad output */
1519static CURLUcode updateurl(CURLU *u, const char *cmd, unsigned int setflags)
1521 const char *p = cmd;
1522 CURLUcode uc;
1524 /* make sure the last command ends with a comma too! */
1525 while(p) {
1526 const char *e = strchr(p, ',');
1527 if(e) {
1528 size_t n = (size_t)(e - p);
1529 char buf[80];
1530 char part[80];
1531 char value[80];
1533 memset(part, 0, sizeof(part)); /* Avoid valgrind false positive. */
1534 memset(value, 0, sizeof(value)); /* Avoid valgrind false positive. */
1535 memcpy(buf, p, n);
1536 buf[n] = 0;
1537 /* !checksrc! disable BANNEDFUNC 1 */
1538 if(sscanf(buf, "%79[^=]=%79[^,]", part, value) == 2) {
1539 CURLUPart what = part2id(part);
1540#if 0
1541 /* for debugging this */
1542 curl_mfprintf(stderr, "%s = \"%s\" [%d]\n", part, value, what);
1543#endif
1544 if(what > CURLUPART_ZONEID)
1545 curl_mfprintf(stderr, "UNKNOWN part '%s'\n", part);
1547 if(!strcmp("NULL", value))
1548 uc = curl_url_set(u, what, NULL, setflags);
1549 else if(!strcmp("\"\"", value))
1550 uc = curl_url_set(u, what, "", setflags);
1551 else
1552 uc = curl_url_set(u, what, value, setflags);
1553 if(uc)
1554 return uc;
1556 p = e + 1;
1557 continue;
1559 break;
1561 return CURLUE_OK;
1564static const struct redircase set_url_list[] = {
1565 {"https://example.com",
1566 "", /* blank redirect */
1567 "https://example.com/",
1568 0, 0, CURLUE_OK },
1569 {"file:///test?test#test",
1570 "", "file:///test?test",
1571 0, 0, CURLUE_OK},
1572 {"https://example.com/path?query#frag",
1573 "", "https://example.com/path?query",
1574 0, 0, CURLUE_OK},
1575 {"ftp://example.com/dir/file#anchor",
1576 "", "ftp://example.com/dir/file",
1577 0, 0, CURLUE_OK},
1578 {"http://example.com/path#frag",
1579 "", "http://example.com/path",
1580 0, 0, CURLUE_OK},
1581 {"http://example.com/#frag",
1582 "", "http://example.com/",
1583 0, 0, CURLUE_OK},
1584 {"http://user:pass@example.com/path?query#frag",
1585 "", "http://user:pass@example.com/path?query",
1586 0, 0, CURLUE_OK},
1587 {"http://example.com:8080/path?query#frag",
1588 "", "http://example.com:8080/path?query",
1589 0, 0, CURLUE_OK},
1590 {"https://user:pass@example.com:8443/path?query#frag",
1591 "", "https://user:pass@example.com:8443/path?query",
1592 0, 0, CURLUE_OK},
1593 {"http://[::1]/path#frag",
1594 "", "http://[::1]/path",
1595 0, 0, CURLUE_OK},
1596 {"http://firstplace.example.com/want/1314",
1597 "//somewhere.example.com/reply/1314",
1598 "http://somewhere.example.com/reply/1314",
1599 0, 0, CURLUE_OK },
1600 {"http://127.0.0.1:46383/want?uri=http://anything/276?secondq/276",
1601 "data/2760002.txt?coolsite=http://anotherurl/?a_second/2760002",
1602 "http://127.0.0.1:46383/"
1603 "data/2760002.txt?coolsite=http://anotherurl/?a_second/2760002",
1604 0, 0, CURLUE_OK },
1605 {"file:///basic#", "#yay",
1606 "file:///basic#yay", 0, 0, CURLUE_OK},
1607 {"file:///basic", "?yay",
1608 "file:///basic?yay", 0, 0, CURLUE_OK},
1609 {"file:///basic?", "?yay",
1610 "file:///basic?yay", 0, 0, CURLUE_OK},
1611 {"file:///basic?hello", "#frag",
1612 "file:///basic?hello#frag", 0, 0, CURLUE_OK},
1613 {"file:///basic?hello", "?q",
1614 "file:///basic?q", 0, 0, CURLUE_OK},
1615 {"http://example.org#without/ash", "/moo#frag",
1616 "http://example.org/moo#frag",
1617 0, 0, CURLUE_OK},
1618 {"http://example.org/", "../path/././../././../moo",
1619 "http://example.org/moo",
1620 0, 0, CURLUE_OK},
1621 {"http://example.org/", ".%2e/path/././../%2E/./../moo",
1622 "http://example.org/moo",
1623 0, 0, CURLUE_OK},
1624 {"http://example.org/", ".%2e/path/./%2e/.%2E/%2E/./%2e%2E/moo",
1625 "http://example.org/moo",
1626 0, 0, CURLUE_OK},
1628 {"http://example.org?bar/moo", "?weird",
1629 "http://example.org/?weird", 0, 0, CURLUE_OK},
1630 {"http://example.org/foo?bar", "?weird",
1631 "http://example.org/foo?weird", 0, 0, CURLUE_OK},
1632 {"http://example.org/foo", "?weird",
1633 "http://example.org/foo?weird", 0, 0, CURLUE_OK},
1634 {"http://example.org", "?weird",
1635 "http://example.org/?weird", 0, 0, CURLUE_OK},
1636 {"http://example.org/#original", "?weird#moo",
1637 "http://example.org/?weird#moo", 0, 0, CURLUE_OK},
1639 {"http://example.org?bar/moo#yes/path", "#new/slash",
1640 "http://example.org/?bar/moo#new/slash", 0, 0, CURLUE_OK},
1641 {"http://example.org/foo?bar", "#weird",
1642 "http://example.org/foo?bar#weird", 0, 0, CURLUE_OK},
1643 {"http://example.org/foo?bar#original", "#weird",
1644 "http://example.org/foo?bar#weird", 0, 0, CURLUE_OK},
1645 {"http://example.org/foo#original", "#weird",
1646 "http://example.org/foo#weird", 0, 0, CURLUE_OK},
1647 {"http://example.org/#original", "#weird",
1648 "http://example.org/#weird", 0, 0, CURLUE_OK},
1649 {"http://example.org#original", "#weird",
1650 "http://example.org/#weird", 0, 0, CURLUE_OK},
1651 {"http://example.org/foo?bar", "moo?hey#weird",
1652 "http://example.org/moo?hey#weird", 0, 0, CURLUE_OK},
1653 {"http://example.org/",
1654 "../path/././../../moo",
1655 "http://example.org/moo",
1656 0, 0, CURLUE_OK},
1657 {"http://example.org/",
1658 "//example.org/../path/../../",
1659 "http://example.org/",
1660 0, 0, CURLUE_OK},
1661 {"http://example.org/",
1662 "///example.org/../path/../../",
1663 "http://example.org/",
1664 0, 0, CURLUE_OK},
1665 {"http://example.org/foo/bar",
1666 ":23",
1667 "http://example.org/foo/:23",
1668 0, 0, CURLUE_OK},
1669 {"http://example.org/foo/bar",
1670 "\\x",
1671 "http://example.org/foo/\\x",
1672 /* WHATWG disagrees */
1673 0, 0, CURLUE_OK},
1674 {"http://example.org/foo/bar",
1675 "#/",
1676 "http://example.org/foo/bar#/",
1677 0, 0, CURLUE_OK},
1678 {"http://example.org/foo/bar",
1679 "?/",
1680 "http://example.org/foo/bar?/",
1681 0, 0, CURLUE_OK},
1682 {"http://example.org/foo/bar",
1683 "#;?",
1684 "http://example.org/foo/bar#;?",
1685 0, 0, CURLUE_OK},
1686 {"http://example.org/foo/bar",
1687 "#",
1688 "http://example.org/foo/bar#",
1689 0, 0, CURLUE_OK},
1690 {"http://example.org/foo/bar",
1691 "?",
1692 "http://example.org/foo/bar?",
1693 0, 0, CURLUE_OK},
1694 {"http://example.org/foo/bar",
1695 "?#",
1696 "http://example.org/foo/bar?#",
1697 0, 0, CURLUE_OK},
1698 {"http://host/path?", "#new",
1699 "http://host/path?#new", 0, 0, CURLUE_OK},
1700 {"http://host/path?#", "#new",
1701 "http://host/path?#new", 0, 0, CURLUE_OK},
1702 {"http://host/path#", "?new",
1703 "http://host/path?new", 0, 0, CURLUE_OK},
1704 {"http://host/path?#", "?new",
1705 "http://host/path?new", 0, 0, CURLUE_OK},
1706 {"http://host/path?#", "sub",
1707 "http://host/sub", 0, 0, CURLUE_OK},
1708 {"http://example.com/please/../gimme/%TESTNUMBER?foobar#hello",
1709 "http://example.net/there/it/is/../../tes t case=/%TESTNUMBER0002? yes no",
1710 "http://example.net/there/tes%20t%20case=/%TESTNUMBER0002?+yes+no",
1711 0, CURLU_URLENCODE | CURLU_ALLOW_SPACE, CURLUE_OK},
1712 {"http://local.test?redirect=http://local.test:80?-321",
1713 "http://local.test:80?-123",
1714 "http://local.test:80/?-123",
1715 0, CURLU_URLENCODE | CURLU_ALLOW_SPACE, CURLUE_OK},
1716 {"http://local.test?redirect=http://local.test:80?-321",
1717 "http://local.test:80?-123",
1718 "http://local.test:80/?-123",
1719 0, 0, CURLUE_OK},
1720 {"http://example.org/static/favicon/wikipedia.ico",
1721 "//fake.example.com/licenses/by-sa/3.0/",
1722 "http://fake.example.com/licenses/by-sa/3.0/",
1723 0, 0, CURLUE_OK},
1724 {"https://example.org/static/favicon/wikipedia.ico",
1725 "//fake.example.com/licenses/by-sa/3.0/",
1726 "https://fake.example.com/licenses/by-sa/3.0/",
1727 0, 0, CURLUE_OK},
1728 {"file://localhost/path?query#frag",
1729 "foo#another",
1730 "file:///foo#another",
1731 0, 0, CURLUE_OK},
1732 {"http://example.com/path?query#frag",
1733 "https://two.example.com/bradnew",
1734 "https://two.example.com/bradnew",
1735 0, 0, CURLUE_OK},
1736 {"http://example.com/path?query#frag",
1737 "../../newpage#foo",
1738 "http://example.com/newpage#foo",
1739 0, 0, CURLUE_OK},
1740 {"http://user:foo@example.com/path?query#frag",
1741 "../../newpage",
1742 "http://user:foo@example.com/newpage",
1743 0, 0, CURLUE_OK},
1744 {"http://user:foo@example.com/path?query#frag",
1745 "../newpage",
1746 "http://user:foo@example.com/newpage",
1747 0, 0, CURLUE_OK},
1748 {"http://user:foo@example.com/path?query#frag",
1749 "http://?hi",
1750 "http:///?hi",
1751 0, CURLU_NO_AUTHORITY, CURLUE_OK},
1752 {"http://host/path", "?query", "http://host/path?query", 0, 0, CURLUE_OK},
1753 {"http://host/path", "#frag", "http://host/path#frag", 0, 0, CURLUE_OK},
1754 {NULL, NULL, NULL, 0, 0, CURLUE_OK}
1757#ifdef USE_IDN
1759struct idncase {
1760 const char *in;
1761 const char *out;
1762 CURLUcode ucode;
1765/* set the URL, extract it punycoded, check the return code */
1766static const struct idncase set_idn_url[] = {
1767 /* Fullwidth commercial at */
1768 { "https://trusted.example\xef\xbc\xa0" "evil.example/",
1769 NULL, CURLUE_BAD_HOSTNAME },
1770 /* Black question mark ornament (looks like a question mark)*/
1771 { "https://bad\xE2\x9D\x93" "host.example/",
1772 "https://xn--badhost-458d.example/", CURLUE_OK },
1773 /* Division Slash (looks like a slash) */
1774 { "https://bad\xE2\x88\x95" "host.example/",
1775 "https://xn--badhost-ef0d.example/", CURLUE_OK },
1776 /* Fullwidth Solidus (looks like a slash) */
1777 { "https://bad\xef\xbc\x8f" "host.example/",
1778 NULL, CURLUE_BAD_HOSTNAME},
1779 /* Fullwidth Stop (looks like a period) */
1780 { "https://bad\xef\xbc\x8e" "host.example/",
1781 "https://bad.host.example/", CURLUE_OK},
1784static int set_idn(void)
1786 unsigned int i;
1787 int error = 0;
1789 for(i = 0; i < CURL_ARRAYSIZE(set_idn_url) && !error; i++) {
1790 CURLUcode rc;
1791 char *url;
1792 CURLU *urlp = curl_url();
1793 if(!urlp) {
1794 error++;
1795 break;
1797 rc = curl_url_set(urlp, CURLUPART_URL, set_idn_url[i].in, 0);
1798 if(rc) {
1799 curl_mfprintf(stderr, "%s:%d Set URL returned %d (%s)\n",
1800 __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
1801 error++;
1804 rc = curl_url_get(urlp, CURLUPART_URL, &url, CURLU_PUNYCODE);
1805 if(rc != set_idn_url[i].ucode) {
1806 curl_mfprintf(stderr, "Get IDN URL\nin: %s\nreturned %d (expected %d)\n",
1807 set_idn_url[i].in, (int)rc, (int)set_idn_url[i].ucode);
1808 error++;
1810 else if(!url || !set_idn_url[i].out) {
1811 if(url) {
1812 curl_mfprintf(stderr, "Got IDN URL (%s) when expected none\n",
1813 url);
1814 error++;
1816 else if(set_idn_url[i].out) {
1817 curl_mfprintf(stderr, "Got no IDN URL when expected %s\n",
1818 set_idn_url[i].out);
1819 error++;
1822 else if(strcmp(url, set_idn_url[i].out)) {
1823 curl_mfprintf(stderr, "Got IDN URL: %s\nexpected %s\n",
1824 url, set_idn_url[i].out);
1825 error++;
1827 curl_free(url);
1828 curl_url_cleanup(urlp);
1830 return error;
1832#else
1833#define set_idn() 0
1834#endif
1836static int set_url(void)
1838 int i;
1839 int error = 0;
1841 for(i = 0; set_url_list[i].in && !error; i++) {
1842 CURLUcode rc;
1843 CURLU *urlp = curl_url();
1844 if(!urlp) {
1845 error++;
1846 break;
1848 rc = curl_url_set(urlp, CURLUPART_URL, set_url_list[i].in,
1849 set_url_list[i].urlflags);
1850 if(!rc) {
1851 rc = curl_url_set(urlp, CURLUPART_URL, set_url_list[i].set,
1852 set_url_list[i].setflags);
1853 if(rc) {
1854 curl_mfprintf(stderr, "%s:%d Set URL %s returned %d (%s)\n",
1855 __FILE__, __LINE__, set_url_list[i].set,
1856 (int)rc, curl_url_strerror(rc));
1857 error++;
1859 else {
1860 char *url = NULL;
1861 rc = curl_url_get(urlp, CURLUPART_URL, &url, CURLU_GET_EMPTY);
1862 if(rc) {
1863 curl_mfprintf(stderr, "%s:%d Get URL returned %d (%s)\n",
1864 __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
1865 error++;
1867 else if(checkurl(set_url_list[i].in, url, set_url_list[i].out)) {
1868 error++;
1870 curl_free(url);
1873 else if(rc != set_url_list[i].ucode) {
1874 curl_mfprintf(stderr, "Set URL\nin: %s\nreturned %d (expected %d)\n",
1875 set_url_list[i].in, (int)rc, (int)set_url_list[i].ucode);
1876 error++;
1878 curl_url_cleanup(urlp);
1880 return error;
1883/* 1. Set a URL
1884 2. Set one or more parts
1885 3. Extract and compare all parts - not the URL
1886 */
1887static int setget_parts(bool has_utf8)
1889 int i;
1890 int error = 0;
1892 for(i = 0; setget_parts_list[i].set && !error; i++) {
1893 CURLU *urlp = curl_url();
1894 if(!urlp) {
1895 error++;
1896 break;
1898 if((setget_parts_list[i].getflags != CURLU_PUNYCODE &&
1899 setget_parts_list[i].getflags != CURLU_PUNY2IDN) || has_utf8) {
1900 CURLUcode rc;
1901 if(setget_parts_list[i].in)
1902 rc = curl_url_set(urlp, CURLUPART_URL, setget_parts_list[i].in,
1903 setget_parts_list[i].urlflags);
1904 else
1905 rc = CURLUE_OK;
1906 if(!rc) {
1907 CURLUcode uc = updateurl(urlp, setget_parts_list[i].set,
1908 setget_parts_list[i].setflags);
1910 if(uc != setget_parts_list[i].pcode) {
1911 curl_mfprintf(stderr,
1912 "updateurl\nin: %s\nreturned %d (expected %d)\n",
1913 setget_parts_list[i].set,
1914 (int)uc, (int)setget_parts_list[i].pcode);
1915 error++;
1917 if(!uc && checkparts(urlp,
1918 setget_parts_list[i].set,
1919 setget_parts_list[i].out,
1920 setget_parts_list[i].getflags))
1921 error++; /* add */
1923 else if(rc != CURLUE_OK) {
1924 curl_mfprintf(stderr, "Set parts\nin: %s\nreturned %d (expected %d)\n",
1925 setget_parts_list[i].in, (int)rc, 0);
1926 error++;
1929 curl_url_cleanup(urlp);
1931 return error;
1934static int set_parts(void)
1936 int i;
1937 int error = 0;
1939 for(i = 0; set_parts_list[i].set && !error; i++) {
1940 CURLUcode rc;
1941 CURLU *urlp = curl_url();
1942 if(!urlp) {
1943 error++;
1944 break;
1946 if(set_parts_list[i].in)
1947 rc = curl_url_set(urlp, CURLUPART_URL, set_parts_list[i].in,
1948 set_parts_list[i].urlflags);
1949 else
1950 rc = CURLUE_OK;
1951 if(!rc) {
1952 char *url = NULL;
1953 CURLUcode uc = updateurl(urlp, set_parts_list[i].set,
1954 set_parts_list[i].setflags);
1956 if(uc != set_parts_list[i].pcode) {
1957 curl_mfprintf(stderr, "updateurl\nin: %s\nreturned %d (expected %d)\n",
1958 set_parts_list[i].set,
1959 (int)uc, (int)set_parts_list[i].pcode);
1960 error++;
1962 if(!uc) {
1963 /* only do this if it worked */
1964 rc = curl_url_get(urlp, CURLUPART_URL, &url, 0);
1965 if(rc) {
1966 curl_mfprintf(stderr, "%s:%d Get URL returned %d (%s)\n",
1967 __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
1968 error++;
1970 else if(checkurl(set_parts_list[i].in, url, set_parts_list[i].out)) {
1971 error++;
1974 curl_free(url);
1976 else if(rc != set_parts_list[i].ucode) {
1977 curl_mfprintf(stderr, "Set parts\nin: %s\nreturned %d (expected %d)\n",
1978 set_parts_list[i].in,
1979 (int)rc, (int)set_parts_list[i].ucode);
1980 error++;
1982 curl_url_cleanup(urlp);
1984 return error;
1987static int get_url(bool has_utf8)
1989 int i;
1990 int error = 0;
1991 for(i = 0; get_url_list[i].in && !error; i++) {
1992 CURLU *urlp = curl_url();
1993 if(!urlp) {
1994 error++;
1995 break;
1997 if((get_url_list[i].getflags != CURLU_PUNYCODE &&
1998 get_url_list[i].getflags != CURLU_PUNY2IDN) || has_utf8) {
1999 CURLUcode rc;
2000 rc = curl_url_set(urlp, CURLUPART_URL, get_url_list[i].in,
2001 get_url_list[i].urlflags);
2002 if(!rc) {
2003 char *url = NULL;
2004 rc = curl_url_get(urlp, CURLUPART_URL, &url, get_url_list[i].getflags);
2005 if(rc) {
2006 curl_mfprintf(stderr, "%s:%d returned %d (%s). URL: '%s'\n",
2007 __FILE__, __LINE__, (int)rc, curl_url_strerror(rc),
2008 get_url_list[i].in);
2009 error++;
2011 else if(checkurl(get_url_list[i].in, url, get_url_list[i].out)) {
2012 error++;
2014 curl_free(url);
2016 if(rc != get_url_list[i].ucode) {
2017 curl_mfprintf(stderr, "Get URL\nin: %s\nreturned %d (expected %d)\n",
2018 get_url_list[i].in, (int)rc, (int)get_url_list[i].ucode);
2019 error++;
2022 curl_url_cleanup(urlp);
2024 return error;
2027static int get_parts(bool has_utf8)
2029 int i;
2030 int error = 0;
2031 for(i = 0; get_parts_list[i].in && !error; i++) {
2032 CURLU *urlp = curl_url();
2033 if(!urlp) {
2034 error++;
2035 break;
2037 if((get_parts_list[i].getflags != CURLU_PUNYCODE &&
2038 get_parts_list[i].getflags != CURLU_PUNY2IDN) || has_utf8) {
2039 CURLUcode rc;
2040 rc = curl_url_set(urlp, CURLUPART_URL,
2041 get_parts_list[i].in,
2042 get_parts_list[i].urlflags);
2043 if(rc != get_parts_list[i].ucode) {
2044 curl_mfprintf(stderr, "Get parts\nin: %s\nreturned %d (expected %d)\n",
2045 get_parts_list[i].in,
2046 (int)rc, (int)get_parts_list[i].ucode);
2047 error++;
2049 else if(get_parts_list[i].ucode) {
2050 /* the expected error happened */
2052 else if(checkparts(urlp, get_parts_list[i].in, get_parts_list[i].out,
2053 get_parts_list[i].getflags))
2054 error++;
2056 curl_url_cleanup(urlp);
2058 return error;
2061static const struct querycase append_list[] = {
2062 {"HTTP://test/?s", "name=joe\x02", "http://test/?s&name=joe%02",
2063 0, CURLU_URLENCODE, CURLUE_OK},
2064 {"HTTP://test/?size=2#f", "name=joe=", "http://test/?size=2&name=joe%3D#f",
2065 0, CURLU_URLENCODE, CURLUE_OK},
2066 {"HTTP://test/?size=2#f", "name=joe doe",
2067 "http://test/?size=2&name=joe+doe#f",
2068 0, CURLU_URLENCODE, CURLUE_OK},
2069 {"HTTP://test/", "name=joe", "http://test/?name=joe", 0, 0, CURLUE_OK},
2070 {"HTTP://test/?size=2", "name=joe", "http://test/?size=2&name=joe",
2071 0, 0, CURLUE_OK},
2072 {"HTTP://test/?size=2&", "name=joe", "http://test/?size=2&name=joe",
2073 0, 0, CURLUE_OK},
2074 {"HTTP://test/?size=2#f", "name=joe", "http://test/?size=2&name=joe#f",
2075 0, 0, CURLUE_OK},
2076 {NULL, NULL, NULL, 0, 0, CURLUE_OK}
2079static int append(void)
2081 int i;
2082 int error = 0;
2083 for(i = 0; append_list[i].in && !error; i++) {
2084 CURLUcode rc;
2085 CURLU *urlp = curl_url();
2086 if(!urlp) {
2087 error++;
2088 break;
2090 rc = curl_url_set(urlp, CURLUPART_URL,
2091 append_list[i].in,
2092 append_list[i].urlflags);
2093 if(rc)
2094 error++;
2095 else
2096 rc = curl_url_set(urlp, CURLUPART_QUERY,
2097 append_list[i].q,
2098 append_list[i].qflags | CURLU_APPENDQUERY);
2099 if(error)
2101 else if(rc != append_list[i].ucode) {
2102 curl_mfprintf(stderr, "Append\nin: %s\nreturned %d (expected %d)\n",
2103 append_list[i].in, (int)rc, (int)append_list[i].ucode);
2104 error++;
2106 else if(append_list[i].ucode) {
2107 /* the expected error happened */
2109 else {
2110 char *url;
2111 rc = curl_url_get(urlp, CURLUPART_URL, &url, 0);
2112 if(rc) {
2113 curl_mfprintf(stderr, "%s:%d Get URL returned %d (%s)\n",
2114 __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
2115 error++;
2117 else {
2118 if(checkurl(append_list[i].in, url, append_list[i].out)) {
2119 error++;
2121 curl_free(url);
2124 curl_url_cleanup(urlp);
2126 return error;
2129static int scopeid(void)
2131 CURLU *u = curl_url();
2132 int error = 0;
2133 CURLUcode rc;
2134 char *url;
2135 if(!u)
2136 return 1;
2138 rc = curl_url_set(u, CURLUPART_URL,
2139 "https://[fe80::20c:29ff:fe9c:409b%25eth0]/hello.html", 0);
2140 if(rc != CURLUE_OK) {
2141 curl_mfprintf(stderr, "%s:%d curl_url_set returned %d (%s)\n",
2142 __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
2143 error++;
2146 rc = curl_url_get(u, CURLUPART_HOST, &url, 0);
2147 if(rc != CURLUE_OK) {
2148 curl_mfprintf(stderr,
2149 "%s:%d curl_url_get CURLUPART_HOST returned %d (%s)\n",
2150 __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
2151 error++;
2153 else {
2154 curl_free(url);
2157 rc = curl_url_set(u, CURLUPART_HOST, "[::1]", 0);
2158 if(rc != CURLUE_OK) {
2159 curl_mfprintf(stderr,
2160 "%s:%d curl_url_set CURLUPART_HOST returned %d (%s)\n",
2161 __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
2162 error++;
2165 rc = curl_url_get(u, CURLUPART_URL, &url, 0);
2166 if(rc != CURLUE_OK) {
2167 curl_mfprintf(stderr,
2168 "%s:%d curl_url_get CURLUPART_URL returned %d (%s)\n",
2169 __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
2170 error++;
2172 else {
2173 curl_free(url);
2176 rc = curl_url_set(u, CURLUPART_HOST, "example.com", 0);
2177 if(rc != CURLUE_OK) {
2178 curl_mfprintf(stderr,
2179 "%s:%d curl_url_set CURLUPART_HOST returned %d (%s)\n",
2180 __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
2181 error++;
2184 rc = curl_url_get(u, CURLUPART_URL, &url, 0);
2185 if(rc != CURLUE_OK) {
2186 curl_mfprintf(stderr,
2187 "%s:%d curl_url_get CURLUPART_URL returned %d (%s)\n",
2188 __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
2189 error++;
2191 else {
2192 curl_free(url);
2195 rc = curl_url_set(u, CURLUPART_HOST, "[fe80::20c:29ff:fe9c:409b%25eth0]", 0);
2196 if(rc != CURLUE_OK) {
2197 curl_mfprintf(stderr,
2198 "%s:%d curl_url_set CURLUPART_HOST returned %d (%s)\n",
2199 __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
2200 error++;
2203 rc = curl_url_get(u, CURLUPART_URL, &url, 0);
2204 if(rc != CURLUE_OK) {
2205 curl_mfprintf(stderr,
2206 "%s:%d curl_url_get CURLUPART_URL returned %d (%s)\n",
2207 __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
2208 error++;
2210 else {
2211 curl_free(url);
2214 rc = curl_url_get(u, CURLUPART_HOST, &url, 0);
2215 if(rc != CURLUE_OK) {
2216 curl_mfprintf(stderr,
2217 "%s:%d curl_url_get CURLUPART_HOST returned %d (%s)\n",
2218 __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
2219 error++;
2221 else {
2222 curl_free(url);
2225 rc = curl_url_get(u, CURLUPART_ZONEID, &url, 0);
2226 if(rc != CURLUE_OK) {
2227 curl_mfprintf(stderr,
2228 "%s:%d curl_url_get CURLUPART_ZONEID returned %d (%s)\n",
2229 __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
2230 error++;
2232 else {
2233 curl_free(url);
2236 rc = curl_url_set(u, CURLUPART_ZONEID, "clown", 0);
2237 if(rc != CURLUE_OK) {
2238 curl_mfprintf(stderr,
2239 "%s:%d curl_url_set CURLUPART_ZONEID returned %d (%s)\n",
2240 __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
2241 error++;
2244 rc = curl_url_get(u, CURLUPART_URL, &url, 0);
2245 if(rc != CURLUE_OK) {
2246 curl_mfprintf(stderr,
2247 "%s:%d curl_url_get CURLUPART_URL returned %d (%s)\n",
2248 __FILE__, __LINE__, (int)rc, curl_url_strerror(rc));
2249 error++;
2251 else {
2252 curl_free(url);
2255 curl_url_cleanup(u);
2257 return error;
2260static int get_nothing(void)
2262 CURLU *u = curl_url();
2263 int error = 0;
2264 CURLUcode rc;
2265 char *p = NULL;
2266 if(!u)
2267 return 1;
2269 rc = curl_url_get(u, CURLUPART_SCHEME, &p, 0);
2270 if(rc != CURLUE_NO_SCHEME) {
2271 curl_mfprintf(stderr, "unexpected return code line %d\n", __LINE__);
2272 error++;
2273 curl_free(p);
2276 rc = curl_url_get(u, CURLUPART_HOST, &p, 0);
2277 if(rc != CURLUE_NO_HOST) {
2278 curl_mfprintf(stderr, "unexpected return code line %d\n", __LINE__);
2279 error++;
2280 curl_free(p);
2283 rc = curl_url_get(u, CURLUPART_USER, &p, 0);
2284 if(rc != CURLUE_NO_USER) {
2285 curl_mfprintf(stderr, "unexpected return code line %d\n", __LINE__);
2286 error++;
2287 curl_free(p);
2290 rc = curl_url_get(u, CURLUPART_PASSWORD, &p, 0);
2291 if(rc != CURLUE_NO_PASSWORD) {
2292 curl_mfprintf(stderr, "unexpected return code line %d\n", __LINE__);
2293 error++;
2294 curl_free(p);
2297 rc = curl_url_get(u, CURLUPART_OPTIONS, &p, 0);
2298 if(rc != CURLUE_NO_OPTIONS) {
2299 curl_mfprintf(stderr, "unexpected return code line %d\n", __LINE__);
2300 error++;
2301 curl_free(p);
2304 rc = curl_url_get(u, CURLUPART_PATH, &p, 0);
2305 if(rc != CURLUE_OK) {
2306 curl_mfprintf(stderr, "unexpected return code line %d\n", __LINE__);
2307 error++;
2309 else
2310 curl_free(p);
2312 rc = curl_url_get(u, CURLUPART_QUERY, &p, 0);
2313 if(rc != CURLUE_NO_QUERY) {
2314 curl_mfprintf(stderr, "unexpected return code line %d\n", __LINE__);
2315 error++;
2316 curl_free(p);
2319 rc = curl_url_get(u, CURLUPART_FRAGMENT, &p, 0);
2320 if(rc != CURLUE_NO_FRAGMENT) {
2321 curl_mfprintf(stderr, "unexpected return code line %d\n", __LINE__);
2322 error++;
2323 curl_free(p);
2326 rc = curl_url_get(u, CURLUPART_ZONEID, &p, 0);
2327 if(rc != CURLUE_NO_ZONEID) {
2328 curl_mfprintf(stderr, "unexpected return code %d on line %d\n", (int)rc,
2329 __LINE__);
2330 error++;
2331 curl_free(p);
2334 curl_url_cleanup(u);
2336 return error;
2339static const struct clearurlcase clear_url_list[] = {
2340 { CURLUPART_SCHEME, "http", NULL, CURLUE_NO_SCHEME },
2341 { CURLUPART_USER, "user", NULL, CURLUE_NO_USER },
2342 { CURLUPART_PASSWORD, "password", NULL, CURLUE_NO_PASSWORD },
2343 { CURLUPART_OPTIONS, "options", NULL, CURLUE_NO_OPTIONS },
2344 { CURLUPART_HOST, "host", NULL, CURLUE_NO_HOST },
2345 { CURLUPART_ZONEID, "eth0", NULL, CURLUE_NO_ZONEID },
2346 { CURLUPART_PORT, "1234", NULL, CURLUE_NO_PORT },
2347 { CURLUPART_PATH, "/hello", "/", CURLUE_OK },
2348 { CURLUPART_QUERY, "a=b", NULL, CURLUE_NO_QUERY },
2349 { CURLUPART_FRAGMENT, "anchor", NULL, CURLUE_NO_FRAGMENT },
2350 { CURLUPART_URL, NULL, NULL, CURLUE_OK },
2353static int clear_url(void)
2355 CURLU *u = curl_url();
2356 int i, error = 0;
2357 CURLUcode rc;
2358 char *p = NULL;
2359 if(!u)
2360 return 1;
2362 for(i = 0; clear_url_list[i].in && !error; i++) {
2363 rc = curl_url_set(u, clear_url_list[i].part, clear_url_list[i].in, 0);
2364 if(rc != CURLUE_OK) {
2365 curl_mfprintf(stderr, "unexpected return code line %d\n", __LINE__);
2366 error++;
2369 rc = curl_url_set(u, CURLUPART_URL, NULL, 0);
2370 if(rc != CURLUE_OK) {
2371 curl_mfprintf(stderr, "unexpected return code line %d\n", __LINE__);
2372 error++;
2375 rc = curl_url_get(u, clear_url_list[i].part, &p, 0);
2376 if(rc != clear_url_list[i].ucode ||
2377 (p && clear_url_list[i].out && strcmp(p, clear_url_list[i].out))) {
2379 curl_mfprintf(stderr, "unexpected return code line %d\n", __LINE__);
2380 error++;
2382 if(rc == CURLUE_OK)
2383 curl_free(p);
2386 curl_url_cleanup(u);
2388 return error;
2391static char total[128000];
2392static char bigpart[120000];
2395 * verify ridiculous URL part sizes
2396 */
2397static int huge(void)
2399 static const char smallpart[] = "c";
2400 int i;
2401 CURLU *urlp = curl_url();
2402 CURLUcode rc;
2403 CURLUPart part[] = {
2404 CURLUPART_SCHEME,
2405 CURLUPART_USER,
2406 CURLUPART_PASSWORD,
2407 CURLUPART_HOST,
2408 CURLUPART_PATH,
2409 CURLUPART_QUERY,
2410 CURLUPART_FRAGMENT
2411 };
2412 int error = 0;
2413 if(!urlp)
2414 return 1;
2415 bigpart[0] = '/'; /* for the path */
2416 memset(&bigpart[1], 'a', sizeof(bigpart) - 2);
2417 bigpart[sizeof(bigpart) - 1] = 0;
2419 for(i = 0; i < 7; i++) {
2420 char *partp;
2421 curl_msnprintf(total, sizeof(total),
2422 "%s://%s:%s@%s/%s?%s#%s",
2423 (i == 0) ? &bigpart[1] : smallpart,
2424 (i == 1) ? &bigpart[1] : smallpart,
2425 (i == 2) ? &bigpart[1] : smallpart,
2426 (i == 3) ? &bigpart[1] : smallpart,
2427 (i == 4) ? &bigpart[1] : smallpart,
2428 (i == 5) ? &bigpart[1] : smallpart,
2429 (i == 6) ? &bigpart[1] : smallpart);
2430 rc = curl_url_set(urlp, CURLUPART_URL, total, CURLU_NON_SUPPORT_SCHEME);
2431 if((!i && (rc != CURLUE_BAD_SCHEME)) ||
2432 (i && rc)) {
2433 curl_mprintf("URL %d: failed to parse [%s]\n", i, total);
2434 error++;
2437 /* only extract if the parse worked */
2438 if(!rc) {
2439 curl_url_get(urlp, part[i], &partp, 0);
2440 if(!partp || strcmp(partp, &bigpart[1 - (i == 4)])) {
2441 curl_mprintf("URL %d part %d: failure\n", i, (int)part[i]);
2442 error++;
2444 curl_free(partp);
2447 curl_url_cleanup(urlp);
2448 return error;
2451static int urldup(void)
2453 static const char * const url[] = {
2454 "http://"
2455 "user:pwd@"
2456 "[2a04:4e42:e00::347%25eth0]"
2457 ":80"
2458 "/path"
2459 "?query"
2460 "#fraggie",
2461 "https://example.com",
2462 "https://user@example.com",
2463 "https://user.pwd@example.com",
2464 "https://user.pwd@example.com:1234",
2465 "https://example.com:1234",
2466 "example.com:1234",
2467 "https://user.pwd@example.com:1234/path?query#frag",
2468 NULL
2469 };
2470 CURLU *copy = NULL;
2471 char *h_str = NULL, *copy_str = NULL;
2472 CURLU *h = curl_url();
2473 int i;
2475 if(!h)
2476 goto err;
2478 for(i = 0; url[i]; i++) {
2479 CURLUcode rc = curl_url_set(h, CURLUPART_URL, url[i], CURLU_GUESS_SCHEME);
2480 if(rc)
2481 goto err;
2482 copy = curl_url_dup(h);
2484 rc = curl_url_get(h, CURLUPART_URL, &h_str, 0);
2485 if(rc)
2486 goto err;
2488 rc = curl_url_get(copy, CURLUPART_URL, &copy_str, 0);
2489 if(rc)
2490 goto err;
2492 if(strcmp(h_str, copy_str)) {
2493 curl_mprintf("Original: %s\nParsed: %s\nCopy: %s\n",
2494 url[i], h_str, copy_str);
2495 goto err;
2497 curl_free(copy_str);
2498 curl_free(h_str);
2499 curl_url_cleanup(copy);
2500 copy_str = NULL;
2501 h_str = NULL;
2502 copy = NULL;
2504 curl_url_cleanup(h);
2505 return 0;
2506err:
2507 curl_free(copy_str);
2508 curl_free(h_str);
2509 curl_url_cleanup(copy);
2510 curl_url_cleanup(h);
2511 return 1;
2514static int test_api_errors(void)
2516 CURLU *u = curl_url();
2517 char *p = NULL;
2518 CURLUcode rc;
2519 if(!u)
2520 return 1;
2522 /* NULL handle */
2523 rc = curl_url_get(NULL, CURLUPART_URL, &p, 0);
2524 if(rc != CURLUE_BAD_HANDLE)
2525 return 1;
2527 rc = curl_url_set(NULL, CURLUPART_URL, "http://example.com", 0);
2528 if(rc != CURLUE_BAD_HANDLE)
2529 return 1;
2531 if(curl_url_dup(NULL))
2532 return 4;
2534 /* NULL part pointer */
2535 rc = curl_url_get(u, CURLUPART_URL, NULL, 0);
2536 if(rc != CURLUE_BAD_PARTPOINTER)
2537 return 2;
2539 /* Unknown part */
2540 /* NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange) */
2541 rc = curl_url_get(u, (CURLUPart)12345, &p, 0);
2542 if(rc != CURLUE_UNKNOWN_PART)
2543 return 3;
2545 curl_url_cleanup(u);
2546 return 0;
2549struct guessscheme1560 {
2550 const char *url;
2551 bool expectedfail; /* the URL should fail to parse */
2552 unsigned int setflags;
2553 const char *scheme;
2554 unsigned int getflags;
2557static int test_scheme_guess(void)
2559 const struct guessscheme1560 g[] = {
2560 { "https://example.com", FALSE, 0, "https", 0 },
2561 { "example.com", TRUE, 0, NULL, 0 },
2562 { "example.com", FALSE, CURLU_GUESS_SCHEME, "http", 0 },
2563 { "ftp.example.com:22", FALSE, CURLU_GUESS_SCHEME, "ftp", 0 },
2564 { "ftp.example.com/foo", FALSE, CURLU_GUESS_SCHEME,
2565 NULL, CURLU_NO_GUESS_SCHEME },
2566 { "dict.example.com:33", FALSE, CURLU_GUESS_SCHEME, "dict", 0 },
2567 { "dict.example.com/bar", FALSE, CURLU_GUESS_SCHEME,
2568 NULL, CURLU_NO_GUESS_SCHEME },
2569 { "ldap.example.com#none", FALSE, CURLU_GUESS_SCHEME, "ldap", 0 },
2570 { "ldap.example.com?special", FALSE, CURLU_GUESS_SCHEME,
2571 NULL, CURLU_NO_GUESS_SCHEME },
2572 { "smtp.example.com?hey#ho", FALSE, CURLU_GUESS_SCHEME, "smtp", 0 },
2573 { "smtp.example.com:99/moo", FALSE, CURLU_GUESS_SCHEME,
2574 NULL, CURLU_NO_GUESS_SCHEME },
2575 { "pop3.example.com:100#foobar", FALSE, CURLU_GUESS_SCHEME, "pop3", 0 },
2576 { "pop3.example.com:101?gg", FALSE, CURLU_GUESS_SCHEME,
2577 NULL, CURLU_NO_GUESS_SCHEME },
2578 { "example.com", FALSE, CURLU_GUESS_SCHEME, NULL, CURLU_NO_GUESS_SCHEME },
2579 { "https://example.com", FALSE, CURLU_GUESS_SCHEME,
2580 "https", CURLU_NO_GUESS_SCHEME },
2581 { "foobar://example.com", FALSE,
2582 CURLU_GUESS_SCHEME|CURLU_NON_SUPPORT_SCHEME,
2583 "foobar", CURLU_NO_GUESS_SCHEME },
2584 { "foobar://example.com", FALSE, CURLU_NON_SUPPORT_SCHEME,
2585 "foobar", CURLU_NO_GUESS_SCHEME },
2586 { "foobar://example.com", FALSE, CURLU_NON_SUPPORT_SCHEME, "foobar", 0 },
2587 };
2588 int error = 0;
2589 unsigned int i;
2590 for(i = 0; i < CURL_ARRAYSIZE(g) && !error; i++) {
2591 CURLU *u = curl_url();
2592 char *schemep = NULL;
2593 if(u) {
2594 int rc = curl_url_set(u, CURLUPART_URL, g[i].url, g[i].setflags);
2595 if(!rc) {
2596 rc = curl_url_get(u, CURLUPART_SCHEME, &schemep, g[i].getflags);
2597 if(!rc && !schemep) {
2598 curl_mfprintf(stderr, "%u: returned success but no scheme\n", i);
2599 error++;
2601 else if(rc && schemep) {
2602 curl_mfprintf(stderr, "%u: returned error but with scheme\n", i);
2603 error++;
2606 else if(!g[i].expectedfail) {
2607 curl_mfprintf(stderr, "%u: URL parsing failed unexpectedly\n", i);
2608 error++;
2611 if(!schemep && g[i].scheme) {
2612 curl_mfprintf(stderr, "%u: got no scheme when %s was expected\n", i,
2613 g[i].scheme);
2614 error++;
2616 else if(schemep && !g[i].scheme) {
2617 curl_mfprintf(stderr, "%u: got scheme %s when none was expected\n", i,
2618 schemep);
2619 error++;
2621 else if(schemep && g[i].scheme && strcmp(schemep, g[i].scheme)) {
2622 curl_mfprintf(stderr, "%u: got scheme %s when %s was expected\n", i,
2623 schemep, g[i].scheme);
2624 error++;
2626 curl_free(schemep);
2627 curl_url_cleanup(u);
2629 return error;
2632static CURLcode test_lib1560(const char *URL)
2634 bool has_utf8 = !!getenv("CURL_TEST_HAVE_CODESET_UTF8");
2636 (void)URL;
2637 if(has_utf8 && set_idn())
2638 return (CURLcode)14;
2640 if(test_scheme_guess())
2641 return (CURLcode)13;
2643 if(test_api_errors())
2644 return (CURLcode)12;
2646 if(urldup())
2647 return (CURLcode)11;
2649 if(setget_parts(has_utf8))
2650 return (CURLcode)10;
2652 if(get_url(has_utf8))
2653 return (CURLcode)3;
2655 if(huge())
2656 return (CURLcode)9;
2658 if(get_nothing())
2659 return (CURLcode)7;
2661 if(scopeid())
2662 return (CURLcode)6;
2664 if(append())
2665 return (CURLcode)5;
2667 if(set_url())
2668 return (CURLcode)1;
2670 if(set_parts())
2671 return (CURLcode)2;
2673 if(get_parts(has_utf8))
2674 return (CURLcode)4;
2676 if(clear_url())
2677 return (CURLcode)8;
2679 curl_mprintf("success\n");
2680 return CURLE_OK;
Diagnostics4 git calls · 32 ms
CallStatusSizeTime032 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200149 B · hit3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=3
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=149
git.pkt.payload.max=78
git.ls_refs.count=2
git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=27
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=10
git.pkt.data=8
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=293470
git.pkt.payload.max=65516
git.sideband.band1.bytes=293354
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=87
git.pack.bytes=293354
git.pack.ofs_delta=0
git.pack.ref_delta=1
git.pack.chain.max=1
git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0
git.pack.full=86
Open pack map
fetch20017 KiB · hit27 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=17887
git.response.cache=HIT
git.response.duration_ms=27
git.fetch.wants=781843a92abd7e6c0d579e599fb26f9e8e80063f
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=17887
git.pkt.payload.max=17866
git.sideband.band1.bytes=17865
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
Ref
refs/heads/master
Commit
31c911efe5652725e930f4d2e60c9060e5f6646d
cf-ray
a5e3358a9c48f485
Request
ef95eee0…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format