setters_tests.json 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148
  1. {
  2. "comment": [
  3. "## Tests for setters of https://url.spec.whatwg.org/#urlutils-members",
  4. "",
  5. "This file contains a JSON object.",
  6. "Other than 'comment', each key is an attribute of the `URL` interface",
  7. "defined in WHATWG’s URL Standard.",
  8. "The values are arrays of test case objects for that attribute.",
  9. "",
  10. "To run a test case for the attribute `attr`:",
  11. "",
  12. "* Create a new `URL` object with the value for the 'href' key",
  13. " the constructor single parameter. (Without a base URL.)",
  14. " This must not throw.",
  15. "* Set the attribute `attr` to (invoke its setter with)",
  16. " with the value of for 'new_value' key.",
  17. "* The value for the 'expected' key is another object.",
  18. " For each `key` / `value` pair of that object,",
  19. " get the attribute `key` (invoke its getter).",
  20. " The returned string must be equal to `value`.",
  21. "",
  22. "Note: the 'href' setter is already covered by urltestdata.json."
  23. ],
  24. "protocol": [
  25. {
  26. "comment": "The empty string is not a valid scheme. Setter leaves the URL unchanged.",
  27. "href": "a://example.net",
  28. "new_value": "",
  29. "expected": {
  30. "href": "a://example.net/",
  31. "protocol": "a:"
  32. }
  33. },
  34. {
  35. "href": "a://example.net",
  36. "new_value": "b",
  37. "expected": {
  38. "href": "b://example.net/",
  39. "protocol": "b:"
  40. }
  41. },
  42. {
  43. "comment": "Upper-case ASCII is lower-cased",
  44. "href": "a://example.net",
  45. "new_value": "B",
  46. "expected": {
  47. "href": "b://example.net/",
  48. "protocol": "b:"
  49. }
  50. },
  51. {
  52. "comment": "Non-ASCII is rejected",
  53. "href": "a://example.net",
  54. "new_value": "é",
  55. "expected": {
  56. "href": "a://example.net/",
  57. "protocol": "a:"
  58. }
  59. },
  60. {
  61. "comment": "No leading digit",
  62. "href": "a://example.net",
  63. "new_value": "0b",
  64. "expected": {
  65. "href": "a://example.net/",
  66. "protocol": "a:"
  67. }
  68. },
  69. {
  70. "comment": "No leading punctuation",
  71. "href": "a://example.net",
  72. "new_value": "+b",
  73. "expected": {
  74. "href": "a://example.net/",
  75. "protocol": "a:"
  76. }
  77. },
  78. {
  79. "href": "a://example.net",
  80. "new_value": "bC0+-.",
  81. "expected": {
  82. "href": "bc0+-.://example.net/",
  83. "protocol": "bc0+-.:"
  84. }
  85. },
  86. {
  87. "comment": "Only some punctuation is acceptable",
  88. "href": "a://example.net",
  89. "new_value": "b,c",
  90. "expected": {
  91. "href": "a://example.net/",
  92. "protocol": "a:"
  93. }
  94. },
  95. {
  96. "comment": "Non-ASCII is rejected",
  97. "href": "a://example.net",
  98. "new_value": "bé",
  99. "expected": {
  100. "href": "a://example.net/",
  101. "protocol": "a:"
  102. }
  103. },
  104. {
  105. "comment": "Spec deviation: from special scheme to not is not problematic. https://github.com/whatwg/url/issues/104",
  106. "href": "http://example.net",
  107. "new_value": "b",
  108. "expected": {
  109. "href": "b://example.net/",
  110. "protocol": "b:"
  111. }
  112. },
  113. {
  114. "comment": "Cannot-be-a-base URL doesn’t have a host, but URL in a special scheme must.",
  115. "href": "mailto:me@example.net",
  116. "new_value": "http",
  117. "expected": {
  118. "href": "mailto:me@example.net",
  119. "protocol": "mailto:"
  120. }
  121. },
  122. {
  123. "comment": "Spec deviation: from non-special scheme with a host to special is not problematic. https://github.com/whatwg/url/issues/104",
  124. "href": "ssh://me@example.net",
  125. "new_value": "http",
  126. "expected": {
  127. "href": "http://me@example.net/",
  128. "protocol": "http:"
  129. }
  130. },
  131. {
  132. "comment": "Stuff after the first ':' is ignored",
  133. "href": "http://example.net",
  134. "new_value": "https:foo : bar",
  135. "expected": {
  136. "href": "https://example.net/",
  137. "protocol": "https:"
  138. }
  139. },
  140. {
  141. "comment": "Stuff after the first ':' is ignored",
  142. "href": "data:text/html,<p>Test",
  143. "new_value": "view-source+data:foo : bar",
  144. "expected": {
  145. "href": "view-source+data:text/html,<p>Test",
  146. "protocol": "view-source+data:"
  147. }
  148. }
  149. ],
  150. "username": [
  151. {
  152. "comment": "No host means no username",
  153. "href": "file:///home/you/index.html",
  154. "new_value": "me",
  155. "expected": {
  156. "href": "file:///home/you/index.html",
  157. "username": ""
  158. }
  159. },
  160. {
  161. "comment": "No host means no username",
  162. "href": "unix:/run/foo.socket",
  163. "new_value": "me",
  164. "expected": {
  165. "href": "unix:/run/foo.socket",
  166. "username": ""
  167. }
  168. },
  169. {
  170. "comment": "Cannot-be-a-base means no username",
  171. "href": "mailto:you@example.net",
  172. "new_value": "me",
  173. "expected": {
  174. "href": "mailto:you@example.net",
  175. "username": ""
  176. }
  177. },
  178. {
  179. "href": "http://example.net",
  180. "new_value": "me",
  181. "expected": {
  182. "href": "http://me@example.net/",
  183. "username": "me"
  184. }
  185. },
  186. {
  187. "href": "http://:secret@example.net",
  188. "new_value": "me",
  189. "expected": {
  190. "href": "http://me:secret@example.net/",
  191. "username": "me"
  192. }
  193. },
  194. {
  195. "href": "http://me@example.net",
  196. "new_value": "",
  197. "expected": {
  198. "href": "http://example.net/",
  199. "username": ""
  200. }
  201. },
  202. {
  203. "href": "http://me:secret@example.net",
  204. "new_value": "",
  205. "expected": {
  206. "href": "http://:secret@example.net/",
  207. "username": ""
  208. }
  209. },
  210. {
  211. "comment": "UTF-8 percent encoding with the userinfo encode set.",
  212. "href": "http://example.net",
  213. "new_value": "\u0000\u0001\t\n\r\u001f !\"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~\u007f\u0080\u0081Éé",
  214. "expected": {
  215. "href": "http://%00%01%09%0A%0D%1F%20!%22%23$%&'()*+,-.%2F09%3A%3B%3C%3D%3E%3F%40AZ%5B%5C%5D%5E_%60az%7B%7C%7D~%7F%C2%80%C2%81%C3%89%C3%A9@example.net/",
  216. "username": "%00%01%09%0A%0D%1F%20!%22%23$%&'()*+,-.%2F09%3A%3B%3C%3D%3E%3F%40AZ%5B%5C%5D%5E_%60az%7B%7C%7D~%7F%C2%80%C2%81%C3%89%C3%A9"
  217. }
  218. },
  219. {
  220. "comment": "Bytes already percent-encoded are left as-is.",
  221. "href": "http://example.net",
  222. "new_value": "%c3%89té",
  223. "expected": {
  224. "href": "http://%c3%89t%C3%A9@example.net/",
  225. "username": "%c3%89t%C3%A9"
  226. }
  227. }
  228. ],
  229. "password": [
  230. {
  231. "comment": "No host means no password",
  232. "href": "file:///home/me/index.html",
  233. "new_value": "secret",
  234. "expected": {
  235. "href": "file:///home/me/index.html",
  236. "password": ""
  237. }
  238. },
  239. {
  240. "comment": "No host means no password",
  241. "href": "unix:/run/foo.socket",
  242. "new_value": "secret",
  243. "expected": {
  244. "href": "unix:/run/foo.socket",
  245. "password": ""
  246. }
  247. },
  248. {
  249. "comment": "Cannot-be-a-base means no password",
  250. "href": "mailto:me@example.net",
  251. "new_value": "secret",
  252. "expected": {
  253. "href": "mailto:me@example.net",
  254. "password": ""
  255. }
  256. },
  257. {
  258. "href": "http://example.net",
  259. "new_value": "secret",
  260. "expected": {
  261. "href": "http://:secret@example.net/",
  262. "password": "secret"
  263. }
  264. },
  265. {
  266. "href": "http://me@example.net",
  267. "new_value": "secret",
  268. "expected": {
  269. "href": "http://me:secret@example.net/",
  270. "password": "secret"
  271. }
  272. },
  273. {
  274. "href": "http://:secret@example.net",
  275. "new_value": "",
  276. "expected": {
  277. "href": "http://example.net/",
  278. "password": ""
  279. }
  280. },
  281. {
  282. "href": "http://me:secret@example.net",
  283. "new_value": "",
  284. "expected": {
  285. "href": "http://me@example.net/",
  286. "password": ""
  287. }
  288. },
  289. {
  290. "comment": "UTF-8 percent encoding with the userinfo encode set.",
  291. "href": "http://example.net",
  292. "new_value": "\u0000\u0001\t\n\r\u001f !\"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~\u007f\u0080\u0081Éé",
  293. "expected": {
  294. "href": "http://:%00%01%09%0A%0D%1F%20!%22%23$%&'()*+,-.%2F09%3A%3B%3C%3D%3E%3F%40AZ%5B%5C%5D%5E_%60az%7B%7C%7D~%7F%C2%80%C2%81%C3%89%C3%A9@example.net/",
  295. "password": "%00%01%09%0A%0D%1F%20!%22%23$%&'()*+,-.%2F09%3A%3B%3C%3D%3E%3F%40AZ%5B%5C%5D%5E_%60az%7B%7C%7D~%7F%C2%80%C2%81%C3%89%C3%A9"
  296. }
  297. },
  298. {
  299. "comment": "Bytes already percent-encoded are left as-is.",
  300. "href": "http://example.net",
  301. "new_value": "%c3%89té",
  302. "expected": {
  303. "href": "http://:%c3%89t%C3%A9@example.net/",
  304. "password": "%c3%89t%C3%A9"
  305. }
  306. }
  307. ],
  308. "host": [
  309. {
  310. "comment": "Cannot-be-a-base means no host",
  311. "href": "mailto:me@example.net",
  312. "new_value": "example.com",
  313. "expected": {
  314. "href": "mailto:me@example.net",
  315. "host": ""
  316. }
  317. },
  318. {
  319. "comment": "Cannot-be-a-base means no password",
  320. "href": "data:text/plain,Stuff",
  321. "new_value": "example.net",
  322. "expected": {
  323. "href": "data:text/plain,Stuff",
  324. "host": ""
  325. }
  326. },
  327. {
  328. "href": "http://example.net",
  329. "new_value": "example.com:8080",
  330. "expected": {
  331. "href": "http://example.com:8080/",
  332. "host": "example.com:8080",
  333. "hostname": "example.com",
  334. "port": "8080"
  335. }
  336. },
  337. {
  338. "comment": "Port number is unchanged if not specified in the new value",
  339. "href": "http://example.net:8080",
  340. "new_value": "example.com",
  341. "expected": {
  342. "href": "http://example.com:8080/",
  343. "host": "example.com:8080",
  344. "hostname": "example.com",
  345. "port": "8080"
  346. }
  347. },
  348. {
  349. "comment": "Port number is removed if empty in the new value: https://github.com/whatwg/url/pull/113",
  350. "href": "http://example.net:8080",
  351. "new_value": "example.com:",
  352. "expected": {
  353. "href": "http://example.com/",
  354. "host": "example.com",
  355. "hostname": "example.com",
  356. "port": ""
  357. }
  358. },
  359. {
  360. "comment": "The empty host is not valid for special schemes",
  361. "href": "http://example.net",
  362. "new_value": "",
  363. "expected": {
  364. "href": "http://example.net/",
  365. "host": "example.net"
  366. }
  367. },
  368. {
  369. "comment": "The empty host is OK for non-special schemes",
  370. "href": "view-source+http://example.net/foo",
  371. "new_value": "",
  372. "expected": {
  373. "href": "view-source+http:///foo",
  374. "host": ""
  375. }
  376. },
  377. {
  378. "comment": "Path-only URLs can gain a host",
  379. "href": "a:/foo",
  380. "new_value": "example.net",
  381. "expected": {
  382. "href": "a://example.net/foo",
  383. "host": "example.net"
  384. }
  385. },
  386. {
  387. "comment": "Path-only URLs can gain a host",
  388. "href": "a:/foo",
  389. "new_value": "example.net",
  390. "expected": {
  391. "href": "a://example.net/foo",
  392. "host": "example.net"
  393. }
  394. },
  395. {
  396. "comment": "IPv4 address syntax is normalized",
  397. "href": "http://example.net",
  398. "new_value": "0x7F000001:8080",
  399. "expected": {
  400. "href": "http://127.0.0.1:8080/",
  401. "host": "127.0.0.1:8080",
  402. "hostname": "127.0.0.1",
  403. "port": "8080"
  404. }
  405. },
  406. {
  407. "comment": "IPv6 address syntax is normalized",
  408. "href": "http://example.net",
  409. "new_value": "[::0:01]:2",
  410. "expected": {
  411. "href": "http://[::1]:2/",
  412. "host": "[::1]:2",
  413. "hostname": "[::1]",
  414. "port": "2"
  415. }
  416. },
  417. {
  418. "comment": "Default port number is removed",
  419. "href": "http://example.net",
  420. "new_value": "example.com:80",
  421. "expected": {
  422. "href": "http://example.com/",
  423. "host": "example.com",
  424. "hostname": "example.com",
  425. "port": ""
  426. }
  427. },
  428. {
  429. "comment": "Default port number is removed",
  430. "href": "https://example.net",
  431. "new_value": "example.com:443",
  432. "expected": {
  433. "href": "https://example.com/",
  434. "host": "example.com",
  435. "hostname": "example.com",
  436. "port": ""
  437. }
  438. },
  439. {
  440. "comment": "Default port number is only removed for the relevant scheme",
  441. "href": "https://example.net",
  442. "new_value": "example.com:80",
  443. "expected": {
  444. "href": "https://example.com:80/",
  445. "host": "example.com:80",
  446. "hostname": "example.com",
  447. "port": "80"
  448. }
  449. },
  450. {
  451. "comment": "Stuff after a / delimiter is ignored",
  452. "href": "http://example.net/path",
  453. "new_value": "example.com/stuff",
  454. "expected": {
  455. "href": "http://example.com/path",
  456. "host": "example.com",
  457. "hostname": "example.com",
  458. "port": ""
  459. }
  460. },
  461. {
  462. "comment": "Stuff after a / delimiter is ignored",
  463. "href": "http://example.net/path",
  464. "new_value": "example.com:8080/stuff",
  465. "expected": {
  466. "href": "http://example.com:8080/path",
  467. "host": "example.com:8080",
  468. "hostname": "example.com",
  469. "port": "8080"
  470. }
  471. },
  472. {
  473. "comment": "Stuff after a ? delimiter is ignored",
  474. "href": "http://example.net/path",
  475. "new_value": "example.com?stuff",
  476. "expected": {
  477. "href": "http://example.com/path",
  478. "host": "example.com",
  479. "hostname": "example.com",
  480. "port": ""
  481. }
  482. },
  483. {
  484. "comment": "Stuff after a ? delimiter is ignored",
  485. "href": "http://example.net/path",
  486. "new_value": "example.com:8080?stuff",
  487. "expected": {
  488. "href": "http://example.com:8080/path",
  489. "host": "example.com:8080",
  490. "hostname": "example.com",
  491. "port": "8080"
  492. }
  493. },
  494. {
  495. "comment": "Stuff after a # delimiter is ignored",
  496. "href": "http://example.net/path",
  497. "new_value": "example.com#stuff",
  498. "expected": {
  499. "href": "http://example.com/path",
  500. "host": "example.com",
  501. "hostname": "example.com",
  502. "port": ""
  503. }
  504. },
  505. {
  506. "comment": "Stuff after a # delimiter is ignored",
  507. "href": "http://example.net/path",
  508. "new_value": "example.com:8080#stuff",
  509. "expected": {
  510. "href": "http://example.com:8080/path",
  511. "host": "example.com:8080",
  512. "hostname": "example.com",
  513. "port": "8080"
  514. }
  515. },
  516. {
  517. "comment": "Stuff after a \\ delimiter is ignored for special schemes",
  518. "href": "http://example.net/path",
  519. "new_value": "example.com\\stuff",
  520. "expected": {
  521. "href": "http://example.com/path",
  522. "host": "example.com",
  523. "hostname": "example.com",
  524. "port": ""
  525. }
  526. },
  527. {
  528. "comment": "Stuff after a \\ delimiter is ignored for special schemes",
  529. "href": "http://example.net/path",
  530. "new_value": "example.com:8080\\stuff",
  531. "expected": {
  532. "href": "http://example.com:8080/path",
  533. "host": "example.com:8080",
  534. "hostname": "example.com",
  535. "port": "8080"
  536. }
  537. },
  538. {
  539. "comment": "\\ is not a delimiter for non-special schemes, and it’s invalid in a domain",
  540. "href": "view-source+http://example.net/path",
  541. "new_value": "example.com\\stuff",
  542. "expected": {
  543. "href": "view-source+http://example.net/path",
  544. "host": "example.net",
  545. "hostname": "example.net",
  546. "port": ""
  547. }
  548. },
  549. {
  550. "comment": "Anything other than ASCII digit stops the port parser in a setter but is not an error",
  551. "href": "view-source+http://example.net/path",
  552. "new_value": "example.com:8080stuff2",
  553. "expected": {
  554. "href": "view-source+http://example.com:8080/path",
  555. "host": "example.com:8080",
  556. "hostname": "example.com",
  557. "port": "8080"
  558. }
  559. },
  560. {
  561. "comment": "Anything other than ASCII digit stops the port parser in a setter but is not an error",
  562. "href": "http://example.net/path",
  563. "new_value": "example.com:8080stuff2",
  564. "expected": {
  565. "href": "http://example.com:8080/path",
  566. "host": "example.com:8080",
  567. "hostname": "example.com",
  568. "port": "8080"
  569. }
  570. },
  571. {
  572. "comment": "Anything other than ASCII digit stops the port parser in a setter but is not an error",
  573. "href": "http://example.net/path",
  574. "new_value": "example.com:8080+2",
  575. "expected": {
  576. "href": "http://example.com:8080/path",
  577. "host": "example.com:8080",
  578. "hostname": "example.com",
  579. "port": "8080"
  580. }
  581. },
  582. {
  583. "comment": "Port numbers are 16 bit integers",
  584. "href": "http://example.net/path",
  585. "new_value": "example.com:65535",
  586. "expected": {
  587. "href": "http://example.com:65535/path",
  588. "host": "example.com:65535",
  589. "hostname": "example.com",
  590. "port": "65535"
  591. }
  592. },
  593. {
  594. "comment": "Port numbers are 16 bit integers, overflowing is an error. Hostname is still set, though.",
  595. "href": "http://example.net/path",
  596. "new_value": "example.com:65536",
  597. "expected": {
  598. "href": "http://example.com/path",
  599. "host": "example.com",
  600. "hostname": "example.com",
  601. "port": ""
  602. }
  603. }
  604. ],
  605. "hostname": [
  606. {
  607. "comment": "Cannot-be-a-base means no host",
  608. "href": "mailto:me@example.net",
  609. "new_value": "example.com",
  610. "expected": {
  611. "href": "mailto:me@example.net",
  612. "host": ""
  613. }
  614. },
  615. {
  616. "comment": "Cannot-be-a-base means no password",
  617. "href": "data:text/plain,Stuff",
  618. "new_value": "example.net",
  619. "expected": {
  620. "href": "data:text/plain,Stuff",
  621. "host": ""
  622. }
  623. },
  624. {
  625. "href": "http://example.net:8080",
  626. "new_value": "example.com",
  627. "expected": {
  628. "href": "http://example.com:8080/",
  629. "host": "example.com:8080",
  630. "hostname": "example.com",
  631. "port": "8080"
  632. }
  633. },
  634. {
  635. "comment": "The empty host is not valid for special schemes",
  636. "href": "http://example.net",
  637. "new_value": "",
  638. "expected": {
  639. "href": "http://example.net/",
  640. "host": "example.net"
  641. }
  642. },
  643. {
  644. "comment": "The empty host is OK for non-special schemes",
  645. "href": "view-source+http://example.net/foo",
  646. "new_value": "",
  647. "expected": {
  648. "href": "view-source+http:///foo",
  649. "host": ""
  650. }
  651. },
  652. {
  653. "comment": "Path-only URLs can gain a host",
  654. "href": "a:/foo",
  655. "new_value": "example.net",
  656. "expected": {
  657. "href": "a://example.net/foo",
  658. "host": "example.net"
  659. }
  660. },
  661. {
  662. "comment": "Path-only URLs can gain a host",
  663. "href": "a:/foo",
  664. "new_value": "example.net",
  665. "expected": {
  666. "href": "a://example.net/foo",
  667. "host": "example.net"
  668. }
  669. },
  670. {
  671. "comment": "IPv4 address syntax is normalized",
  672. "href": "http://example.net:8080",
  673. "new_value": "0x7F000001",
  674. "expected": {
  675. "href": "http://127.0.0.1:8080/",
  676. "host": "127.0.0.1:8080",
  677. "hostname": "127.0.0.1",
  678. "port": "8080"
  679. }
  680. },
  681. {
  682. "comment": "IPv6 address syntax is normalized",
  683. "href": "http://example.net",
  684. "new_value": "[::0:01]",
  685. "expected": {
  686. "href": "http://[::1]/",
  687. "host": "[::1]",
  688. "hostname": "[::1]",
  689. "port": ""
  690. }
  691. },
  692. {
  693. "comment": "Stuff after a : delimiter is ignored",
  694. "href": "http://example.net/path",
  695. "new_value": "example.com:8080",
  696. "expected": {
  697. "href": "http://example.com/path",
  698. "host": "example.com",
  699. "hostname": "example.com",
  700. "port": ""
  701. }
  702. },
  703. {
  704. "comment": "Stuff after a : delimiter is ignored",
  705. "href": "http://example.net:8080/path",
  706. "new_value": "example.com:",
  707. "expected": {
  708. "href": "http://example.com:8080/path",
  709. "host": "example.com:8080",
  710. "hostname": "example.com",
  711. "port": "8080"
  712. }
  713. },
  714. {
  715. "comment": "Stuff after a / delimiter is ignored",
  716. "href": "http://example.net/path",
  717. "new_value": "example.com/stuff",
  718. "expected": {
  719. "href": "http://example.com/path",
  720. "host": "example.com",
  721. "hostname": "example.com",
  722. "port": ""
  723. }
  724. },
  725. {
  726. "comment": "Stuff after a ? delimiter is ignored",
  727. "href": "http://example.net/path",
  728. "new_value": "example.com?stuff",
  729. "expected": {
  730. "href": "http://example.com/path",
  731. "host": "example.com",
  732. "hostname": "example.com",
  733. "port": ""
  734. }
  735. },
  736. {
  737. "comment": "Stuff after a # delimiter is ignored",
  738. "href": "http://example.net/path",
  739. "new_value": "example.com#stuff",
  740. "expected": {
  741. "href": "http://example.com/path",
  742. "host": "example.com",
  743. "hostname": "example.com",
  744. "port": ""
  745. }
  746. },
  747. {
  748. "comment": "Stuff after a \\ delimiter is ignored for special schemes",
  749. "href": "http://example.net/path",
  750. "new_value": "example.com\\stuff",
  751. "expected": {
  752. "href": "http://example.com/path",
  753. "host": "example.com",
  754. "hostname": "example.com",
  755. "port": ""
  756. }
  757. },
  758. {
  759. "comment": "\\ is not a delimiter for non-special schemes, and it’s invalid in a domain",
  760. "href": "view-source+http://example.net/path",
  761. "new_value": "example.com\\stuff",
  762. "expected": {
  763. "href": "view-source+http://example.net/path",
  764. "host": "example.net",
  765. "hostname": "example.net",
  766. "port": ""
  767. }
  768. }
  769. ],
  770. "port": [
  771. {
  772. "href": "http://example.net",
  773. "new_value": "8080",
  774. "expected": {
  775. "href": "http://example.net:8080/",
  776. "host": "example.net:8080",
  777. "hostname": "example.net",
  778. "port": "8080"
  779. }
  780. },
  781. {
  782. "comment": "Port number is removed if empty in the new value: https://github.com/whatwg/url/pull/113",
  783. "href": "http://example.net:8080",
  784. "new_value": "",
  785. "expected": {
  786. "href": "http://example.net/",
  787. "host": "example.net",
  788. "hostname": "example.net",
  789. "port": ""
  790. }
  791. },
  792. {
  793. "comment": "Default port number is removed",
  794. "href": "http://example.net:8080",
  795. "new_value": "80",
  796. "expected": {
  797. "href": "http://example.net/",
  798. "host": "example.net",
  799. "hostname": "example.net",
  800. "port": ""
  801. }
  802. },
  803. {
  804. "comment": "Default port number is removed",
  805. "href": "https://example.net:4433",
  806. "new_value": "443",
  807. "expected": {
  808. "href": "https://example.net/",
  809. "host": "example.net",
  810. "hostname": "example.net",
  811. "port": ""
  812. }
  813. },
  814. {
  815. "comment": "Default port number is only removed for the relevant scheme",
  816. "href": "https://example.net",
  817. "new_value": "80",
  818. "expected": {
  819. "href": "https://example.net:80/",
  820. "host": "example.net:80",
  821. "hostname": "example.net",
  822. "port": "80"
  823. }
  824. },
  825. {
  826. "comment": "Stuff after a / delimiter is ignored",
  827. "href": "http://example.net/path",
  828. "new_value": "8080/stuff",
  829. "expected": {
  830. "href": "http://example.net:8080/path",
  831. "host": "example.net:8080",
  832. "hostname": "example.net",
  833. "port": "8080"
  834. }
  835. },
  836. {
  837. "comment": "Stuff after a ? delimiter is ignored",
  838. "href": "http://example.net/path",
  839. "new_value": "8080?stuff",
  840. "expected": {
  841. "href": "http://example.net:8080/path",
  842. "host": "example.net:8080",
  843. "hostname": "example.net",
  844. "port": "8080"
  845. }
  846. },
  847. {
  848. "comment": "Stuff after a # delimiter is ignored",
  849. "href": "http://example.net/path",
  850. "new_value": "8080#stuff",
  851. "expected": {
  852. "href": "http://example.net:8080/path",
  853. "host": "example.net:8080",
  854. "hostname": "example.net",
  855. "port": "8080"
  856. }
  857. },
  858. {
  859. "comment": "Stuff after a \\ delimiter is ignored for special schemes",
  860. "href": "http://example.net/path",
  861. "new_value": "8080\\stuff",
  862. "expected": {
  863. "href": "http://example.net:8080/path",
  864. "host": "example.net:8080",
  865. "hostname": "example.net",
  866. "port": "8080"
  867. }
  868. },
  869. {
  870. "comment": "Anything other than ASCII digit stops the port parser in a setter but is not an error",
  871. "href": "view-source+http://example.net/path",
  872. "new_value": "8080stuff2",
  873. "expected": {
  874. "href": "view-source+http://example.net:8080/path",
  875. "host": "example.net:8080",
  876. "hostname": "example.net",
  877. "port": "8080"
  878. }
  879. },
  880. {
  881. "comment": "Anything other than ASCII digit stops the port parser in a setter but is not an error",
  882. "href": "http://example.net/path",
  883. "new_value": "8080stuff2",
  884. "expected": {
  885. "href": "http://example.net:8080/path",
  886. "host": "example.net:8080",
  887. "hostname": "example.net",
  888. "port": "8080"
  889. }
  890. },
  891. {
  892. "comment": "Anything other than ASCII digit stops the port parser in a setter but is not an error",
  893. "href": "http://example.net/path",
  894. "new_value": "8080+2",
  895. "expected": {
  896. "href": "http://example.net:8080/path",
  897. "host": "example.net:8080",
  898. "hostname": "example.net",
  899. "port": "8080"
  900. }
  901. },
  902. {
  903. "comment": "Port numbers are 16 bit integers",
  904. "href": "http://example.net/path",
  905. "new_value": "65535",
  906. "expected": {
  907. "href": "http://example.net:65535/path",
  908. "host": "example.net:65535",
  909. "hostname": "example.net",
  910. "port": "65535"
  911. }
  912. },
  913. {
  914. "comment": "Port numbers are 16 bit integers, overflowing is an error",
  915. "href": "http://example.net:8080/path",
  916. "new_value": "65536",
  917. "expected": {
  918. "href": "http://example.net:8080/path",
  919. "host": "example.net:8080",
  920. "hostname": "example.net",
  921. "port": "8080"
  922. }
  923. }
  924. ],
  925. "pathname": [
  926. {
  927. "comment": "Cannot-be-a-base don’t have a path",
  928. "href": "mailto:me@example.net",
  929. "new_value": "/foo",
  930. "expected": {
  931. "href": "mailto:me@example.net",
  932. "pathname": "me@example.net"
  933. }
  934. },
  935. {
  936. "href": "unix:/run/foo.socket?timeout=10",
  937. "new_value": "/var/log/../run/bar.socket",
  938. "expected": {
  939. "href": "unix:/var/run/bar.socket?timeout=10",
  940. "pathname": "/var/run/bar.socket"
  941. }
  942. },
  943. {
  944. "href": "https://example.net#nav",
  945. "new_value": "home",
  946. "expected": {
  947. "href": "https://example.net/home#nav",
  948. "pathname": "/home"
  949. }
  950. },
  951. {
  952. "href": "https://example.net#nav",
  953. "new_value": "../home",
  954. "expected": {
  955. "href": "https://example.net/home#nav",
  956. "pathname": "/home"
  957. }
  958. },
  959. {
  960. "comment": "\\ is a segment delimiter for 'special' URLs",
  961. "href": "http://example.net/home?lang=fr#nav",
  962. "new_value": "\\a\\%2E\\b\\%2e.\\c",
  963. "expected": {
  964. "href": "http://example.net/a/c?lang=fr#nav",
  965. "pathname": "/a/c"
  966. }
  967. },
  968. {
  969. "comment": "\\ is *not* a segment delimiter for non-'special' URLs",
  970. "href": "view-source+http://example.net/home?lang=fr#nav",
  971. "new_value": "\\a\\%2E\\b\\%2e.\\c",
  972. "expected": {
  973. "href": "view-source+http://example.net/\\a\\.\\b\\..\\c?lang=fr#nav",
  974. "pathname": "/\\a\\.\\b\\..\\c"
  975. }
  976. },
  977. {
  978. "comment": "UTF-8 percent encoding with the default encode set. Tabs and newlines are removed. Leading or training C0 controls and space are removed.",
  979. "href": "a:/",
  980. "new_value": "\u0000\u0001\t\n\r\u001f !\u0000\u0001\t\n\r\u001f !\"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~\u007f\u0080\u0081Éé",
  981. "expected": {
  982. "href": "a:/!%00%01%1F%20!%22%23$%&'()*+,-./09:;%3C=%3E%3F@AZ[\\]^_%60az%7B|%7D~%7F%C2%80%C2%81%C3%89%C3%A9",
  983. "pathname": "/!%00%01%1F%20!%22%23$%&'()*+,-./09:;%3C=%3E%3F@AZ[\\]^_%60az%7B|%7D~%7F%C2%80%C2%81%C3%89%C3%A9"
  984. }
  985. },
  986. {
  987. "comment": "Bytes already percent-encoded are left as-is, except %2E.",
  988. "href": "http://example.net",
  989. "new_value": "%2e%2E%c3%89té",
  990. "expected": {
  991. "href": "http://example.net/..%c3%89t%C3%A9",
  992. "pathname": "/..%c3%89t%C3%A9"
  993. }
  994. }
  995. ],
  996. "search": [
  997. {
  998. "href": "https://example.net#nav",
  999. "new_value": "lang=fr",
  1000. "expected": {
  1001. "href": "https://example.net/?lang=fr#nav",
  1002. "search": "?lang=fr"
  1003. }
  1004. },
  1005. {
  1006. "href": "https://example.net?lang=en-US#nav",
  1007. "new_value": "lang=fr",
  1008. "expected": {
  1009. "href": "https://example.net/?lang=fr#nav",
  1010. "search": "?lang=fr"
  1011. }
  1012. },
  1013. {
  1014. "href": "https://example.net?lang=en-US#nav",
  1015. "new_value": "?lang=fr",
  1016. "expected": {
  1017. "href": "https://example.net/?lang=fr#nav",
  1018. "search": "?lang=fr"
  1019. }
  1020. },
  1021. {
  1022. "href": "https://example.net?lang=en-US#nav",
  1023. "new_value": "??lang=fr",
  1024. "expected": {
  1025. "href": "https://example.net/??lang=fr#nav",
  1026. "search": "??lang=fr"
  1027. }
  1028. },
  1029. {
  1030. "href": "https://example.net?lang=en-US#nav",
  1031. "new_value": "?",
  1032. "expected": {
  1033. "href": "https://example.net/?#nav",
  1034. "search": ""
  1035. }
  1036. },
  1037. {
  1038. "href": "https://example.net?lang=en-US#nav",
  1039. "new_value": "",
  1040. "expected": {
  1041. "href": "https://example.net/#nav",
  1042. "search": ""
  1043. }
  1044. },
  1045. {
  1046. "href": "https://example.net?lang=en-US",
  1047. "new_value": "",
  1048. "expected": {
  1049. "href": "https://example.net/",
  1050. "search": ""
  1051. }
  1052. },
  1053. {
  1054. "href": "https://example.net",
  1055. "new_value": "",
  1056. "expected": {
  1057. "href": "https://example.net/",
  1058. "search": ""
  1059. }
  1060. },
  1061. {
  1062. "comment": "UTF-8 percent encoding with the query encode set. Tabs and newlines are removed. Leading or training C0 controls and space are removed.",
  1063. "href": "a:/",
  1064. "new_value": "\u0000\u0001\t\n\r\u001f !\u0000\u0001\t\n\r\u001f !\"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~\u007f\u0080\u0081Éé",
  1065. "expected": {
  1066. "href": "a:/?!%00%01%1F%20!%22%23$%&'()*+,-./09:;%3C=%3E?@AZ[\\]^_`az{|}~%7F%C2%80%C2%81%C3%89%C3%A9",
  1067. "search": "?!%00%01%1F%20!%22%23$%&'()*+,-./09:;%3C=%3E?@AZ[\\]^_`az{|}~%7F%C2%80%C2%81%C3%89%C3%A9"
  1068. }
  1069. },
  1070. {
  1071. "comment": "Bytes already percent-encoded are left as-is",
  1072. "href": "http://example.net",
  1073. "new_value": "%c3%89té",
  1074. "expected": {
  1075. "href": "http://example.net/?%c3%89t%C3%A9",
  1076. "search": "?%c3%89t%C3%A9"
  1077. }
  1078. }
  1079. ],
  1080. "hash": [
  1081. {
  1082. "href": "https://example.net",
  1083. "new_value": "main",
  1084. "expected": {
  1085. "href": "https://example.net/#main",
  1086. "hash": "#main"
  1087. }
  1088. },
  1089. {
  1090. "href": "https://example.net#nav",
  1091. "new_value": "main",
  1092. "expected": {
  1093. "href": "https://example.net/#main",
  1094. "hash": "#main"
  1095. }
  1096. },
  1097. {
  1098. "href": "https://example.net?lang=en-US",
  1099. "new_value": "##nav",
  1100. "expected": {
  1101. "href": "https://example.net/?lang=en-US##nav",
  1102. "hash": "##nav"
  1103. }
  1104. },
  1105. {
  1106. "href": "https://example.net?lang=en-US#nav",
  1107. "new_value": "#main",
  1108. "expected": {
  1109. "href": "https://example.net/?lang=en-US#main",
  1110. "hash": "#main"
  1111. }
  1112. },
  1113. {
  1114. "href": "https://example.net?lang=en-US#nav",
  1115. "new_value": "#",
  1116. "expected": {
  1117. "href": "https://example.net/?lang=en-US#",
  1118. "hash": ""
  1119. }
  1120. },
  1121. {
  1122. "href": "https://example.net?lang=en-US#nav",
  1123. "new_value": "",
  1124. "expected": {
  1125. "href": "https://example.net/?lang=en-US",
  1126. "hash": ""
  1127. }
  1128. },
  1129. {
  1130. "comment": "Simple percent-encoding; nuls, tabs, and newlines are removed",
  1131. "href": "a:/",
  1132. "new_value": "\u0000\u0001\t\n\r\u001f !\u0000\u0001\t\n\r\u001f !\"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~\u007f\u0080\u0081Éé",
  1133. "expected": {
  1134. "href": "a:/#!%01%1F !\"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~%7F%C2%80%C2%81%C3%89%C3%A9",
  1135. "hash": "#!%01%1F !\"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~%7F%C2%80%C2%81%C3%89%C3%A9"
  1136. }
  1137. },
  1138. {
  1139. "comment": "Bytes already percent-encoded are left as-is",
  1140. "href": "http://example.net",
  1141. "new_value": "%c3%89té",
  1142. "expected": {
  1143. "href": "http://example.net/#%c3%89t%C3%A9",
  1144. "hash": "#%c3%89t%C3%A9"
  1145. }
  1146. }
  1147. ]
  1148. }