1 USING: accessors arrays assocs io.sockets io.sockets.secure kernel
2 linked-assocs present prettyprint sequences tools.test urls ;
5 { "localhost" f } [ "localhost" parse-host ] unit-test
6 { "localhost" 8888 } [ "localhost:8888" parse-host ] unit-test
12 { host "www.apple.com" }
15 { query LH{ { "a" "b" } } }
18 "http://www.apple.com:1234/a/path?a=b#foo"
23 { host "www.apple.com" }
25 { query LH{ { "a" "b" } } }
28 "http://www.apple.com/a/path?a=b#foo"
33 { host "www.apple.com" }
35 { path "/another/fine/path" }
38 "http://www.apple.com:1234/another/fine/path#foo"
42 { path "/a/relative/path" }
45 "/a/relative/path#foo"
49 { path "/a/relative/path" }
55 { path "a/relative/path" }
62 { query LH{ { "a" "b" } } }
69 { host "ftp.kernel.org" }
73 "ftp://slava@ftp.kernel.org/"
78 { host "ftp.kernel.org" }
83 "ftp://slava:secret@ftp.kernel.org/"
90 { query LH{ { "a" f } } }
94 ! Capital letters, digits, hyphen, plus and period are allowed
95 ! characters in the scheme
96 ! part. https://tools.ietf.org/html/rfc1738#section-5
99 { protocol "foo.bar" }
100 { host "www.google.com" }
103 "foo.bar://www.google.com/"
107 { protocol "foo.-bar" }
108 { host "www.google.com" }
111 "foo.-bar://www.google.com/"
116 { host "www.google.com" }
119 "t1000://www.google.com/"
123 { protocol "no-auth" }
124 { path "/some/random/path" }
126 "no-auth:/some/random/path"
131 { host "example.org" }
136 "http://user:@example.org/"
141 { host "example.org" }
146 "http://:pass@example.org/"
151 { host "example.org" }
154 "http://example.org/%2F/"
159 [ 1array ] [ [ >url ] curry ] bi* unit-test
163 swap [ 1array ] [ [ present ] curry ] bi* unit-test
173 { query LH{ { "ш" "ш" } } }
176 [ "http://ш:ш@ш.com:1234/ш?ш=ш#ш" >url ] unit-test
186 { query LH{ { "query" "Dürst" } } }
189 } [ "http://März.com/päth?query=Dürst#☃" >url ] unit-test
193 { host "www.google.com" }
196 [ "https://www.google.com:/" >url ] unit-test
198 { "https://www.google.com/" }
201 { host "www.google.com" }
203 } present ] unit-test
205 { "b" } [ "a" "b" url-append-path ] unit-test
207 { "a/b" } [ "a/c" "b" url-append-path ] unit-test
209 { "a/b" } [ "a/" "b" url-append-path ] unit-test
211 { "/b" } [ "a" "/b" url-append-path ] unit-test
213 { "/b" } [ "a/b/" "/b" url-append-path ] unit-test
215 { "/xxx/bar" } [ "/xxx/baz" "bar" url-append-path ] unit-test
220 { host "www.apple.com" }
227 { host "www.apple.com" }
242 { host "www.apple.com" }
244 { path "/a/path/relative/path" }
245 { query LH{ { "a" "b" } } }
251 { host "www.apple.com" }
257 { path "relative/path" }
258 { query LH{ { "a" "b" } } }
268 { host "www.apple.com" }
270 { path "/a/path/relative/path" }
271 { query LH{ { "a" "b" } } }
277 { host "www.apple.com" }
283 { path "relative/path" }
284 { query LH{ { "a" "b" } } }
294 { host "www.apple.com" }
300 { host "www.apple.com" }
314 { host "www.apple.com" }
320 { host "www.apple.com" }
327 { host "www.apple.com" }
334 ! Support //foo.com, which has the same protocol as the url we derive from
335 { URL" http://foo.com" }
336 [ URL" http://google.com" URL" //foo.com" derive-url ] unit-test
338 { URL" https://foo.com" }
339 [ URL" https://google.com" URL" //foo.com" derive-url ] unit-test
342 <url> "a" "b" set-query-param "b" query-param
346 URL" http://www.google.com" "foo" "bar" set-query-param
347 query>> linked-assoc?
350 { "foo#3" } [ URL" foo" clone 3 >>anchor present ] unit-test
352 { "http://www.foo.com/" } [ "http://www.foo.com:80" >url present ] unit-test
354 { f } [ URL" /gp/redirect.html/002-7009742-0004012?location=http://advantage.amazon.com/gp/vendor/public/join%26token%3d77E3769AB3A5B6CF611699E150DC33010761CE12" protocol>> ] unit-test
360 { query LH{ { "foo" "bar" } } }
364 [ "http://localhost?foo=bar" >url ] unit-test
370 { query LH{ { "foo" "bar" } } }
374 [ "http://localhost/?foo=bar" >url ] unit-test
376 { "/" } [ "http://www.jedit.org" >url path>> ] unit-test
378 { "USING: urls ;\nURL\" foo\"" } [ URL" foo" unparse-use ] unit-test
380 { T{ inet { host "google.com" } { port 80 } } }
381 [ URL" http://google.com/" url-addr ] unit-test
385 { addrspec T{ inet { host "google.com" } { port 443 } } }
386 { hostname "google.com" }
389 [ URL" https://google.com/" url-addr ] unit-test
392 [ URL" git+https://google.com/git/factor.git" >url protocol>> ] unit-test
394 ! Params should be rendered in the order in which they are added.
395 { "/?foo=foo&bar=bar&baz=baz" } [
397 "foo" "foo" set-query-param
398 "bar" "bar" set-query-param
399 "baz" "baz" set-query-param
403 ! Scheme characters are
404 ! case-insensitive. https://tools.ietf.org/html/rfc3986#section-3.1
405 { URL" http://www.google.com/" } [
406 URL" HTTP://www.google.com/"
409 { URL" https://host:1234/path" } [ URL" https://host:1234/path" redacted-url ] unit-test
410 { URL" https://user@host:1234/path" } [ URL" https://user@host:1234/path" redacted-url ] unit-test
411 { URL" https://user:xxxxx@host:1234/path" } [ URL" https://user:password@host:1234/path" redacted-url ] unit-test
414 { "/a/b/c" "./////d" "/a/b/d" }
415 { "/a/b/c" "./././././d" "/a/b/d" }
416 { "/a/b/c" "/d" "/d" }
417 { "/a/b/c" "/./d" "/d" }
418 { "/a/b/c" "/../d" "/d" }
419 { "/a/b/c" "/d" "/d" }
420 { "/a/b/c" "d" "/a/b/d" }
421 { "/a/b/c" "./d" "/a/b/d" }
422 { "/a/b/c" "d/" "/a/b/d/" }
423 { "/a/b/c" "." "/a/b/" }
424 { "/a/b/c" "./" "/a/b/" }
425 { "/a/b/c" ".." "/a/" }
426 { "/a/b/c" "../" "/a/" }
427 { "/a/b/c" "../d" "/a/d" }
428 { "/a/b/c" "../.." "/" }
429 { "/a/b/c" "../../" "/" }
430 { "/a/b/c" "../../d" "/d" }
431 { "/a/b/c" "../../../d" "/d" }
432 { "/a/b/c" "d." "/a/b/d." }
433 { "/a/b/c" ".d" "/a/b/.d" }
434 { "/a/b/c" "d.." "/a/b/d.." }
435 { "/a/b/c" "..d" "/a/b/..d" }
436 { "/a/b/c" "./../d" "/a/d" }
437 { "/a/b/c" "./d/." "/a/b/d/" }
438 { "/a/b/c" "d/./e" "/a/b/d/e" }
439 { "/a/b/c" "d/../e" "/a/b/e" }
440 { "/a/b/c/d/" "../../e/f" "/a/b/e/f" }
441 { "/a/b/c/d" "../../e/f" "/a/e/f" }
442 { "/a/b/c/d/" "../../e/f/" "/a/b/e/f/" }
443 { "/a/b/c/d" "../../e/f/" "/a/e/f/" }
444 { "/a/b/c/d/" "/../../e/f/" "/e/f/" }
445 { "/a/b/c/d" "/../../e/f/" "/e/f/" }
447 1 cut* swap first2 '[ _ _ url-append-path ] unit-test
450 ! RFC 3986 1.1.2. Examples
455 { host "ftp.is.co.za" }
456 { path "/rfc/rfc1808.txt" }
458 } [ "ftp://ftp.is.co.za/rfc/rfc1808.txt" >url ] unit-test
463 { host "www.ietf.org" }
464 { path "/rfc/rfc2396.txt" }
466 } [ "http://www.ietf.org/rfc/rfc2396.txt" >url ] unit-test
472 { host "[2001:db8::7]" }
474 { query LH{ { "objectClass?one" f } } }
476 } [ "ldap://[2001:db8::7]/c=GB?objectClass?one" >url ] unit-test
480 { protocol "mailto" }
481 { path "John.Doe@example.com" }
483 } [ "mailto:John.Doe@example.com" >url ] unit-test
489 { path "comp.infosystems.www.servers.unix" }
491 } [ "news:comp.infosystems.www.servers.unix" >url ] unit-test
497 { path "+1-816-555-1212" }
499 } [ "tel:+1-816-555-1212" >url ] unit-test
503 { protocol "telnet" }
504 { host "192.0.2.16" }
508 } [ "telnet://192.0.2.16:80/" >url ] unit-test
513 { path "oasis:names:specification:docbook:dtd:xml:4.1.2" }
515 } [ "urn:oasis:names:specification:docbook:dtd:xml:4.1.2" >url ] unit-test
517 ! RFC 3986 6.2.2. Syntax Normalization
518 { URL" example://a/b/c/%7Bfoo%7D" } [
519 URL" eXAMPLE://a/./b/../b/%63/%7bfoo%7d"
522 ! RFC 3986 6.2.3. Scheme-Based Normalization
526 "http://example.com/"
527 "http://example.com:/"
528 "http://example.com:80/"
529 } [ >url present "http://example.com/" = ] all?