web-uri.test 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. ;;;; web-uri.test --- URI library -*- mode: scheme; coding: utf-8; -*-
  2. ;;;;
  3. ;;;; Copyright (C) 2010-2012, 2014, 2017 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. (with-test-prefix "build-uri-reference"
  103. (pass-if "//host/etc/foo"
  104. (uri=? (build-uri-reference #:host "host"
  105. #:path "/etc/foo")
  106. #:host "host"
  107. #:path "/etc/foo"))
  108. (pass-if "/path/to/some/foo?query"
  109. (uri=? (build-uri-reference #:path "/path/to/some/foo"
  110. #:query "query")
  111. #:path "/path/to/some/foo"
  112. #:query "query"))
  113. (pass-if "nextdoc/foo"
  114. (uri=? (build-uri-reference #:path "nextdoc/foo")
  115. #:path "nextdoc/foo")))
  116. (with-test-prefix "string->uri"
  117. (pass-if "ftp:"
  118. (uri=? (string->uri "ftp:")
  119. #:scheme 'ftp
  120. #:path ""))
  121. (pass-if "ftp:foo"
  122. (uri=? (string->uri "ftp:foo")
  123. #:scheme 'ftp
  124. #:path "foo"))
  125. (pass-if "ftp://foo/bar"
  126. (uri=? (string->uri "ftp://foo/bar")
  127. #:scheme 'ftp
  128. #:host "foo"
  129. #:path "/bar"))
  130. (pass-if "ftp://foo@bar:22/baz"
  131. (uri=? (string->uri "ftp://foo@bar:22/baz")
  132. #:scheme 'ftp
  133. #:userinfo "foo"
  134. #:host "bar"
  135. #:port 22
  136. #:path "/baz"))
  137. (pass-if "http://bad.host.1"
  138. (not (string->uri "http://bad.host.1")))
  139. (pass-if "http://1.good.host"
  140. (uri=? (string->uri "http://1.good.host")
  141. #:scheme 'http #:host "1.good.host" #:path ""))
  142. (when (memq 'socket *features*)
  143. (pass-if "http://192.0.2.1"
  144. (uri=? (string->uri "http://192.0.2.1")
  145. #:scheme 'http #:host "192.0.2.1" #:path ""))
  146. (pass-if "http://[2001:db8::1]"
  147. (uri=? (string->uri "http://[2001:db8::1]")
  148. #:scheme 'http #:host "2001:db8::1" #:path ""))
  149. (pass-if "http://[2001:db8::1]:80"
  150. (uri=? (string->uri "http://[2001:db8::1]:80")
  151. #:scheme 'http
  152. #:host "2001:db8::1"
  153. #:port 80
  154. #:path ""))
  155. (pass-if "http://[::ffff:192.0.2.1]"
  156. (uri=? (string->uri "http://[::ffff:192.0.2.1]")
  157. #:scheme 'http #:host "::ffff:192.0.2.1" #:path "")))
  158. (pass-if "http://foo:"
  159. (uri=? (string->uri "http://foo:")
  160. #:scheme 'http #:host "foo" #:path ""))
  161. (pass-if "http://foo:/"
  162. (uri=? (string->uri "http://foo:/")
  163. #:scheme 'http #:host "foo" #:path "/"))
  164. (pass-if "http://2012.jsconf.us/"
  165. (uri=? (string->uri "http://2012.jsconf.us/")
  166. #:scheme 'http #:host "2012.jsconf.us" #:path "/"))
  167. (pass-if "http://foo:not-a-port"
  168. (not (string->uri "http://foo:not-a-port")))
  169. (pass-if "http://:10"
  170. (not (string->uri "http://:10")))
  171. (pass-if "http://foo@"
  172. (not (string->uri "http://foo@")))
  173. (pass-if "file:/"
  174. (uri=? (string->uri "file:/")
  175. #:scheme 'file
  176. #:path "/"))
  177. (pass-if "file:/etc/hosts"
  178. (uri=? (string->uri "file:/etc/hosts")
  179. #:scheme 'file
  180. #:path "/etc/hosts"))
  181. (pass-if "file:///etc/hosts"
  182. (uri=? (string->uri "file:///etc/hosts")
  183. #:scheme 'file
  184. #:path "/etc/hosts"))
  185. (pass-if "http://foo#bar"
  186. (uri=? (string->uri "http://foo#bar")
  187. #:scheme 'http
  188. #:host "foo"
  189. #:path ""
  190. #:fragment "bar"))
  191. (pass-if "http://foo:/#bar"
  192. (uri=? (string->uri "http://foo:/#bar")
  193. #:scheme 'http
  194. #:host "foo"
  195. #:path "/"
  196. #:fragment "bar"))
  197. (pass-if "http://foo:100#bar"
  198. (uri=? (string->uri "http://foo:100#bar")
  199. #:scheme 'http
  200. #:host "foo"
  201. #:port 100
  202. #:path ""
  203. #:fragment "bar"))
  204. (pass-if "http://foo:100/#bar"
  205. (uri=? (string->uri "http://foo:100/#bar")
  206. #:scheme 'http
  207. #:host "foo"
  208. #:port 100
  209. #:path "/"
  210. #:fragment "bar"))
  211. (pass-if "http://foo?q#bar"
  212. (uri=? (string->uri "http://foo?q#bar")
  213. #:scheme 'http
  214. #:host "foo"
  215. #:path ""
  216. #:query "q"
  217. #:fragment "bar"))
  218. (pass-if "http://foo:/?q#bar"
  219. (uri=? (string->uri "http://foo:/?q#bar")
  220. #:scheme 'http
  221. #:host "foo"
  222. #:path "/"
  223. #:query "q"
  224. #:fragment "bar"))
  225. (pass-if "http://foo:100?q#bar"
  226. (uri=? (string->uri "http://foo:100?q#bar")
  227. #:scheme 'http
  228. #:host "foo"
  229. #:port 100
  230. #:path ""
  231. #:query "q"
  232. #:fragment "bar"))
  233. (pass-if "http://foo:100/?q#bar"
  234. (uri=? (string->uri "http://foo:100/?q#bar")
  235. #:scheme 'http
  236. #:host "foo"
  237. #:port 100
  238. #:path "/"
  239. #:query "q"
  240. #:fragment "bar")))
  241. (with-test-prefix "string->uri-reference"
  242. (pass-if "/foo"
  243. (uri=? (string->uri-reference "/foo")
  244. #:path "/foo"))
  245. (pass-if "ftp:/foo"
  246. (uri=? (string->uri-reference "ftp:/foo")
  247. #:scheme 'ftp
  248. #:path "/foo"))
  249. (pass-if "ftp:foo"
  250. (uri=? (string->uri-reference "ftp:foo")
  251. #:scheme 'ftp
  252. #:path "foo"))
  253. (pass-if "//foo/bar"
  254. (uri=? (string->uri-reference "//foo/bar")
  255. #:host "foo"
  256. #:path "/bar"))
  257. (pass-if "ftp://foo@bar:22/baz"
  258. (uri=? (string->uri-reference "ftp://foo@bar:22/baz")
  259. #:scheme 'ftp
  260. #:userinfo "foo"
  261. #:host "bar"
  262. #:port 22
  263. #:path "/baz"))
  264. (pass-if "//foo@bar:22/baz"
  265. (uri=? (string->uri-reference "//foo@bar:22/baz")
  266. #:userinfo "foo"
  267. #:host "bar"
  268. #:port 22
  269. #:path "/baz"))
  270. (pass-if "http://bad.host.1"
  271. (not (string->uri-reference "http://bad.host.1")))
  272. (pass-if "//bad.host.1"
  273. (not (string->uri-reference "//bad.host.1")))
  274. (pass-if "http://1.good.host"
  275. (uri=? (string->uri-reference "http://1.good.host")
  276. #:scheme 'http #:host "1.good.host" #:path ""))
  277. (pass-if "//1.good.host"
  278. (uri=? (string->uri-reference "//1.good.host")
  279. #:host "1.good.host" #:path ""))
  280. (when (memq 'socket *features*)
  281. (pass-if "http://192.0.2.1"
  282. (uri=? (string->uri-reference "http://192.0.2.1")
  283. #:scheme 'http #:host "192.0.2.1" #:path ""))
  284. (pass-if "//192.0.2.1"
  285. (uri=? (string->uri-reference "//192.0.2.1")
  286. #:host "192.0.2.1" #:path ""))
  287. (pass-if "http://[2001:db8::1]"
  288. (uri=? (string->uri-reference "http://[2001:db8::1]")
  289. #:scheme 'http #:host "2001:db8::1" #:path ""))
  290. (pass-if "//[2001:db8::1]"
  291. (uri=? (string->uri-reference "//[2001:db8::1]")
  292. #:host "2001:db8::1" #:path ""))
  293. (pass-if "http://[2001:db8::1]:80"
  294. (uri=? (string->uri-reference "http://[2001:db8::1]:80")
  295. #:scheme 'http
  296. #:host "2001:db8::1"
  297. #:port 80
  298. #:path ""))
  299. (pass-if "//[2001:db8::1]:80"
  300. (uri=? (string->uri-reference "//[2001:db8::1]:80")
  301. #:host "2001:db8::1"
  302. #:port 80
  303. #:path ""))
  304. (pass-if "http://[::ffff:192.0.2.1]"
  305. (uri=? (string->uri-reference "http://[::ffff:192.0.2.1]")
  306. #:scheme 'http #:host "::ffff:192.0.2.1" #:path ""))
  307. (pass-if "//[::ffff:192.0.2.1]"
  308. (uri=? (string->uri-reference "//[::ffff:192.0.2.1]")
  309. #:host "::ffff:192.0.2.1" #:path "")))
  310. (pass-if "http://foo:"
  311. (uri=? (string->uri-reference "http://foo:")
  312. #:scheme 'http #:host "foo" #:path ""))
  313. (pass-if "//foo:"
  314. (uri=? (string->uri-reference "//foo:")
  315. #:host "foo" #:path ""))
  316. (pass-if "http://foo:/"
  317. (uri=? (string->uri-reference "http://foo:/")
  318. #:scheme 'http #:host "foo" #:path "/"))
  319. (pass-if "//foo:/"
  320. (uri=? (string->uri-reference "//foo:/")
  321. #:host "foo" #:path "/"))
  322. (pass-if "http://2012.jsconf.us/"
  323. (uri=? (string->uri-reference "http://2012.jsconf.us/")
  324. #:scheme 'http #:host "2012.jsconf.us" #:path "/"))
  325. (pass-if "//2012.jsconf.us/"
  326. (uri=? (string->uri-reference "//2012.jsconf.us/")
  327. #:host "2012.jsconf.us" #:path "/"))
  328. (pass-if "http://foo:not-a-port"
  329. (not (string->uri-reference "http://foo:not-a-port")))
  330. (pass-if "//foo:not-a-port"
  331. (not (string->uri-reference "//foo:not-a-port")))
  332. (pass-if "http://:10"
  333. (not (string->uri-reference "http://:10")))
  334. (pass-if "//:10"
  335. (not (string->uri-reference "//:10")))
  336. (pass-if "http://foo@"
  337. (not (string->uri-reference "http://foo@")))
  338. (pass-if "//foo@"
  339. (not (string->uri-reference "//foo@")))
  340. (pass-if "file:/"
  341. (uri=? (string->uri-reference "file:/")
  342. #:scheme 'file
  343. #:path "/"))
  344. (pass-if "/"
  345. (uri=? (string->uri-reference "/")
  346. #:path "/"))
  347. (pass-if "foo"
  348. (uri=? (string->uri-reference "foo")
  349. #:path "foo"))
  350. (pass-if "file:/etc/hosts"
  351. (uri=? (string->uri-reference "file:/etc/hosts")
  352. #:scheme 'file
  353. #:path "/etc/hosts"))
  354. (pass-if "/etc/hosts"
  355. (uri=? (string->uri-reference "/etc/hosts")
  356. #:path "/etc/hosts"))
  357. (pass-if "file:///etc/hosts"
  358. (uri=? (string->uri-reference "file:///etc/hosts")
  359. #:scheme 'file
  360. #:path "/etc/hosts"))
  361. (pass-if "///etc/hosts"
  362. (uri=? (string->uri-reference "///etc/hosts")
  363. #:path "/etc/hosts"))
  364. (pass-if "/foo#bar"
  365. (uri=? (string->uri-reference "/foo#bar")
  366. #:path "/foo"
  367. #:fragment "bar"))
  368. (pass-if "//foo#bar"
  369. (uri=? (string->uri-reference "//foo#bar")
  370. #:host "foo"
  371. #:path ""
  372. #:fragment "bar"))
  373. (pass-if "//foo:/#bar"
  374. (uri=? (string->uri-reference "//foo:/#bar")
  375. #:host "foo"
  376. #:path "/"
  377. #:fragment "bar"))
  378. (pass-if "//foo:100#bar"
  379. (uri=? (string->uri-reference "//foo:100#bar")
  380. #:host "foo"
  381. #:port 100
  382. #:path ""
  383. #:fragment "bar"))
  384. (pass-if "//foo:100/#bar"
  385. (uri=? (string->uri-reference "//foo:100/#bar")
  386. #:host "foo"
  387. #:port 100
  388. #:path "/"
  389. #:fragment "bar"))
  390. (pass-if "/foo?q#bar"
  391. (uri=? (string->uri-reference "/foo?q#bar")
  392. #:path "/foo"
  393. #:query "q"
  394. #:fragment "bar"))
  395. (pass-if "//foo?q#bar"
  396. (uri=? (string->uri-reference "//foo?q#bar")
  397. #:host "foo"
  398. #:path ""
  399. #:query "q"
  400. #:fragment "bar"))
  401. (pass-if "//foo:/?q#bar"
  402. (uri=? (string->uri-reference "//foo:/?q#bar")
  403. #:host "foo"
  404. #:path "/"
  405. #:query "q"
  406. #:fragment "bar"))
  407. (pass-if "//foo:100?q#bar"
  408. (uri=? (string->uri-reference "//foo:100?q#bar")
  409. #:host "foo"
  410. #:port 100
  411. #:path ""
  412. #:query "q"
  413. #:fragment "bar"))
  414. (pass-if "//foo:100/?q#bar"
  415. (uri=? (string->uri-reference "//foo:100/?q#bar")
  416. #:host "foo"
  417. #:port 100
  418. #:path "/"
  419. #:query "q"
  420. #:fragment "bar")))
  421. (with-test-prefix "string->uri-reference"
  422. (pass-if "/"
  423. (uri=? (string->uri-reference "/")
  424. #:path "/"))
  425. (pass-if "/path/to/foo"
  426. (uri=? (string->uri-reference "/path/to/foo")
  427. #:path "/path/to/foo"))
  428. (pass-if "//example.org"
  429. (uri=? (string->uri-reference "//example.org")
  430. #:host "example.org"
  431. #:path ""))
  432. (pass-if "//bar@example.org/path/to/foo"
  433. (uri=? (string->uri-reference "//bar@example.org/path/to/foo")
  434. #:userinfo "bar"
  435. #:host "example.org"
  436. #:path "/path/to/foo"))
  437. (pass-if "nextdoc/foo"
  438. (uri=? (string->uri-reference "nextdoc/foo")
  439. #:path "nextdoc/foo")))
  440. (with-test-prefix "uri->string"
  441. (pass-if "ftp:"
  442. (equal? "ftp:"
  443. (uri->string (string->uri "ftp:"))))
  444. (pass-if "ftp:foo"
  445. (equal? "ftp:foo"
  446. (uri->string (string->uri "ftp:foo"))))
  447. (pass-if "ftp://foo/bar"
  448. (equal? "ftp://foo/bar"
  449. (uri->string (string->uri "ftp://foo/bar"))))
  450. (pass-if "//foo/bar"
  451. (equal? "//foo/bar"
  452. (uri->string (string->uri-reference "//foo/bar"))))
  453. (pass-if "ftp://foo@bar:22/baz"
  454. (equal? "ftp://foo@bar:22/baz"
  455. (uri->string (string->uri "ftp://foo@bar:22/baz"))))
  456. (pass-if "//foo@bar:22/baz"
  457. (equal? "//foo@bar:22/baz"
  458. (uri->string (string->uri-reference "//foo@bar:22/baz"))))
  459. (when (memq 'socket *features*)
  460. (pass-if "http://192.0.2.1"
  461. (equal? "http://192.0.2.1"
  462. (uri->string (string->uri "http://192.0.2.1"))))
  463. (pass-if "//192.0.2.1"
  464. (equal? "//192.0.2.1"
  465. (uri->string (string->uri-reference "//192.0.2.1"))))
  466. (pass-if "http://[2001:db8::1]"
  467. (equal? "http://[2001:db8::1]"
  468. (uri->string (string->uri "http://[2001:db8::1]"))))
  469. (pass-if "//[2001:db8::1]"
  470. (equal? "//[2001:db8::1]"
  471. (uri->string (string->uri-reference "//[2001:db8::1]"))))
  472. (pass-if "http://[::ffff:192.0.2.1]"
  473. (equal? "http://[::ffff:192.0.2.1]"
  474. (uri->string (string->uri "http://[::ffff:192.0.2.1]"))))
  475. (pass-if "//[::ffff:192.0.2.1]"
  476. (equal? "//[::ffff:192.0.2.1]"
  477. (uri->string (string->uri-reference "//[::ffff:192.0.2.1]")))))
  478. (pass-if "http://foo:"
  479. (equal? "http://foo"
  480. (uri->string (string->uri "http://foo:"))))
  481. (pass-if "//foo"
  482. (equal? "//foo"
  483. (uri->string (string->uri-reference "//foo"))))
  484. (pass-if "http://foo:/"
  485. (equal? "http://foo/"
  486. (uri->string (string->uri "http://foo:/"))))
  487. (pass-if "//foo:/"
  488. (equal? "//foo/"
  489. (uri->string (string->uri-reference "//foo:/"))))
  490. (pass-if "/"
  491. (equal? "/"
  492. (uri->string (string->uri-reference "/"))))
  493. (pass-if "/foo"
  494. (equal? "/foo"
  495. (uri->string (string->uri-reference "/foo"))))
  496. (pass-if "/foo/"
  497. (equal? "/foo/"
  498. (uri->string (string->uri-reference "/foo/"))))
  499. (pass-if "/foo/?bar#baz"
  500. (equal? "/foo/?bar#baz"
  501. (uri->string (string->uri-reference "/foo/?bar#baz"))))
  502. (pass-if "foo/?bar#baz"
  503. (equal? "foo/?bar#baz"
  504. (uri->string (string->uri-reference "foo/?bar#baz"))))
  505. (pass-if "/path/to/foo"
  506. (equal? "/path/to/foo"
  507. (uri->string (string->uri-reference "/path/to/foo"))))
  508. (pass-if "//example.org"
  509. (equal? "//example.org"
  510. (uri->string (string->uri-reference "//example.org"))))
  511. (pass-if "//bar@example.org/path/to/foo"
  512. (equal? "//bar@example.org/path/to/foo"
  513. (uri->string (string->uri-reference "//bar@example.org/path/to/foo"))))
  514. (pass-if "nextdoc/foo"
  515. (equal? "nextdoc/foo"
  516. (uri->string (string->uri-reference "nextdoc/foo")))))
  517. (with-test-prefix "decode"
  518. (pass-if "foo%20bar"
  519. (equal? "foo bar" (uri-decode "foo%20bar")))
  520. (pass-if "foo+bar"
  521. (equal? "foo bar" (uri-decode "foo+bar")))
  522. (pass-if "foo+bar"
  523. (equal? '("foo+bar") (split-and-decode-uri-path "foo+bar"))))
  524. (with-test-prefix "encode"
  525. (pass-if (equal? "foo%20bar" (uri-encode "foo bar")))
  526. (pass-if (equal? "foo%0A%00bar" (uri-encode "foo\n\x00bar")))
  527. (pass-if (equal? "%3C%3E%5C%5E" (uri-encode "<>\\^"))))