setters_tests.json 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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": "Non-ASCII is rejected",
  88. "href": "a://example.net",
  89. "new_value": "bé",
  90. "expected": {
  91. "href": "a://example.net/",
  92. "protocol": "a:"
  93. }
  94. },
  95. {
  96. "comment": "Spec deviation: from special scheme to not is not problematic. https://github.com/whatwg/url/issues/104",
  97. "href": "http://example.net",
  98. "new_value": "b",
  99. "expected": {
  100. "href": "b://example.net/",
  101. "protocol": "b:"
  102. }
  103. },
  104. {
  105. "comment": "Cannot-be-a-base URL doesn’t have a host, but URL in a special scheme must.",
  106. "href": "mailto:me@example.net",
  107. "new_value": "http",
  108. "expected": {
  109. "href": "mailto:me@example.net",
  110. "protocol": "mailto:"
  111. }
  112. },
  113. {
  114. "comment": "Spec deviation: from non-special scheme with a host to special is not problematic. https://github.com/whatwg/url/issues/104",
  115. "href": "ssh://me@example.net",
  116. "new_value": "http",
  117. "expected": {
  118. "href": "http://me@example.net/",
  119. "protocol": "http:"
  120. }
  121. },
  122. {
  123. "comment": "Stuff after the first ':' is ignored",
  124. "href": "http://example.net",
  125. "new_value": "https:foo : bar",
  126. "expected": {
  127. "href": "https://example.net/",
  128. "protocol": "https:"
  129. }
  130. },
  131. {
  132. "comment": "Stuff after the first ':' is ignored",
  133. "href": "data:text/html,<p>Test",
  134. "new_value": "view-source+data:foo : bar",
  135. "expected": {
  136. "href": "view-source+data:text/html,<p>Test",
  137. "protocol": "view-source+data:"
  138. }
  139. }
  140. ],
  141. "username": [
  142. {
  143. "comment": "No host means no username",
  144. "href": "file:///home/you/index.html",
  145. "new_value": "me",
  146. "expected": {
  147. "href": "file:///home/you/index.html",
  148. "username": ""
  149. }
  150. },
  151. {
  152. "comment": "Cannot-be-a-base means no username",
  153. "href": "mailto:you@example.net",
  154. "new_value": "me",
  155. "expected": {
  156. "href": "mailto:you@example.net",
  157. "username": ""
  158. }
  159. },
  160. {
  161. "href": "http://example.net",
  162. "new_value": "me",
  163. "expected": {
  164. "href": "http://me@example.net/",
  165. "username": "me"
  166. }
  167. },
  168. {
  169. "href": "http://:secret@example.net",
  170. "new_value": "me",
  171. "expected": {
  172. "href": "http://me:secret@example.net/",
  173. "username": "me"
  174. }
  175. },
  176. {
  177. "href": "http://me@example.net",
  178. "new_value": "",
  179. "expected": {
  180. "href": "http://example.net/",
  181. "username": ""
  182. }
  183. },
  184. {
  185. "href": "http://me:secret@example.net",
  186. "new_value": "",
  187. "expected": {
  188. "href": "http://:secret@example.net/",
  189. "username": ""
  190. }
  191. },
  192. {
  193. "comment": "UTF-8 percent encoding with the userinfo encode set.",
  194. "href": "http://example.net",
  195. "new_value": "\u0000\u0001\t\n\r\u001f !\"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~\u007f\u0080\u0081Éé",
  196. "expected": {
  197. "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/",
  198. "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"
  199. }
  200. },
  201. {
  202. "comment": "Bytes already percent-encoded are left as-is.",
  203. "href": "http://example.net",
  204. "new_value": "%c3%89t%c3%a9",
  205. "expected": {
  206. "href": "http://%c3%89t%c3%a9@example.net/",
  207. "username": "%c3%89t%c3%a9"
  208. }
  209. }
  210. ],
  211. "password": [],
  212. "host": [],
  213. "hostname": [],
  214. "port": [],
  215. "pathname": [],
  216. "search": [],
  217. "hash": []
  218. }