Skip to content

Commit

Permalink
Test URLs with empty query and fragment
Browse files Browse the repository at this point in the history
Closes whatwg/url#539.

Closes #25829 by superseding it.

Co-authored-by: Daijiro Wachi <daijiro.wachi@gmail.com>
  • Loading branch information
guybedford and watilde committed Jul 7, 2021
1 parent 38628c2 commit 6315c77
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions url/resources/a-element-origin.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ function runURLTests(urltests) {
for(var i = 0, l = urltests.length; i < l; i++) {
var expected = urltests[i]
if (typeof expected === "string" || !("origin" in expected)) continue
// skip without base because you cannot unset the baseURL of a document
if (expected.base === null) continue;

test(function() {
var url = bURL(expected.input, expected.base)
Expand Down
2 changes: 2 additions & 0 deletions url/resources/a-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ function runURLTests(urltests) {
for(var i = 0, l = urltests.length; i < l; i++) {
var expected = urltests[i]
if (typeof expected === "string") continue // skip comments
// skip without base because you cannot unset the baseURL of a document
if (expected.base === null) continue;

test(function() {
var url = bURL(expected.input, expected.base)
Expand Down
11 changes: 11 additions & 0 deletions url/resources/urltestdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -8016,5 +8016,16 @@
"protocol": "abc:",
"search": "",
"username": ""
},
"Empty query and fragment with blank should throw an error",
{
"input": "#",
"base": null,
"failure": true
},
{
"input": "?",
"base": null,
"failure": true
}
]
2 changes: 1 addition & 1 deletion url/url-constructor.any.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// META: timeout=long

function bURL(url, base) {
return new URL(url, base || "about:blank")
return base ? new URL(url, base) : new URL(url)
}

function runURLTests(urltests) {
Expand Down
2 changes: 1 addition & 1 deletion url/url-origin.any.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
promise_test(() => fetch("resources/urltestdata.json").then(res => res.json()).then(runURLTests), "Loading data…");

function bURL(url, base) {
return new URL(url, base || "about:blank")
return base ? new URL(url, base) : new URL(url)
}

function runURLTests(urltests) {
Expand Down

0 comments on commit 6315c77

Please sign in to comment.