Debian Codegraph @

test-suite/tests/web-uri.test

raw
1 ;;;; web-uri.test --- URI library -*- mode: scheme; coding: utf-8; -*-
2 ;;;;
3 ;;;; Copyright (C) 2010-2012, 2014, 2017, 2019, 2020 Free Software Foundation, Inc.
4 ;;;;
5 ;;;; This library is free software; you can redistribute it and/or
6 ;;;; modify it under the terms of the GNU Lesser General Public
7 ;;;; License as published by the Free Software Foundation; either
8 ;;;; version 3 of the License, or (at your option) any later version.
9 ;;;;
10 ;;;; This library is distributed in the hope that it will be useful,
11 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ;;;; Lesser General Public License for more details.
14 ;;;;
15 ;;;; You should have received a copy of the GNU Lesser General Public
16 ;;;; License along with this library; if not, write to the Free Software
17 ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19
20 (define-module (test-web-uri)
21 #:use-module (web uri)
22 #:use-module (ice-9 regex)
23 #:use-module (test-suite lib))
24
25
26 ;; FIXME: need more decode / encode tests
27
28
29 (define* (uri=? uri #:key scheme userinfo host port path query fragment)
30 (and (uri-reference? uri)
31 (equal? (uri-scheme uri) scheme)
32 (equal? (uri-userinfo uri) userinfo)
33 (equal? (uri-host uri) host)
34 (equal? (uri-port uri) port)
35 (equal? (uri-path uri) path)
36 (equal? (uri-query uri) query)
37 (equal? (uri-fragment uri) fragment)))
38
39 (define-syntax pass-if-uri-exception
40 (syntax-rules ()
41 ((_ name pat exp)
42 (pass-if name
43 (catch 'uri-error
44 (lambda () exp (error "expected uri-error exception"))
45 (lambda (k message args)
46 (if (string-match pat message)
47 #t
48 (error "unexpected uri-error exception" message args))))))))
49
50 (with-test-prefix "build-uri"
51 (pass-if "ftp:"
52 (uri=? (build-uri 'ftp)
53 #:scheme 'ftp
54 #:path ""))
55
56 (pass-if "ftp:foo"
57 (uri=? (build-uri 'ftp #:path "foo")
58 #:scheme 'ftp
59 #:path "foo"))
60
61 (pass-if "ftp://foo"
62 (uri=? (build-uri 'ftp #:host "foo")
63 #:scheme 'ftp
64 #:host "foo"
65 #:path ""))
66
67 (pass-if "ftp://foo/bar"
68 (uri=? (build-uri 'ftp #:host "foo" #:path "/bar")
69 #:scheme 'ftp
70 #:host "foo"
71 #:path "/bar"))
72
73 (pass-if "ftp://foo@bar:22/baz"
74 (uri=? (build-uri 'ftp #:userinfo "foo" #:host "bar" #:port 22 #:path "/baz")
75 #:scheme 'ftp
76 #:userinfo "foo"
77 #:host "bar"
78 #:port 22
79 #:path "/baz"))
80
81 (pass-if-uri-exception "non-symbol scheme"
82 "Expected.*symbol"
83 (build-uri "nonsym"))
84
85 (pass-if-uri-exception "http://bad.host.1"
86 "Expected.*host"
87 (build-uri 'http #:host "bad.host.1"))
88
89 (pass-if "http://bad.host.1 (no validation)"
90 (uri=? (build-uri 'http #:host "bad.host.1" #:validate? #f)
91 #:scheme 'http #:host "bad.host.1" #:path ""))
92
93 (pass-if "http://1.good.host"
94 (uri=? (build-uri 'http #:host "1.good.host")
95 #:scheme 'http #:host "1.good.host" #:path ""))
96
97 (when (memq 'socket *features*)
98 (pass-if "http://192.0.2.1"
99 (uri=? (build-uri 'http #:host "192.0.2.1")
100 #:scheme 'http #:host "192.0.2.1" #:path ""))
101
102 (pass-if "http://[2001:db8::1]"
103 (uri=? (build-uri 'http #:host "2001:db8::1")
104 #:scheme 'http #:host "2001:db8::1" #:path ""))
105
106 (pass-if "http://[::ffff:192.0.2.1]"
107 (uri=? (build-uri 'http #:host "::ffff:192.0.2.1")
108 #:scheme 'http #:host "::ffff:192.0.2.1" #:path "")))
109
110 (pass-if-uri-exception "http://foo:not-a-port"
111 "Expected.*port"
112 (build-uri 'http #:host "foo" #:port "not-a-port"))
113
114 (pass-if-uri-exception "http://foo:10 but port as string"
115 "Expected.*port"
116 (build-uri 'http #:host "foo" #:port "10"))
117
118 (pass-if-uri-exception "http://:10"
119 "Expected.*host"
120 (build-uri 'http #:port 10))
121
122 (pass-if-uri-exception "http://foo@"
123 "Expected.*host"
124 (build-uri 'http #:userinfo "foo"))
125
126 ;; In this test, we need to reload the '(web uri)' module with a
127 ;; different locale. This is because some locale-dependent things
128 ;; (e.g., compiled regexes) are computed when the module is loaded.
129 (pass-if-uri-exception "http://illégal.com"
130 "Expected.*host"
131 (dynamic-wind
132 (lambda () #t)
133 (lambda ()
134 (with-locale "en_US.utf8"
135 (reload-module (resolve-module '(web uri)))
136 (build-uri 'http #:host "illégal.com")))
137 (lambda ()
138 (reload-module (resolve-module '(web uri)))))))
139
140 (with-test-prefix "build-uri-reference"
141 (pass-if "//host/etc/foo"
142 (uri=? (build-uri-reference #:host "host"
143 #:path "/etc/foo")
144 #:host "host"
145 #:path "/etc/foo"))
146
147 (pass-if "/path/to/some/foo?query"
148 (uri=? (build-uri-reference #:path "/path/to/some/foo"
149 #:query "query")
150 #:path "/path/to/some/foo"
151 #:query "query"))
152
153 (pass-if "nextdoc/foo"
154 (uri=? (build-uri-reference #:path "nextdoc/foo")
155 #:path "nextdoc/foo")))
156
157 (with-test-prefix "string->uri"
158 (pass-if "ftp:"
159 (uri=? (string->uri "ftp:")
160 #:scheme 'ftp
161 #:path ""))
162
163 (pass-if "ftp:foo"
164 (uri=? (string->uri "ftp:foo")
165 #:scheme 'ftp
166 #:path "foo"))
167
168 (pass-if "ftp://foo/bar"
169 (uri=? (string->uri "ftp://foo/bar")
170 #:scheme 'ftp
171 #:host "foo"
172 #:path "/bar"))
173
174 (pass-if "ftp://foo@bar:22/baz"
175 (uri=? (string->uri "ftp://foo@bar:22/baz")
176 #:scheme 'ftp
177 #:userinfo "foo"
178 #:host "bar"
179 #:port 22
180 #:path "/baz"))
181
182 (pass-if-equal "xyz://abc/x/y/z" ;<https://bugs.gnu.org/40582>
183 (list 'xyz "abc" "/x/y/z")
184 (let ((uri (string->uri "xyz://abc/x/y/z")))
185 (list (uri-scheme uri)
186 (uri-host uri)
187 (uri-path uri))))
188
189 (pass-if "http://bad.host.1"
190 (not (string->uri "http://bad.host.1")))
191
192 (pass-if "http://1.good.host"
193 (uri=? (string->uri "http://1.good.host")
194 #:scheme 'http #:host "1.good.host" #:path ""))
195
196 (when (memq 'socket *features*)
197 (pass-if "http://192.0.2.1"
198 (uri=? (string->uri "http://192.0.2.1")
199 #:scheme 'http #:host "192.0.2.1" #:path ""))
200
201 (pass-if "http://[2001:db8::1]"
202 (uri=? (string->uri "http://[2001:db8::1]")
203 #:scheme 'http #:host "2001:db8::1" #:path ""))
204
205 (pass-if "http://[2001:db8::1]:80"
206 (uri=? (string->uri "http://[2001:db8::1]:80")
207 #:scheme 'http
208 #:host "2001:db8::1"
209 #:port 80
210 #:path ""))
211
212 (pass-if "http://[::ffff:192.0.2.1]"
213 (uri=? (string->uri "http://[::ffff:192.0.2.1]")
214 #:scheme 'http #:host "::ffff:192.0.2.1" #:path "")))
215
216 (pass-if "http://foo:"
217 (uri=? (string->uri "http://foo:")
218 #:scheme 'http #:host "foo" #:path ""))
219
220 (pass-if "http://foo:/"
221 (uri=? (string->uri "http://foo:/")
222 #:scheme 'http #:host "foo" #:path "/"))
223
224 (pass-if "http://2012.jsconf.us/"
225 (uri=? (string->uri "http://2012.jsconf.us/")
226 #:scheme 'http #:host "2012.jsconf.us" #:path "/"))
227
228 (pass-if "http://foo:not-a-port"
229 (not (string->uri "http://foo:not-a-port")))
230
231 (pass-if "http://:10"
232 (not (string->uri "http://:10")))
233
234 (pass-if "http://foo@"
235 (not (string->uri "http://foo@")))
236
237 (pass-if "file:/"
238 (uri=? (string->uri "file:/")
239 #:scheme 'file
240 #:path "/"))
241
242 (pass-if "file:/etc/hosts"
243 (uri=? (string->uri "file:/etc/hosts")
244 #:scheme 'file
245 #:path "/etc/hosts"))
246
247 (pass-if "file:///etc/hosts"
248 (uri=? (string->uri "file:///etc/hosts")
249 #:scheme 'file
250 #:path "/etc/hosts"))
251
252 (pass-if "http://foo#bar"
253 (uri=? (string->uri "http://foo#bar")
254 #:scheme 'http
255 #:host "foo"
256 #:path ""
257 #:fragment "bar"))
258
259 (pass-if "http://foo:/#bar"
260 (uri=? (string->uri "http://foo:/#bar")
261 #:scheme 'http
262 #:host "foo"
263 #:path "/"
264 #:fragment "bar"))
265
266 (pass-if "http://foo:100#bar"
267 (uri=? (string->uri "http://foo:100#bar")
268 #:scheme 'http
269 #:host "foo"
270 #:port 100
271 #:path ""
272 #:fragment "bar"))
273
274 (pass-if "http://foo:100/#bar"
275 (uri=? (string->uri "http://foo:100/#bar")
276 #:scheme 'http
277 #:host "foo"
278 #:port 100
279 #:path "/"
280 #:fragment "bar"))
281
282 (pass-if "http://foo?q#bar"
283 (uri=? (string->uri "http://foo?q#bar")
284 #:scheme 'http
285 #:host "foo"
286 #:path ""
287 #:query "q"
288 #:fragment "bar"))
289
290 (pass-if "http://foo:/?q#bar"
291 (uri=? (string->uri "http://foo:/?q#bar")
292 #:scheme 'http
293 #:host "foo"
294 #:path "/"
295 #:query "q"
296 #:fragment "bar"))
297
298 (pass-if "http://foo:100?q#bar"
299 (uri=? (string->uri "http://foo:100?q#bar")
300 #:scheme 'http
301 #:host "foo"
302 #:port 100
303 #:path ""
304 #:query "q"
305 #:fragment "bar"))
306
307 (pass-if "http://foo:100/?q#bar"
308 (uri=? (string->uri "http://foo:100/?q#bar")
309 #:scheme 'http
310 #:host "foo"
311 #:port 100
312 #:path "/"
313 #:query "q"
314 #:fragment "bar"))
315
316 ;; This test reproduces bug #35785. See the 'illégal' test above for
317 ;; why we reload the module.
318 (pass-if "http://www.example.com (sv_SE)"
319 (dynamic-wind
320 (lambda () #t)
321 (lambda ()
322 (with-locale "sv_SE.utf8"
323 (reload-module (resolve-module '(web uri)))
324 (uri=? (string->uri "http://www.example.com")
325 #:scheme 'http #:host "www.example.com" #:path "")))
326 (lambda ()
327 (reload-module (resolve-module '(web uri)))))))
328
329 (with-test-prefix "string->uri-reference"
330 (pass-if "/foo"
331 (uri=? (string->uri-reference "/foo")
332 #:path "/foo"))
333
334 (pass-if "ftp:/foo"
335 (uri=? (string->uri-reference "ftp:/foo")
336 #:scheme 'ftp
337 #:path "/foo"))
338
339 (pass-if "ftp:foo"
340 (uri=? (string->uri-reference "ftp:foo")
341 #:scheme 'ftp
342 #:path "foo"))
343
344 (pass-if "//foo/bar"
345 (uri=? (string->uri-reference "//foo/bar")
346 #:host "foo"
347 #:path "/bar"))
348
349 (pass-if "ftp://foo@bar:22/baz"
350 (uri=? (string->uri-reference "ftp://foo@bar:22/baz")
351 #:scheme 'ftp
352 #:userinfo "foo"
353 #:host "bar"
354 #:port 22
355 #:path "/baz"))
356
357 (pass-if "//foo@bar:22/baz"
358 (uri=? (string->uri-reference "//foo@bar:22/baz")
359 #:userinfo "foo"
360 #:host "bar"
361 #:port 22
362 #:path "/baz"))
363
364 (pass-if "http://bad.host.1"
365 (not (string->uri-reference "http://bad.host.1")))
366
367 (pass-if "//bad.host.1"
368 (not (string->uri-reference "//bad.host.1")))
369
370 (pass-if "//bad.host.1."
371 (not (string->uri-reference "//bad.host.1.")))
372
373 (pass-if "//bad.host.."
374 (not (string->uri-reference "//bad.host..")))
375
376 (pass-if "//1.good.host."
377 (uri=? (string->uri-reference "//1.good.host.")
378 #:host "1.good.host." #:path ""))
379
380 (pass-if "http://1.good.host"
381 (uri=? (string->uri-reference "http://1.good.host")
382 #:scheme 'http #:host "1.good.host" #:path ""))
383
384 (pass-if "//1.good.host"
385 (uri=? (string->uri-reference "//1.good.host")
386 #:host "1.good.host" #:path ""))
387
388 (when (memq 'socket *features*)
389 (pass-if "http://192.0.2.1"
390 (uri=? (string->uri-reference "http://192.0.2.1")
391 #:scheme 'http #:host "192.0.2.1" #:path ""))
392
393 (pass-if "//192.0.2.1"
394 (uri=? (string->uri-reference "//192.0.2.1")
395 #:host "192.0.2.1" #:path ""))
396
397 (pass-if "http://[2001:db8::1]"
398 (uri=? (string->uri-reference "http://[2001:db8::1]")
399 #:scheme 'http #:host "2001:db8::1" #:path ""))
400
401 (pass-if "//[2001:db8::1]"
402 (uri=? (string->uri-reference "//[2001:db8::1]")
403 #:host "2001:db8::1" #:path ""))
404
405 (pass-if "http://[2001:db8::1]:80"
406 (uri=? (string->uri-reference "http://[2001:db8::1]:80")
407 #:scheme 'http
408 #:host "2001:db8::1"
409 #:port 80
410 #:path ""))
411
412 (pass-if "//[2001:db8::1]:80"
413 (uri=? (string->uri-reference "//[2001:db8::1]:80")
414 #:host "2001:db8::1"
415 #:port 80
416 #:path ""))
417
418 (pass-if "http://[::ffff:192.0.2.1]"
419 (uri=? (string->uri-reference "http://[::ffff:192.0.2.1]")
420 #:scheme 'http #:host "::ffff:192.0.2.1" #:path ""))
421
422 (pass-if "//[::ffff:192.0.2.1]"
423 (uri=? (string->uri-reference "//[::ffff:192.0.2.1]")
424 #:host "::ffff:192.0.2.1" #:path "")))
425
426 (pass-if "http://foo:"
427 (uri=? (string->uri-reference "http://foo:")
428 #:scheme 'http #:host "foo" #:path ""))
429
430 (pass-if "//foo:"
431 (uri=? (string->uri-reference "//foo:")
432 #:host "foo" #:path ""))
433
434 (pass-if "http://foo:/"
435 (uri=? (string->uri-reference "http://foo:/")
436 #:scheme 'http #:host "foo" #:path "/"))
437
438 (pass-if "//foo:/"
439 (uri=? (string->uri-reference "//foo:/")
440 #:host "foo" #:path "/"))
441
442 (pass-if "http://2012.jsconf.us/"
443 (uri=? (string->uri-reference "http://2012.jsconf.us/")
444 #:scheme 'http #:host "2012.jsconf.us" #:path "/"))
445
446 (pass-if "//2012.jsconf.us/"
447 (uri=? (string->uri-reference "//2012.jsconf.us/")
448 #:host "2012.jsconf.us" #:path "/"))
449
450 (pass-if "http://foo:not-a-port"
451 (not (string->uri-reference "http://foo:not-a-port")))
452
453 (pass-if "//foo:not-a-port"
454 (not (string->uri-reference "//foo:not-a-port")))
455
456 (pass-if "http://:10"
457 (not (string->uri-reference "http://:10")))
458
459 (pass-if "//:10"
460 (not (string->uri-reference "//:10")))
461
462 (pass-if "http://foo@"
463 (not (string->uri-reference "http://foo@")))
464
465 (pass-if "//foo@"
466 (not (string->uri-reference "//foo@")))
467
468 (pass-if "file:/"
469 (uri=? (string->uri-reference "file:/")
470 #:scheme 'file
471 #:path "/"))
472
473 (pass-if "/"
474 (uri=? (string->uri-reference "/")
475 #:path "/"))
476
477 (pass-if "foo"
478 (uri=? (string->uri-reference "foo")
479 #:path "foo"))
480
481 (pass-if "file:/etc/hosts"
482 (uri=? (string->uri-reference "file:/etc/hosts")
483 #:scheme 'file
484 #:path "/etc/hosts"))
485
486 (pass-if "/etc/hosts"
487 (uri=? (string->uri-reference "/etc/hosts")
488 #:path "/etc/hosts"))
489
490 (pass-if "file:///etc/hosts"
491 (uri=? (string->uri-reference "file:///etc/hosts")
492 #:scheme 'file
493 #:path "/etc/hosts"))
494
495 (pass-if "///etc/hosts"
496 (uri=? (string->uri-reference "///etc/hosts")
497 #:path "/etc/hosts"))
498
499 (pass-if "/foo#bar"
500 (uri=? (string->uri-reference "/foo#bar")
501 #:path "/foo"
502 #:fragment "bar"))
503
504 (pass-if "//foo#bar"
505 (uri=? (string->uri-reference "//foo#bar")
506 #:host "foo"
507 #:path ""
508 #:fragment "bar"))
509
510 (pass-if "//foo:/#bar"
511 (uri=? (string->uri-reference "//foo:/#bar")
512 #:host "foo"
513 #:path "/"
514 #:fragment "bar"))
515
516 (pass-if "//foo:100#bar"
517 (uri=? (string->uri-reference "//foo:100#bar")
518 #:host "foo"
519 #:port 100
520 #:path ""
521 #:fragment "bar"))
522
523 (pass-if "//foo:100/#bar"
524 (uri=? (string->uri-reference "//foo:100/#bar")
525 #:host "foo"
526 #:port 100
527 #:path "/"
528 #:fragment "bar"))
529
530 (pass-if "/foo?q#bar"
531 (uri=? (string->uri-reference "/foo?q#bar")
532 #:path "/foo"
533 #:query "q"
534 #:fragment "bar"))
535
536 (pass-if "//foo?q#bar"
537 (uri=? (string->uri-reference "//foo?q#bar")
538 #:host "foo"
539 #:path ""
540 #:query "q"
541 #:fragment "bar"))
542
543 (pass-if "//foo:/?q#bar"
544 (uri=? (string->uri-reference "//foo:/?q#bar")
545 #:host "foo"
546 #:path "/"
547 #:query "q"
548 #:fragment "bar"))
549
550 (pass-if "//foo:100?q#bar"
551 (uri=? (string->uri-reference "//foo:100?q#bar")
552 #:host "foo"
553 #:port 100
554 #:path ""
555 #:query "q"
556 #:fragment "bar"))
557
558 (pass-if "//foo:100/?q#bar"
559 (uri=? (string->uri-reference "//foo:100/?q#bar")
560 #:host "foo"
561 #:port 100
562 #:path "/"
563 #:query "q"
564 #:fragment "bar")))
565
566 (with-test-prefix "string->uri-reference"
567 (pass-if "/"
568 (uri=? (string->uri-reference "/")
569 #:path "/"))
570
571 (pass-if "/path/to/foo"
572 (uri=? (string->uri-reference "/path/to/foo")
573 #:path "/path/to/foo"))
574
575 (pass-if "//example.org"
576 (uri=? (string->uri-reference "//example.org")
577 #:host "example.org"
578 #:path ""))
579
580 (pass-if "//[email protected]/path/to/foo"
581 (uri=? (string->uri-reference "//[email protected]/path/to/foo")
582 #:userinfo "bar"
583 #:host "example.org"
584 #:path "/path/to/foo"))
585
586 (pass-if "nextdoc/foo"
587 (uri=? (string->uri-reference "nextdoc/foo")
588 #:path "nextdoc/foo")))
589
590 (with-test-prefix "uri->string"
591 (pass-if "ftp:"
592 (equal? "ftp:"
593 (uri->string (string->uri "ftp:"))))
594
595 (pass-if "ftp:foo"
596 (equal? "ftp:foo"
597 (uri->string (string->uri "ftp:foo"))))
598
599 (pass-if "ftp://foo/bar"
600 (equal? "ftp://foo/bar"
601 (uri->string (string->uri "ftp://foo/bar"))))
602
603 (pass-if "//foo/bar"
604 (equal? "//foo/bar"
605 (uri->string (string->uri-reference "//foo/bar"))))
606
607 (pass-if "ftp://foo@bar:22/baz"
608 (equal? "ftp://foo@bar:22/baz"
609 (uri->string (string->uri "ftp://foo@bar:22/baz"))))
610
611 (pass-if "//foo@bar:22/baz"
612 (equal? "//foo@bar:22/baz"
613 (uri->string (string->uri-reference "//foo@bar:22/baz"))))
614
615 (when (memq 'socket *features*)
616 (pass-if "http://192.0.2.1"
617 (equal? "http://192.0.2.1"
618 (uri->string (string->uri "http://192.0.2.1"))))
619
620 (pass-if "//192.0.2.1"
621 (equal? "//192.0.2.1"
622 (uri->string (string->uri-reference "//192.0.2.1"))))
623
624 (pass-if "http://[2001:db8::1]"
625 (equal? "http://[2001:db8::1]"
626 (uri->string (string->uri "http://[2001:db8::1]"))))
627
628 (pass-if "//[2001:db8::1]"
629 (equal? "//[2001:db8::1]"
630 (uri->string (string->uri-reference "//[2001:db8::1]"))))
631
632 (pass-if "http://[::ffff:192.0.2.1]"
633 (equal? "http://[::ffff:192.0.2.1]"
634 (uri->string (string->uri "http://[::ffff:192.0.2.1]"))))
635
636 (pass-if "//[::ffff:192.0.2.1]"
637 (equal? "//[::ffff:192.0.2.1]"
638 (uri->string (string->uri-reference "//[::ffff:192.0.2.1]")))))
639
640 (pass-if "http://foo:"
641 (equal? "http://foo"
642 (uri->string (string->uri "http://foo:"))))
643
644 (pass-if "//foo"
645 (equal? "//foo"
646 (uri->string (string->uri-reference "//foo"))))
647
648 (pass-if "http://foo:/"
649 (equal? "http://foo/"
650 (uri->string (string->uri "http://foo:/"))))
651
652 (pass-if "//foo:/"
653 (equal? "//foo/"
654 (uri->string (string->uri-reference "//foo:/"))))
655
656 (pass-if "/"
657 (equal? "/"
658 (uri->string (string->uri-reference "/"))))
659
660 (pass-if "/foo"
661 (equal? "/foo"
662 (uri->string (string->uri-reference "/foo"))))
663
664 (pass-if "/foo/"
665 (equal? "/foo/"
666 (uri->string (string->uri-reference "/foo/"))))
667
668 (pass-if "/foo/?bar#baz"
669 (equal? "/foo/?bar#baz"
670 (uri->string (string->uri-reference "/foo/?bar#baz"))))
671
672 (pass-if "foo/?bar#baz"
673 (equal? "foo/?bar#baz"
674 (uri->string (string->uri-reference "foo/?bar#baz"))))
675
676 (pass-if "/path/to/foo"
677 (equal? "/path/to/foo"
678 (uri->string (string->uri-reference "/path/to/foo"))))
679
680 (pass-if "//example.org"
681 (equal? "//example.org"
682 (uri->string (string->uri-reference "//example.org"))))
683
684 (pass-if "//[email protected]/path/to/foo"
685 (equal? "//[email protected]/path/to/foo"
686 (uri->string (string->uri-reference "//[email protected]/path/to/foo"))))
687
688 (pass-if "nextdoc/foo"
689 (equal? "nextdoc/foo"
690 (uri->string (string->uri-reference "nextdoc/foo")))))
691
692 (with-test-prefix "decode"
693 (pass-if "foo%20bar"
694 (equal? "foo bar" (uri-decode "foo%20bar")))
695
696 (pass-if "foo+bar"
697 (equal? "foo bar" (uri-decode "foo+bar")))
698
699 (pass-if "foo+bar"
700 (equal? '("foo+bar") (split-and-decode-uri-path "foo+bar"))))
701
702 (with-test-prefix "encode"
703 (pass-if (equal? "foo%20bar" (uri-encode "foo bar")))
704 (pass-if (equal? "foo%0A%00bar" (uri-encode "foo\n\x00bar")))
705 (pass-if (equal? "%3C%3E%5C%5E" (uri-encode "<>\\^"))))