web-uri.test 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  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. (define-module (test-web-uri)
  19. #:use-module (web uri)
  20. #:use-module (ice-9 regex)
  21. #:use-module (test-suite lib))
  22. ;; FIXME: need more decode / encode tests
  23. (define* (uri=? uri #:key scheme userinfo host port path query fragment)
  24. (and (uri-reference? uri)
  25. (equal? (uri-scheme uri) scheme)
  26. (equal? (uri-userinfo uri) userinfo)
  27. (equal? (uri-host uri) host)
  28. (equal? (uri-port uri) port)
  29. (equal? (uri-path uri) path)
  30. (equal? (uri-query uri) query)
  31. (equal? (uri-fragment uri) fragment)))
  32. (define-syntax pass-if-uri-exception
  33. (syntax-rules ()
  34. ((_ name pat exp)
  35. (pass-if name
  36. (catch 'uri-error
  37. (lambda () exp (error "expected uri-error exception"))
  38. (lambda (k message args)
  39. (if (string-match pat message)
  40. #t
  41. (error "unexpected uri-error exception" message args))))))))
  42. (with-test-prefix "build-uri"
  43. (pass-if "ftp:"
  44. (uri=? (build-uri 'ftp)
  45. #:scheme 'ftp
  46. #:path ""))
  47. (pass-if "ftp:foo"
  48. (uri=? (build-uri 'ftp #:path "foo")
  49. #:scheme 'ftp
  50. #:path "foo"))
  51. (pass-if "ftp://foo"
  52. (uri=? (build-uri 'ftp #:host "foo")
  53. #:scheme 'ftp
  54. #:host "foo"
  55. #:path ""))
  56. (pass-if "ftp://foo/bar"
  57. (uri=? (build-uri 'ftp #:host "foo" #:path "/bar")
  58. #:scheme 'ftp
  59. #:host "foo"
  60. #:path "/bar"))
  61. (pass-if "ftp://foo@bar:22/baz"
  62. (uri=? (build-uri 'ftp #:userinfo "foo" #:host "bar" #:port 22 #:path "/baz")
  63. #:scheme 'ftp
  64. #:userinfo "foo"
  65. #:host "bar"
  66. #:port 22
  67. #:path "/baz"))
  68. (pass-if-uri-exception "non-symbol scheme"
  69. "Expected.*symbol"
  70. (build-uri "nonsym"))
  71. (pass-if-uri-exception "http://bad.host.1"
  72. "Expected.*host"
  73. (build-uri 'http #:host "bad.host.1"))
  74. (pass-if "http://bad.host.1 (no validation)"
  75. (uri=? (build-uri 'http #:host "bad.host.1" #:validate? #f)
  76. #:scheme 'http #:host "bad.host.1" #:path ""))
  77. (pass-if "http://1.good.host"
  78. (uri=? (build-uri 'http #:host "1.good.host")
  79. #:scheme 'http #:host "1.good.host" #:path ""))
  80. (when (memq 'socket *features*)
  81. (pass-if "http://192.0.2.1"
  82. (uri=? (build-uri 'http #:host "192.0.2.1")
  83. #:scheme 'http #:host "192.0.2.1" #:path ""))
  84. (pass-if "http://[2001:db8::1]"
  85. (uri=? (build-uri 'http #:host "2001:db8::1")
  86. #:scheme 'http #:host "2001:db8::1" #:path ""))
  87. (pass-if "http://[::ffff:192.0.2.1]"
  88. (uri=? (build-uri 'http #:host "::ffff:192.0.2.1")
  89. #:scheme 'http #:host "::ffff:192.0.2.1" #:path "")))
  90. (pass-if-uri-exception "http://foo:not-a-port"
  91. "Expected.*port"
  92. (build-uri 'http #:host "foo" #:port "not-a-port"))
  93. (pass-if-uri-exception "http://foo:10 but port as string"
  94. "Expected.*port"
  95. (build-uri 'http #:host "foo" #:port "10"))
  96. (pass-if-uri-exception "http://:10"
  97. "Expected.*host"
  98. (build-uri 'http #:port 10))
  99. (pass-if-uri-exception "http://foo@"
  100. "Expected.*host"
  101. (build-uri 'http #:userinfo "foo"))
  102. ;; In this test, we need to reload the '(web uri)' module with a
  103. ;; different locale. This is because some locale-dependent things
  104. ;; (e.g., compiled regexes) are computed when the module is loaded.
  105. (pass-if-uri-exception "http://illégal.com"
  106. "Expected.*host"
  107. (dynamic-wind
  108. (lambda () #t)
  109. (lambda ()
  110. (with-locale "en_US.utf8"
  111. (reload-module (resolve-module '(web uri)))
  112. (build-uri 'http #:host "illégal.com")))
  113. (lambda ()
  114. (reload-module (resolve-module '(web uri)))))))
  115. (with-test-prefix "build-uri-reference"
  116. (pass-if "//host/etc/foo"
  117. (uri=? (build-uri-reference #:host "host"
  118. #:path "/etc/foo")
  119. #:host "host"
  120. #:path "/etc/foo"))
  121. (pass-if "/path/to/some/foo?query"
  122. (uri=? (build-uri-reference #:path "/path/to/some/foo"
  123. #:query "query")
  124. #:path "/path/to/some/foo"
  125. #:query "query"))
  126. (pass-if "nextdoc/foo"
  127. (uri=? (build-uri-reference #:path "nextdoc/foo")
  128. #:path "nextdoc/foo")))
  129. (with-test-prefix "string->uri"
  130. (pass-if "ftp:"
  131. (uri=? (string->uri "ftp:")
  132. #:scheme 'ftp
  133. #:path ""))
  134. (pass-if "ftp:foo"
  135. (uri=? (string->uri "ftp:foo")
  136. #:scheme 'ftp
  137. #:path "foo"))
  138. (pass-if "ftp://foo/bar"
  139. (uri=? (string->uri "ftp://foo/bar")
  140. #:scheme 'ftp
  141. #:host "foo"
  142. #:path "/bar"))
  143. (pass-if "ftp://foo@bar:22/baz"
  144. (uri=? (string->uri "ftp://foo@bar:22/baz")
  145. #:scheme 'ftp
  146. #:userinfo "foo"
  147. #:host "bar"
  148. #:port 22
  149. #:path "/baz"))
  150. (pass-if-equal "xyz://abc/x/y/z" ;<https://bugs.gnu.org/40582>
  151. (list 'xyz "abc" "/x/y/z")
  152. (let ((uri (string->uri "xyz://abc/x/y/z")))
  153. (list (uri-scheme uri)
  154. (uri-host uri)
  155. (uri-path uri))))
  156. (pass-if "http://bad.host.1"
  157. (not (string->uri "http://bad.host.1")))
  158. (pass-if "http://1.good.host"
  159. (uri=? (string->uri "http://1.good.host")
  160. #:scheme 'http #:host "1.good.host" #:path ""))
  161. (when (memq 'socket *features*)
  162. (pass-if "http://192.0.2.1"
  163. (uri=? (string->uri "http://192.0.2.1")
  164. #:scheme 'http #:host "192.0.2.1" #:path ""))
  165. (pass-if "http://[2001:db8::1]"
  166. (uri=? (string->uri "http://[2001:db8::1]")
  167. #:scheme 'http #:host "2001:db8::1" #:path ""))
  168. (pass-if "http://[2001:db8::1]:80"
  169. (uri=? (string->uri "http://[2001:db8::1]:80")
  170. #:scheme 'http
  171. #:host "2001:db8::1"
  172. #:port 80
  173. #:path ""))
  174. (pass-if "http://[::ffff:192.0.2.1]"
  175. (uri=? (string->uri "http://[::ffff:192.0.2.1]")
  176. #:scheme 'http #:host "::ffff:192.0.2.1" #:path "")))
  177. (pass-if "http://foo:"
  178. (uri=? (string->uri "http://foo:")
  179. #:scheme 'http #:host "foo" #:path ""))
  180. (pass-if "http://foo:/"
  181. (uri=? (string->uri "http://foo:/")
  182. #:scheme 'http #:host "foo" #:path "/"))
  183. (pass-if "http://2012.jsconf.us/"
  184. (uri=? (string->uri "http://2012.jsconf.us/")
  185. #:scheme 'http #:host "2012.jsconf.us" #:path "/"))
  186. (pass-if "http://foo:not-a-port"
  187. (not (string->uri "http://foo:not-a-port")))
  188. (pass-if "http://:10"
  189. (not (string->uri "http://:10")))
  190. (pass-if "http://foo@"
  191. (not (string->uri "http://foo@")))
  192. (pass-if "file:/"
  193. (uri=? (string->uri "file:/")
  194. #:scheme 'file
  195. #:path "/"))
  196. (pass-if "file:/etc/hosts"
  197. (uri=? (string->uri "file:/etc/hosts")
  198. #:scheme 'file
  199. #:path "/etc/hosts"))
  200. (pass-if "file:///etc/hosts"
  201. (uri=? (string->uri "file:///etc/hosts")
  202. #:scheme 'file
  203. #:path "/etc/hosts"))
  204. (pass-if "http://foo#bar"
  205. (uri=? (string->uri "http://foo#bar")
  206. #:scheme 'http
  207. #:host "foo"
  208. #:path ""
  209. #:fragment "bar"))
  210. (pass-if "http://foo:/#bar"
  211. (uri=? (string->uri "http://foo:/#bar")
  212. #:scheme 'http
  213. #:host "foo"
  214. #:path "/"
  215. #:fragment "bar"))
  216. (pass-if "http://foo:100#bar"
  217. (uri=? (string->uri "http://foo:100#bar")
  218. #:scheme 'http
  219. #:host "foo"
  220. #:port 100
  221. #:path ""
  222. #:fragment "bar"))
  223. (pass-if "http://foo:100/#bar"
  224. (uri=? (string->uri "http://foo:100/#bar")
  225. #:scheme 'http
  226. #:host "foo"
  227. #:port 100
  228. #:path "/"
  229. #:fragment "bar"))
  230. (pass-if "http://foo?q#bar"
  231. (uri=? (string->uri "http://foo?q#bar")
  232. #:scheme 'http
  233. #:host "foo"
  234. #:path ""
  235. #:query "q"
  236. #:fragment "bar"))
  237. (pass-if "http://foo:/?q#bar"
  238. (uri=? (string->uri "http://foo:/?q#bar")
  239. #:scheme 'http
  240. #:host "foo"
  241. #:path "/"
  242. #:query "q"
  243. #:fragment "bar"))
  244. (pass-if "http://foo:100?q#bar"
  245. (uri=? (string->uri "http://foo:100?q#bar")
  246. #:scheme 'http
  247. #:host "foo"
  248. #:port 100
  249. #:path ""
  250. #:query "q"
  251. #:fragment "bar"))
  252. (pass-if "http://foo:100/?q#bar"
  253. (uri=? (string->uri "http://foo:100/?q#bar")
  254. #:scheme 'http
  255. #:host "foo"
  256. #:port 100
  257. #:path "/"
  258. #:query "q"
  259. #:fragment "bar"))
  260. ;; This test reproduces bug #35785. See the 'illégal' test above for
  261. ;; why we reload the module.
  262. (pass-if "http://www.example.com (sv_SE)"
  263. (dynamic-wind
  264. (lambda () #t)
  265. (lambda ()
  266. (with-locale "sv_SE.utf8"
  267. (reload-module (resolve-module '(web uri)))
  268. (uri=? (string->uri "http://www.example.com")
  269. #:scheme 'http #:host "www.example.com" #:path "")))
  270. (lambda ()
  271. (reload-module (resolve-module '(web uri)))))))
  272. (with-test-prefix "string->uri-reference"
  273. (pass-if "/foo"
  274. (uri=? (string->uri-reference "/foo")
  275. #:path "/foo"))
  276. (pass-if "ftp:/foo"
  277. (uri=? (string->uri-reference "ftp:/foo")
  278. #:scheme 'ftp
  279. #:path "/foo"))
  280. (pass-if "ftp:foo"
  281. (uri=? (string->uri-reference "ftp:foo")
  282. #:scheme 'ftp
  283. #:path "foo"))
  284. (pass-if "//foo/bar"
  285. (uri=? (string->uri-reference "//foo/bar")
  286. #:host "foo"
  287. #:path "/bar"))
  288. (pass-if "ftp://foo@bar:22/baz"
  289. (uri=? (string->uri-reference "ftp://foo@bar:22/baz")
  290. #:scheme 'ftp
  291. #:userinfo "foo"
  292. #:host "bar"
  293. #:port 22
  294. #:path "/baz"))
  295. (pass-if "//foo@bar:22/baz"
  296. (uri=? (string->uri-reference "//foo@bar:22/baz")
  297. #:userinfo "foo"
  298. #:host "bar"
  299. #:port 22
  300. #:path "/baz"))
  301. (pass-if "http://bad.host.1"
  302. (not (string->uri-reference "http://bad.host.1")))
  303. (pass-if "//bad.host.1"
  304. (not (string->uri-reference "//bad.host.1")))
  305. (pass-if "http://1.good.host"
  306. (uri=? (string->uri-reference "http://1.good.host")
  307. #:scheme 'http #:host "1.good.host" #:path ""))
  308. (pass-if "//1.good.host"
  309. (uri=? (string->uri-reference "//1.good.host")
  310. #:host "1.good.host" #:path ""))
  311. (when (memq 'socket *features*)
  312. (pass-if "http://192.0.2.1"
  313. (uri=? (string->uri-reference "http://192.0.2.1")
  314. #:scheme 'http #:host "192.0.2.1" #:path ""))
  315. (pass-if "//192.0.2.1"
  316. (uri=? (string->uri-reference "//192.0.2.1")
  317. #:host "192.0.2.1" #:path ""))
  318. (pass-if "http://[2001:db8::1]"
  319. (uri=? (string->uri-reference "http://[2001:db8::1]")
  320. #:scheme 'http #:host "2001:db8::1" #:path ""))
  321. (pass-if "//[2001:db8::1]"
  322. (uri=? (string->uri-reference "//[2001:db8::1]")
  323. #:host "2001:db8::1" #:path ""))
  324. (pass-if "http://[2001:db8::1]:80"
  325. (uri=? (string->uri-reference "http://[2001:db8::1]:80")
  326. #:scheme 'http
  327. #:host "2001:db8::1"
  328. #:port 80
  329. #:path ""))
  330. (pass-if "//[2001:db8::1]:80"
  331. (uri=? (string->uri-reference "//[2001:db8::1]:80")
  332. #:host "2001:db8::1"
  333. #:port 80
  334. #:path ""))
  335. (pass-if "http://[::ffff:192.0.2.1]"
  336. (uri=? (string->uri-reference "http://[::ffff:192.0.2.1]")
  337. #:scheme 'http #:host "::ffff:192.0.2.1" #:path ""))
  338. (pass-if "//[::ffff:192.0.2.1]"
  339. (uri=? (string->uri-reference "//[::ffff:192.0.2.1]")
  340. #:host "::ffff:192.0.2.1" #:path "")))
  341. (pass-if "http://foo:"
  342. (uri=? (string->uri-reference "http://foo:")
  343. #:scheme 'http #:host "foo" #:path ""))
  344. (pass-if "//foo:"
  345. (uri=? (string->uri-reference "//foo:")
  346. #:host "foo" #:path ""))
  347. (pass-if "http://foo:/"
  348. (uri=? (string->uri-reference "http://foo:/")
  349. #:scheme 'http #:host "foo" #:path "/"))
  350. (pass-if "//foo:/"
  351. (uri=? (string->uri-reference "//foo:/")
  352. #:host "foo" #:path "/"))
  353. (pass-if "http://2012.jsconf.us/"
  354. (uri=? (string->uri-reference "http://2012.jsconf.us/")
  355. #:scheme 'http #:host "2012.jsconf.us" #:path "/"))
  356. (pass-if "//2012.jsconf.us/"
  357. (uri=? (string->uri-reference "//2012.jsconf.us/")
  358. #:host "2012.jsconf.us" #:path "/"))
  359. (pass-if "http://foo:not-a-port"
  360. (not (string->uri-reference "http://foo:not-a-port")))
  361. (pass-if "//foo:not-a-port"
  362. (not (string->uri-reference "//foo:not-a-port")))
  363. (pass-if "http://:10"
  364. (not (string->uri-reference "http://:10")))
  365. (pass-if "//:10"
  366. (not (string->uri-reference "//:10")))
  367. (pass-if "http://foo@"
  368. (not (string->uri-reference "http://foo@")))
  369. (pass-if "//foo@"
  370. (not (string->uri-reference "//foo@")))
  371. (pass-if "file:/"
  372. (uri=? (string->uri-reference "file:/")
  373. #:scheme 'file
  374. #:path "/"))
  375. (pass-if "/"
  376. (uri=? (string->uri-reference "/")
  377. #:path "/"))
  378. (pass-if "foo"
  379. (uri=? (string->uri-reference "foo")
  380. #:path "foo"))
  381. (pass-if "file:/etc/hosts"
  382. (uri=? (string->uri-reference "file:/etc/hosts")
  383. #:scheme 'file
  384. #:path "/etc/hosts"))
  385. (pass-if "/etc/hosts"
  386. (uri=? (string->uri-reference "/etc/hosts")
  387. #:path "/etc/hosts"))
  388. (pass-if "file:///etc/hosts"
  389. (uri=? (string->uri-reference "file:///etc/hosts")
  390. #:scheme 'file
  391. #:path "/etc/hosts"))
  392. (pass-if "///etc/hosts"
  393. (uri=? (string->uri-reference "///etc/hosts")
  394. #:path "/etc/hosts"))
  395. (pass-if "/foo#bar"
  396. (uri=? (string->uri-reference "/foo#bar")
  397. #:path "/foo"
  398. #:fragment "bar"))
  399. (pass-if "//foo#bar"
  400. (uri=? (string->uri-reference "//foo#bar")
  401. #:host "foo"
  402. #:path ""
  403. #:fragment "bar"))
  404. (pass-if "//foo:/#bar"
  405. (uri=? (string->uri-reference "//foo:/#bar")
  406. #:host "foo"
  407. #:path "/"
  408. #:fragment "bar"))
  409. (pass-if "//foo:100#bar"
  410. (uri=? (string->uri-reference "//foo:100#bar")
  411. #:host "foo"
  412. #:port 100
  413. #:path ""
  414. #:fragment "bar"))
  415. (pass-if "//foo:100/#bar"
  416. (uri=? (string->uri-reference "//foo:100/#bar")
  417. #:host "foo"
  418. #:port 100
  419. #:path "/"
  420. #:fragment "bar"))
  421. (pass-if "/foo?q#bar"
  422. (uri=? (string->uri-reference "/foo?q#bar")
  423. #:path "/foo"
  424. #:query "q"
  425. #:fragment "bar"))
  426. (pass-if "//foo?q#bar"
  427. (uri=? (string->uri-reference "//foo?q#bar")
  428. #:host "foo"
  429. #:path ""
  430. #:query "q"
  431. #:fragment "bar"))
  432. (pass-if "//foo:/?q#bar"
  433. (uri=? (string->uri-reference "//foo:/?q#bar")
  434. #:host "foo"
  435. #:path "/"
  436. #:query "q"
  437. #:fragment "bar"))
  438. (pass-if "//foo:100?q#bar"
  439. (uri=? (string->uri-reference "//foo:100?q#bar")
  440. #:host "foo"
  441. #:port 100
  442. #:path ""
  443. #:query "q"
  444. #:fragment "bar"))
  445. (pass-if "//foo:100/?q#bar"
  446. (uri=? (string->uri-reference "//foo:100/?q#bar")
  447. #:host "foo"
  448. #:port 100
  449. #:path "/"
  450. #:query "q"
  451. #:fragment "bar")))
  452. (with-test-prefix "string->uri-reference"
  453. (pass-if "/"
  454. (uri=? (string->uri-reference "/")
  455. #:path "/"))
  456. (pass-if "/path/to/foo"
  457. (uri=? (string->uri-reference "/path/to/foo")
  458. #:path "/path/to/foo"))
  459. (pass-if "//example.org"
  460. (uri=? (string->uri-reference "//example.org")
  461. #:host "example.org"
  462. #:path ""))
  463. (pass-if "//bar@example.org/path/to/foo"
  464. (uri=? (string->uri-reference "//bar@example.org/path/to/foo")
  465. #:userinfo "bar"
  466. #:host "example.org"
  467. #:path "/path/to/foo"))
  468. (pass-if "nextdoc/foo"
  469. (uri=? (string->uri-reference "nextdoc/foo")
  470. #:path "nextdoc/foo")))
  471. (with-test-prefix "uri->string"
  472. (pass-if "ftp:"
  473. (equal? "ftp:"
  474. (uri->string (string->uri "ftp:"))))
  475. (pass-if "ftp:foo"
  476. (equal? "ftp:foo"
  477. (uri->string (string->uri "ftp:foo"))))
  478. (pass-if "ftp://foo/bar"
  479. (equal? "ftp://foo/bar"
  480. (uri->string (string->uri "ftp://foo/bar"))))
  481. (pass-if "//foo/bar"
  482. (equal? "//foo/bar"
  483. (uri->string (string->uri-reference "//foo/bar"))))
  484. (pass-if "ftp://foo@bar:22/baz"
  485. (equal? "ftp://foo@bar:22/baz"
  486. (uri->string (string->uri "ftp://foo@bar:22/baz"))))
  487. (pass-if "//foo@bar:22/baz"
  488. (equal? "//foo@bar:22/baz"
  489. (uri->string (string->uri-reference "//foo@bar:22/baz"))))
  490. (when (memq 'socket *features*)
  491. (pass-if "http://192.0.2.1"
  492. (equal? "http://192.0.2.1"
  493. (uri->string (string->uri "http://192.0.2.1"))))
  494. (pass-if "//192.0.2.1"
  495. (equal? "//192.0.2.1"
  496. (uri->string (string->uri-reference "//192.0.2.1"))))
  497. (pass-if "http://[2001:db8::1]"
  498. (equal? "http://[2001:db8::1]"
  499. (uri->string (string->uri "http://[2001:db8::1]"))))
  500. (pass-if "//[2001:db8::1]"
  501. (equal? "//[2001:db8::1]"
  502. (uri->string (string->uri-reference "//[2001:db8::1]"))))
  503. (pass-if "http://[::ffff:192.0.2.1]"
  504. (equal? "http://[::ffff:192.0.2.1]"
  505. (uri->string (string->uri "http://[::ffff:192.0.2.1]"))))
  506. (pass-if "//[::ffff:192.0.2.1]"
  507. (equal? "//[::ffff:192.0.2.1]"
  508. (uri->string (string->uri-reference "//[::ffff:192.0.2.1]")))))
  509. (pass-if "http://foo:"
  510. (equal? "http://foo"
  511. (uri->string (string->uri "http://foo:"))))
  512. (pass-if "//foo"
  513. (equal? "//foo"
  514. (uri->string (string->uri-reference "//foo"))))
  515. (pass-if "http://foo:/"
  516. (equal? "http://foo/"
  517. (uri->string (string->uri "http://foo:/"))))
  518. (pass-if "//foo:/"
  519. (equal? "//foo/"
  520. (uri->string (string->uri-reference "//foo:/"))))
  521. (pass-if "/"
  522. (equal? "/"
  523. (uri->string (string->uri-reference "/"))))
  524. (pass-if "/foo"
  525. (equal? "/foo"
  526. (uri->string (string->uri-reference "/foo"))))
  527. (pass-if "/foo/"
  528. (equal? "/foo/"
  529. (uri->string (string->uri-reference "/foo/"))))
  530. (pass-if "/foo/?bar#baz"
  531. (equal? "/foo/?bar#baz"
  532. (uri->string (string->uri-reference "/foo/?bar#baz"))))
  533. (pass-if "foo/?bar#baz"
  534. (equal? "foo/?bar#baz"
  535. (uri->string (string->uri-reference "foo/?bar#baz"))))
  536. (pass-if "/path/to/foo"
  537. (equal? "/path/to/foo"
  538. (uri->string (string->uri-reference "/path/to/foo"))))
  539. (pass-if "//example.org"
  540. (equal? "//example.org"
  541. (uri->string (string->uri-reference "//example.org"))))
  542. (pass-if "//bar@example.org/path/to/foo"
  543. (equal? "//bar@example.org/path/to/foo"
  544. (uri->string (string->uri-reference "//bar@example.org/path/to/foo"))))
  545. (pass-if "nextdoc/foo"
  546. (equal? "nextdoc/foo"
  547. (uri->string (string->uri-reference "nextdoc/foo")))))
  548. (with-test-prefix "decode"
  549. (pass-if "foo%20bar"
  550. (equal? "foo bar" (uri-decode "foo%20bar")))
  551. (pass-if "foo+bar"
  552. (equal? "foo bar" (uri-decode "foo+bar")))
  553. (pass-if "foo+bar"
  554. (equal? '("foo+bar") (split-and-decode-uri-path "foo+bar"))))
  555. (with-test-prefix "encode"
  556. (pass-if (equal? "foo%20bar" (uri-encode "foo bar")))
  557. (pass-if (equal? "foo%0A%00bar" (uri-encode "foo\n\x00bar")))
  558. (pass-if (equal? "%3C%3E%5C%5E" (uri-encode "<>\\^"))))