Skip to content

Commit 2533d76

Browse files
KhafraDevronag
authored andcommitted
wpt: add scheme-others.sub.any.js and fix issues
1 parent 77a17f4 commit 2533d76

File tree

7 files changed

+42
-15
lines changed

7 files changed

+42
-15
lines changed

lib/fetch/response.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,12 @@ class Response {
189189
throw new TypeError('Illegal invocation')
190190
}
191191

192+
const urlList = this[kState].urlList
193+
192194
// The url getter steps are to return the empty string if this’s
193195
// response’s URL is null; otherwise this’s response’s URL,
194196
// serialized with exclude fragment set to true.
195-
const url = this[kState].urlList[0] ?? null
197+
const url = urlList[urlList.length - 1] ?? null
196198

197199
if (url === null) {
198200
return ''

lib/fetch/util.js

-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,6 @@ function bytesMatch (bytes, metadataList) {
547547
const expectedValue = item.hash
548548

549549
// 3. Let actualValue be the result of applying algorithm to bytes.
550-
// Note: "applying algorithm to bytes" converts the result to base64
551550
const actualValue = crypto.createHash(algorithm).update(bytes).digest('base64')
552551

553552
// 4. If actualValue is a case-sensitive match for expectedValue,

test/fetch/about-uri.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ const { fetch } = require('../..')
55

66
test('fetching about: uris', async (t) => {
77
t.test('about:blank', async (t) => {
8-
const res = await fetch('about:blank')
9-
10-
t.equal(res.url, 'about:blank')
11-
t.equal(res.statusText, 'OK')
12-
t.equal(res.headers.get('Content-Type'), 'text/html;charset=utf-8')
13-
t.end()
8+
await t.rejects(fetch('about:blank'))
149
})
1510

1611
t.test('All other about: urls should return an error', async (t) => {

test/fetch/integrity.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ setGlobalDispatcher(new Agent({
1616

1717
test('request with correct integrity checksum', (t) => {
1818
const body = 'Hello world!'
19-
const hash = createHash('sha256').update(body).digest('hex')
19+
const hash = createHash('sha256').update(body).digest('base64')
2020

2121
const server = createServer((req, res) => {
2222
res.end(body)
@@ -58,7 +58,7 @@ test('request with wrong integrity checksum', (t) => {
5858

5959
test('request with integrity checksum on encoded body', (t) => {
6060
const body = 'Hello world!'
61-
const hash = createHash('sha256').update(body).digest('hex')
61+
const hash = createHash('sha256').update(body).digest('base64')
6262

6363
const server = createServer((req, res) => {
6464
res.setHeader('content-encoding', 'gzip')

test/node-fetch/main.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1532,12 +1532,12 @@ describe('node-fetch', () => {
15321532
})
15331533
})
15341534

1535-
it('should keep `?` sign in URL when no params are given', () => {
1535+
it('should NOT keep `?` sign in URL when no params are given', () => {
15361536
const url = `${base}question?`
15371537
const urlObject = new URL(url)
15381538
const request = new Request(urlObject)
15391539
return fetch(request).then(res => {
1540-
expect(res.url).to.equal(url)
1540+
expect(res.url).to.equal(url.slice(0, -1))
15411541
expect(res.ok).to.be.true
15421542
expect(res.status).to.equal(200)
15431543
})
@@ -1554,12 +1554,12 @@ describe('node-fetch', () => {
15541554
})
15551555
})
15561556

1557-
it('should preserve the hash (#) symbol', () => {
1557+
it('should NOT preserve the hash (#) symbol', () => {
15581558
const url = `${base}question?#`
15591559
const urlObject = new URL(url)
15601560
const request = new Request(urlObject)
15611561
return fetch(request).then(res => {
1562-
expect(res.url).to.equal(url)
1562+
expect(res.url).to.equal(url.slice(0, -2))
15631563
expect(res.ok).to.be.true
15641564
expect(res.status).to.equal(200)
15651565
})

test/node-fetch/response.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ describe('Response', () => {
121121
status: 346,
122122
statusText: 'production'
123123
})
124-
res[kState].urlList = [base]
124+
res[kState].urlList = [new URL(base)]
125125
const cl = res.clone()
126126
expect(cl.headers.get('a')).to.equal('1')
127127
expect(cl.type).to.equal('default')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// META: global=window,worker
2+
// META: script=../resources/utils.js
3+
4+
function checkKoUrl(url, desc) {
5+
if (!desc)
6+
desc = "Fetching " + url.substring(0, 45) + " is KO"
7+
promise_test(function(test) {
8+
var promise = fetch(url);
9+
return promise_rejects_js(test, TypeError, promise);
10+
}, desc);
11+
}
12+
13+
var urlWithoutScheme = "://{{host}}:{{ports[http][0]}}/";
14+
checkKoUrl("aaa" + urlWithoutScheme);
15+
checkKoUrl("cap" + urlWithoutScheme);
16+
checkKoUrl("cid" + urlWithoutScheme);
17+
checkKoUrl("dav" + urlWithoutScheme);
18+
checkKoUrl("dict" + urlWithoutScheme);
19+
checkKoUrl("dns" + urlWithoutScheme);
20+
checkKoUrl("geo" + urlWithoutScheme);
21+
checkKoUrl("im" + urlWithoutScheme);
22+
checkKoUrl("imap" + urlWithoutScheme);
23+
checkKoUrl("ipp" + urlWithoutScheme);
24+
checkKoUrl("ldap" + urlWithoutScheme);
25+
checkKoUrl("mailto" + urlWithoutScheme);
26+
checkKoUrl("nfs" + urlWithoutScheme);
27+
checkKoUrl("pop" + urlWithoutScheme);
28+
checkKoUrl("rtsp" + urlWithoutScheme);
29+
checkKoUrl("snmp" + urlWithoutScheme);
30+
31+
done();

0 commit comments

Comments
 (0)