Skip to content

Commit e256ace

Browse files
KhafraDevronag
authored andcommitted
wpt: add response-url.sub.any.js
1 parent 5cb2eed commit e256ace

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

lib/fetch/dataURL.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function URLSerializer (url, excludeFragment = false) {
135135
}
136136

137137
// 3. Append url’s host, serialized, to output.
138-
output += decodeURIComponent(url.host)
138+
output += decodeURIComponent(url.hostname)
139139

140140
// 4. If url’s port is non-null, append U+003A (:) followed by url’s port,
141141
// serialized, to output.

lib/fetch/request.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const { kEnumerableProperty } = util
2424
const { kHeaders, kSignal, kState, kGuard, kRealm } = require('./symbols')
2525
const { webidl } = require('./webidl')
2626
const { getGlobalOrigin } = require('./global')
27+
const { URLSerializer } = require('./dataURL')
2728
const { kHeadersList } = require('../core/symbols')
2829
const assert = require('assert')
2930

@@ -542,7 +543,7 @@ class Request {
542543
}
543544

544545
// The url getter steps are to return this’s request’s URL, serialized.
545-
return this[kState].url.toString()
546+
return URLSerializer(this[kState].url)
546547
}
547548

548549
// Returns a Headers object consisting of the headers associated with request.

lib/fetch/response.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const { kState, kHeaders, kGuard, kRealm } = require('./symbols')
2222
const { webidl } = require('./webidl')
2323
const { FormData } = require('./formdata')
2424
const { getGlobalOrigin } = require('./global')
25+
const { URLSerializer } = require('./dataURL')
2526
const { kHeadersList } = require('../core/symbols')
2627
const assert = require('assert')
2728
const { types } = require('util')
@@ -192,18 +193,13 @@ class Response {
192193
// The url getter steps are to return the empty string if this’s
193194
// response’s URL is null; otherwise this’s response’s URL,
194195
// serialized with exclude fragment set to true.
195-
let url = responseURL(this[kState])
196+
const url = this[kState].urlList[0] ?? null
196197

197-
if (url == null) {
198+
if (url === null) {
198199
return ''
199200
}
200201

201-
if (url.hash) {
202-
url = new URL(url)
203-
url.hash = ''
204-
}
205-
206-
return url.toString()
202+
return URLSerializer(url, true)
207203
}
208204

209205
// Returns whether response was obtained through a redirect.

test/wpt/runner/runner/util.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export function handlePipes (code, url) {
110110
// "The port number of servers, by protocol e.g. {{ports[http][0]}}
111111
// for the first (and, depending on setup, possibly only) http server"
112112
case 'ports': {
113-
return `${server.port}/`
113+
return server.port
114114
}
115115
default: {
116116
throw new TypeError(`Unknown substitute "${sub}".`)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function checkResponseURL(fetchedURL, expectedURL)
2+
{
3+
promise_test(function() {
4+
return fetch(fetchedURL).then(function(response) {
5+
assert_equals(response.url, expectedURL);
6+
});
7+
}, "Testing response url getter with " +fetchedURL);
8+
}
9+
10+
var baseURL = "http://{{host}}:{{ports[http][0]}}";
11+
checkResponseURL(baseURL + "/ada", baseURL + "/ada");
12+
checkResponseURL(baseURL + "/#", baseURL + "/");
13+
checkResponseURL(baseURL + "/#ada", baseURL + "/");
14+
checkResponseURL(baseURL + "#ada", baseURL + "/");
15+
16+
done();

0 commit comments

Comments
 (0)