urltest.lua 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. local socket = require("socket")
  2. socket.url = require("socket.url")
  3. dofile("testsupport.lua")
  4. local check_build_url = function(parsed)
  5. local built = socket.url.build(parsed)
  6. if built ~= parsed.url then
  7. print("built is different from expected")
  8. print(built)
  9. print(expected)
  10. os.exit()
  11. end
  12. end
  13. local check_protect = function(parsed, path, unsafe)
  14. local built = socket.url.build_path(parsed, unsafe)
  15. if built ~= path then
  16. print(built, path)
  17. print("path composition failed.")
  18. os.exit()
  19. end
  20. end
  21. local check_invert = function(url)
  22. local parsed = socket.url.parse(url)
  23. parsed.path = socket.url.build_path(socket.url.parse_path(parsed.path))
  24. local rebuilt = socket.url.build(parsed)
  25. if rebuilt ~= url then
  26. print(url, rebuilt)
  27. print("original and rebuilt are different")
  28. os.exit()
  29. end
  30. end
  31. local check_parse_path = function(path, expect)
  32. local parsed = socket.url.parse_path(path)
  33. for i = 1, math.max(#parsed, #expect) do
  34. if parsed[i] ~= expect[i] then
  35. print(path)
  36. os.exit()
  37. end
  38. end
  39. if expect.is_directory ~= parsed.is_directory then
  40. print(path)
  41. print("is_directory mismatch")
  42. os.exit()
  43. end
  44. if expect.is_absolute ~= parsed.is_absolute then
  45. print(path)
  46. print("is_absolute mismatch")
  47. os.exit()
  48. end
  49. local built = socket.url.build_path(expect)
  50. if built ~= path then
  51. print(built, path)
  52. print("path composition failed.")
  53. os.exit()
  54. end
  55. end
  56. local check_absolute_url = function(base, relative, absolute)
  57. local res = socket.url.absolute(base, relative)
  58. if res ~= absolute then
  59. io.write("absolute: In test for '", relative, "' expected '",
  60. absolute, "' but got '", res, "'\n")
  61. os.exit()
  62. end
  63. end
  64. local check_parse_url = function(gaba)
  65. local url = gaba.url
  66. gaba.url = nil
  67. local parsed = socket.url.parse(url)
  68. for i, v in pairs(gaba) do
  69. if v ~= parsed[i] then
  70. io.write("parse: In test for '", url, "' expected ", i, " = '",
  71. v, "' but got '", tostring(parsed[i]), "'\n")
  72. for i,v in pairs(parsed) do print(i,v) end
  73. os.exit()
  74. end
  75. end
  76. for i, v in pairs(parsed) do
  77. if v ~= gaba[i] then
  78. io.write("parse: In test for '", url, "' expected ", i, " = '",
  79. tostring(gaba[i]), "' but got '", v, "'\n")
  80. for i,v in pairs(parsed) do print(i,v) end
  81. os.exit()
  82. end
  83. end
  84. end
  85. print("testing URL parsing")
  86. check_parse_url{
  87. url = "scheme://user:pass$%?#wd@host:port/path;params?query#fragment",
  88. scheme = "scheme",
  89. authority = "user:pass$%?#wd@host:port",
  90. host = "host",
  91. port = "port",
  92. userinfo = "user:pass$%?#wd",
  93. password = "pass$%?#wd",
  94. user = "user",
  95. path = "/path",
  96. params = "params",
  97. query = "query",
  98. fragment = "fragment"
  99. }
  100. check_parse_url{
  101. url = "scheme://user:pass?#wd@host:port/path;params?query#fragment",
  102. scheme = "scheme",
  103. authority = "user:pass?#wd@host:port",
  104. host = "host",
  105. port = "port",
  106. userinfo = "user:pass?#wd",
  107. password = "pass?#wd",
  108. user = "user",
  109. path = "/path",
  110. params = "params",
  111. query = "query",
  112. fragment = "fragment"
  113. }
  114. check_parse_url{
  115. url = "scheme://user:pass-wd@host:port/path;params?query#fragment",
  116. scheme = "scheme",
  117. authority = "user:pass-wd@host:port",
  118. host = "host",
  119. port = "port",
  120. userinfo = "user:pass-wd",
  121. password = "pass-wd",
  122. user = "user",
  123. path = "/path",
  124. params = "params",
  125. query = "query",
  126. fragment = "fragment"
  127. }
  128. check_parse_url{
  129. url = "scheme://user:pass#wd@host:port/path;params?query#fragment",
  130. scheme = "scheme",
  131. authority = "user:pass#wd@host:port",
  132. host = "host",
  133. port = "port",
  134. userinfo = "user:pass#wd",
  135. password = "pass#wd",
  136. user = "user",
  137. path = "/path",
  138. params = "params",
  139. query = "query",
  140. fragment = "fragment"
  141. }
  142. check_parse_url{
  143. url = "scheme://user:pass#wd@host:port/path;params?query",
  144. scheme = "scheme",
  145. authority = "user:pass#wd@host:port",
  146. host = "host",
  147. port = "port",
  148. userinfo = "user:pass#wd",
  149. password = "pass#wd",
  150. user = "user",
  151. path = "/path",
  152. params = "params",
  153. query = "query",
  154. }
  155. check_parse_url{
  156. url = "scheme://userinfo@host:port/path;params?query#fragment",
  157. scheme = "scheme",
  158. authority = "userinfo@host:port",
  159. host = "host",
  160. port = "port",
  161. userinfo = "userinfo",
  162. user = "userinfo",
  163. path = "/path",
  164. params = "params",
  165. query = "query",
  166. fragment = "fragment"
  167. }
  168. check_parse_url{
  169. url = "scheme://user:password@host:port/path;params?query#fragment",
  170. scheme = "scheme",
  171. authority = "user:password@host:port",
  172. host = "host",
  173. port = "port",
  174. userinfo = "user:password",
  175. user = "user",
  176. password = "password",
  177. path = "/path",
  178. params = "params",
  179. query = "query",
  180. fragment = "fragment",
  181. }
  182. check_parse_url{
  183. url = "scheme://userinfo@host:port/path;params?query#",
  184. scheme = "scheme",
  185. authority = "userinfo@host:port",
  186. host = "host",
  187. port = "port",
  188. userinfo = "userinfo",
  189. user = "userinfo",
  190. path = "/path",
  191. params = "params",
  192. query = "query",
  193. fragment = ""
  194. }
  195. check_parse_url{
  196. url = "scheme://userinfo@host:port/path;params?#fragment",
  197. scheme = "scheme",
  198. authority = "userinfo@host:port",
  199. host = "host",
  200. port = "port",
  201. userinfo = "userinfo",
  202. user = "userinfo",
  203. path = "/path",
  204. params = "params",
  205. query = "",
  206. fragment = "fragment"
  207. }
  208. check_parse_url{
  209. url = "scheme://userinfo@host:port/path;params#fragment",
  210. scheme = "scheme",
  211. authority = "userinfo@host:port",
  212. host = "host",
  213. port = "port",
  214. userinfo = "userinfo",
  215. user = "userinfo",
  216. path = "/path",
  217. params = "params",
  218. fragment = "fragment"
  219. }
  220. check_parse_url{
  221. url = "scheme://userinfo@host:port/path;?query#fragment",
  222. scheme = "scheme",
  223. authority = "userinfo@host:port",
  224. host = "host",
  225. port = "port",
  226. userinfo = "userinfo",
  227. user = "userinfo",
  228. path = "/path",
  229. params = "",
  230. query = "query",
  231. fragment = "fragment"
  232. }
  233. check_parse_url{
  234. url = "scheme://userinfo@host:port/path?query#fragment",
  235. scheme = "scheme",
  236. authority = "userinfo@host:port",
  237. host = "host",
  238. port = "port",
  239. userinfo = "userinfo",
  240. user = "userinfo",
  241. path = "/path",
  242. query = "query",
  243. fragment = "fragment"
  244. }
  245. check_parse_url{
  246. url = "scheme://userinfo@host:port/;params?query#fragment",
  247. scheme = "scheme",
  248. authority = "userinfo@host:port",
  249. host = "host",
  250. port = "port",
  251. userinfo = "userinfo",
  252. user = "userinfo",
  253. path = "/",
  254. params = "params",
  255. query = "query",
  256. fragment = "fragment"
  257. }
  258. check_parse_url{
  259. url = "scheme://userinfo@host:port",
  260. scheme = "scheme",
  261. authority = "userinfo@host:port",
  262. host = "host",
  263. port = "port",
  264. userinfo = "userinfo",
  265. user = "userinfo",
  266. }
  267. check_parse_url{
  268. url = "//userinfo@host:port/path;params?query#fragment",
  269. authority = "userinfo@host:port",
  270. host = "host",
  271. port = "port",
  272. userinfo = "userinfo",
  273. user = "userinfo",
  274. path = "/path",
  275. params = "params",
  276. query = "query",
  277. fragment = "fragment"
  278. }
  279. check_parse_url{
  280. url = "//userinfo@host:port/path",
  281. authority = "userinfo@host:port",
  282. host = "host",
  283. port = "port",
  284. userinfo = "userinfo",
  285. user = "userinfo",
  286. path = "/path",
  287. }
  288. check_parse_url{
  289. url = "//userinfo@host/path",
  290. authority = "userinfo@host",
  291. host = "host",
  292. userinfo = "userinfo",
  293. user = "userinfo",
  294. path = "/path",
  295. }
  296. check_parse_url{
  297. url = "//user:password@host/path",
  298. authority = "user:password@host",
  299. host = "host",
  300. userinfo = "user:password",
  301. password = "password",
  302. user = "user",
  303. path = "/path",
  304. }
  305. check_parse_url{
  306. url = "//user:@host/path",
  307. authority = "user:@host",
  308. host = "host",
  309. userinfo = "user:",
  310. password = "",
  311. user = "user",
  312. path = "/path",
  313. }
  314. check_parse_url{
  315. url = "//user@host:port/path",
  316. authority = "user@host:port",
  317. host = "host",
  318. userinfo = "user",
  319. user = "user",
  320. port = "port",
  321. path = "/path",
  322. }
  323. check_parse_url{
  324. url = "//host:port/path",
  325. authority = "host:port",
  326. port = "port",
  327. host = "host",
  328. path = "/path",
  329. }
  330. check_parse_url{
  331. url = "//host/path",
  332. authority = "host",
  333. host = "host",
  334. path = "/path",
  335. }
  336. check_parse_url{
  337. url = "//host",
  338. authority = "host",
  339. host = "host",
  340. }
  341. check_parse_url{
  342. url = "/path",
  343. path = "/path",
  344. }
  345. check_parse_url{
  346. url = "path",
  347. path = "path",
  348. }
  349. -- IPv6 tests
  350. check_parse_url{
  351. url = "http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html",
  352. scheme = "http",
  353. host = "FEDC:BA98:7654:3210:FEDC:BA98:7654:3210",
  354. authority = "[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80",
  355. port = "80",
  356. path = "/index.html"
  357. }
  358. check_parse_url{
  359. url = "http://[1080:0:0:0:8:800:200C:417A]/index.html",
  360. scheme = "http",
  361. host = "1080:0:0:0:8:800:200C:417A",
  362. authority = "[1080:0:0:0:8:800:200C:417A]",
  363. path = "/index.html"
  364. }
  365. check_parse_url{
  366. url = "http://[3ffe:2a00:100:7031::1]",
  367. scheme = "http",
  368. host = "3ffe:2a00:100:7031::1",
  369. authority = "[3ffe:2a00:100:7031::1]",
  370. }
  371. check_parse_url{
  372. url = "http://[1080::8:800:200C:417A]/foo",
  373. scheme = "http",
  374. host = "1080::8:800:200C:417A",
  375. authority = "[1080::8:800:200C:417A]",
  376. path = "/foo"
  377. }
  378. check_parse_url{
  379. url = "http://[::192.9.5.5]/ipng",
  380. scheme = "http",
  381. host = "::192.9.5.5",
  382. authority = "[::192.9.5.5]",
  383. path = "/ipng"
  384. }
  385. check_parse_url{
  386. url = "http://[::FFFF:129.144.52.38]:80/index.html",
  387. scheme = "http",
  388. host = "::FFFF:129.144.52.38",
  389. port = "80",
  390. authority = "[::FFFF:129.144.52.38]:80",
  391. path = "/index.html"
  392. }
  393. check_parse_url{
  394. url = "http://[2010:836B:4179::836B:4179]",
  395. scheme = "http",
  396. host = "2010:836B:4179::836B:4179",
  397. authority = "[2010:836B:4179::836B:4179]",
  398. }
  399. check_parse_url{
  400. url = "//userinfo@[::FFFF:129.144.52.38]:port/path;params?query#fragment",
  401. authority = "userinfo@[::FFFF:129.144.52.38]:port",
  402. host = "::FFFF:129.144.52.38",
  403. port = "port",
  404. userinfo = "userinfo",
  405. user = "userinfo",
  406. path = "/path",
  407. params = "params",
  408. query = "query",
  409. fragment = "fragment"
  410. }
  411. check_parse_url{
  412. url = "scheme://user:password@[::192.9.5.5]:port/path;params?query#fragment",
  413. scheme = "scheme",
  414. authority = "user:password@[::192.9.5.5]:port",
  415. host = "::192.9.5.5",
  416. port = "port",
  417. userinfo = "user:password",
  418. user = "user",
  419. password = "password",
  420. path = "/path",
  421. params = "params",
  422. query = "query",
  423. fragment = "fragment"
  424. }
  425. print("testing URL building")
  426. check_build_url {
  427. url = "scheme://user:password@host:port/path;params?query#fragment",
  428. scheme = "scheme",
  429. host = "host",
  430. port = "port",
  431. user = "user",
  432. password = "password",
  433. path = "/path",
  434. params = "params",
  435. query = "query",
  436. fragment = "fragment"
  437. }
  438. check_build_url{
  439. url = "//userinfo@[::FFFF:129.144.52.38]:port/path;params?query#fragment",
  440. host = "::FFFF:129.144.52.38",
  441. port = "port",
  442. user = "userinfo",
  443. path = "/path",
  444. params = "params",
  445. query = "query",
  446. fragment = "fragment"
  447. }
  448. check_build_url{
  449. url = "scheme://user:password@[::192.9.5.5]:port/path;params?query#fragment",
  450. scheme = "scheme",
  451. host = "::192.9.5.5",
  452. port = "port",
  453. user = "user",
  454. password = "password",
  455. path = "/path",
  456. params = "params",
  457. query = "query",
  458. fragment = "fragment"
  459. }
  460. check_build_url {
  461. url = "scheme://user:password@host/path;params?query#fragment",
  462. scheme = "scheme",
  463. host = "host",
  464. user = "user",
  465. password = "password",
  466. path = "/path",
  467. params = "params",
  468. query = "query",
  469. fragment = "fragment"
  470. }
  471. check_build_url {
  472. url = "scheme://user@host/path;params?query#fragment",
  473. scheme = "scheme",
  474. host = "host",
  475. user = "user",
  476. path = "/path",
  477. params = "params",
  478. query = "query",
  479. fragment = "fragment"
  480. }
  481. check_build_url {
  482. url = "scheme://host/path;params?query#fragment",
  483. scheme = "scheme",
  484. host = "host",
  485. path = "/path",
  486. params = "params",
  487. query = "query",
  488. fragment = "fragment"
  489. }
  490. check_build_url {
  491. url = "scheme://host/path;params#fragment",
  492. scheme = "scheme",
  493. host = "host",
  494. path = "/path",
  495. params = "params",
  496. fragment = "fragment"
  497. }
  498. check_build_url {
  499. url = "scheme://host/path#fragment",
  500. scheme = "scheme",
  501. host = "host",
  502. path = "/path",
  503. fragment = "fragment"
  504. }
  505. check_build_url {
  506. url = "scheme://host/path",
  507. scheme = "scheme",
  508. host = "host",
  509. path = "/path",
  510. }
  511. check_build_url {
  512. url = "//host/path",
  513. host = "host",
  514. path = "/path",
  515. }
  516. check_build_url {
  517. url = "/path",
  518. path = "/path",
  519. }
  520. check_build_url {
  521. url = "scheme://user:password@host:port/path;params?query#fragment",
  522. scheme = "scheme",
  523. host = "host",
  524. port = "port",
  525. user = "user",
  526. userinfo = "not used",
  527. password = "password",
  528. path = "/path",
  529. params = "params",
  530. query = "query",
  531. fragment = "fragment"
  532. }
  533. check_build_url {
  534. url = "scheme://user:password@host:port/path;params?query#fragment",
  535. scheme = "scheme",
  536. host = "host",
  537. port = "port",
  538. user = "user",
  539. userinfo = "not used",
  540. authority = "not used",
  541. password = "password",
  542. path = "/path",
  543. params = "params",
  544. query = "query",
  545. fragment = "fragment"
  546. }
  547. check_build_url {
  548. url = "scheme://user:password@host:port/path;params?query#fragment",
  549. scheme = "scheme",
  550. host = "host",
  551. port = "port",
  552. userinfo = "user:password",
  553. authority = "not used",
  554. path = "/path",
  555. params = "params",
  556. query = "query",
  557. fragment = "fragment"
  558. }
  559. check_build_url {
  560. url = "scheme://user:password@host:port/path;params?query#fragment",
  561. scheme = "scheme",
  562. authority = "user:password@host:port",
  563. path = "/path",
  564. params = "params",
  565. query = "query",
  566. fragment = "fragment"
  567. }
  568. -- standard RFC tests
  569. print("testing absolute resolution")
  570. check_absolute_url("http://a/b/c/d;p?q#f", "g:h", "g:h")
  571. check_absolute_url("http://a/b/c/d;p?q#f", "g", "http://a/b/c/g")
  572. check_absolute_url("http://a/b/c/d;p?q#f", "./g", "http://a/b/c/g")
  573. check_absolute_url("http://a/b/c/d;p?q#f", "g/", "http://a/b/c/g/")
  574. check_absolute_url("http://a/b/c/d;p?q#f", "/g", "http://a/g")
  575. check_absolute_url("http://a/b/c/d;p?q#f", "//g", "http://g")
  576. check_absolute_url("http://a/b/c/d;p?q#f", "?y", "http://a/b/c/d;p?y")
  577. check_absolute_url("http://a/b/c/d;p?q#f", "g?y", "http://a/b/c/g?y")
  578. check_absolute_url("http://a/b/c/d;p?q#f", "g?y/./x", "http://a/b/c/g?y/./x")
  579. check_absolute_url("http://a/b/c/d;p?q#f", "#s", "http://a/b/c/d;p?q#s")
  580. check_absolute_url("http://a/b/c/d;p?q#f", "g#s", "http://a/b/c/g#s")
  581. check_absolute_url("http://a/b/c/d;p?q#f", "g#s/./x", "http://a/b/c/g#s/./x")
  582. check_absolute_url("http://a/b/c/d;p?q#f", "g?y#s", "http://a/b/c/g?y#s")
  583. check_absolute_url("http://a/b/c/d;p?q#f", ";x", "http://a/b/c/d;x")
  584. check_absolute_url("http://a/b/c/d;p?q#f", "g;x", "http://a/b/c/g;x")
  585. check_absolute_url("http://a/b/c/d;p?q#f", "g;x?y#s", "http://a/b/c/g;x?y#s")
  586. check_absolute_url("http://a/b/c/d;p?q#f", ".", "http://a/b/c/")
  587. check_absolute_url("http://a/b/c/d;p?q#f", "./", "http://a/b/c/")
  588. check_absolute_url("http://a/b/c/d;p?q#f", "..", "http://a/b/")
  589. check_absolute_url("http://a/b/c/d;p?q#f", "../", "http://a/b/")
  590. check_absolute_url("http://a/b/c/d;p?q#f", "../g", "http://a/b/g")
  591. check_absolute_url("http://a/b/c/d;p?q#f", "../..", "http://a/")
  592. check_absolute_url("http://a/b/c/d;p?q#f", "../../", "http://a/")
  593. check_absolute_url("http://a/b/c/d;p?q#f", "../../g", "http://a/g")
  594. check_absolute_url("http://a/b/c/d;p?q#f", "", "http://a/b/c/d;p?q#f")
  595. check_absolute_url("http://a/b/c/d;p?q#f", "/./g", "http://a/./g")
  596. check_absolute_url("http://a/b/c/d;p?q#f", "/../g", "http://a/../g")
  597. check_absolute_url("http://a/b/c/d;p?q#f", "g.", "http://a/b/c/g.")
  598. check_absolute_url("http://a/b/c/d;p?q#f", ".g", "http://a/b/c/.g")
  599. check_absolute_url("http://a/b/c/d;p?q#f", "g..", "http://a/b/c/g..")
  600. check_absolute_url("http://a/b/c/d;p?q#f", "..g", "http://a/b/c/..g")
  601. check_absolute_url("http://a/b/c/d;p?q#f", "./../g", "http://a/b/g")
  602. check_absolute_url("http://a/b/c/d;p?q#f", "./g/.", "http://a/b/c/g/")
  603. check_absolute_url("http://a/b/c/d;p?q#f", "g/./h", "http://a/b/c/g/h")
  604. check_absolute_url("http://a/b/c/d;p?q#f", "g/../h", "http://a/b/c/h")
  605. -- extra tests
  606. check_absolute_url("//a/b/c/d;p?q#f", "d/e/f", "//a/b/c/d/e/f")
  607. check_absolute_url("/a/b/c/d;p?q#f", "d/e/f", "/a/b/c/d/e/f")
  608. check_absolute_url("a/b/c/d", "d/e/f", "a/b/c/d/e/f")
  609. check_absolute_url("a/b/c/d/../", "d/e/f", "a/b/c/d/e/f")
  610. check_absolute_url("http://velox.telemar.com.br", "/dashboard/index.html",
  611. "http://velox.telemar.com.br/dashboard/index.html")
  612. print("testing path parsing and composition")
  613. check_parse_path("/eu/tu/ele", { "eu", "tu", "ele"; is_absolute = 1 })
  614. check_parse_path("/eu/", { "eu"; is_absolute = 1, is_directory = 1 })
  615. check_parse_path("eu/tu/ele/nos/vos/eles/",
  616. { "eu", "tu", "ele", "nos", "vos", "eles"; is_directory = 1})
  617. check_parse_path("/", { is_absolute = 1, is_directory = 1})
  618. check_parse_path("", { })
  619. check_parse_path("eu%01/%02tu/e%03l%04e/nos/vos%05/e%12les/",
  620. { "eu\1", "\2tu", "e\3l\4e", "nos", "vos\5", "e\18les"; is_directory = 1})
  621. check_parse_path("eu/tu", { "eu", "tu" })
  622. print("testing path protection")
  623. check_protect({ "eu", "-_.!~*'():@&=+$,", "tu" }, "eu/-_.!~*'():@&=+$,/tu")
  624. check_protect({ "eu ", "~diego" }, "eu%20/~diego")
  625. check_protect({ "/eu>", "<diego?" }, "%2Feu%3E/%3Cdiego%3F")
  626. check_protect({ "\\eu]", "[diego`" }, "%5Ceu%5D/%5Bdiego%60")
  627. check_protect({ "{eu}", "|diego\127" }, "%7Beu%7D/%7Cdiego%7F")
  628. check_protect({ "eu ", "~diego" }, "eu /~diego", 1)
  629. check_protect({ "/eu>", "<diego?" }, "/eu>/<diego?", 1)
  630. check_protect({ "\\eu]", "[diego`" }, "\\eu]/[diego`", 1)
  631. check_protect({ "{eu}", "|diego\127" }, "{eu}/|diego\127", 1)
  632. print("testing inversion")
  633. check_invert("http:")
  634. check_invert("a/b/c/d.html")
  635. check_invert("//net_loc")
  636. check_invert("http:a/b/d/c.html")
  637. check_invert("//net_loc/a/b/d/c.html")
  638. check_invert("http://net_loc/a/b/d/c.html")
  639. check_invert("//who:isit@net_loc")
  640. check_invert("http://he:[email protected]/a/b/c/i.html;type=moo?this=that#mark")
  641. check_invert("/b/c/d#fragment")
  642. check_invert("/b/c/d;param#fragment")
  643. check_invert("/b/c/d;param?query#fragment")
  644. check_invert("/b/c/d?query")
  645. check_invert("/b/c/d;param?query")
  646. check_invert("http://he:man@[::192.168.1.1]/a/b/c/i.html;type=moo?this=that#mark")
  647. print("the library passed all tests")