Skip to content

Commit 21c19de

Browse files
committed
script: Remove check for zero request body length in FetchLater
Per the spec discussion in [1] we should only check for a length of `null` and not zero. [1]: whatwg/fetch#1902 Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
1 parent 2bc8687 commit 21c19de

5 files changed

Lines changed: 15 additions & 56 deletions

File tree

components/script/fetch.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,13 @@ pub(crate) fn FetchLater(
394394
if !url.is_potentially_trustworthy() {
395395
return Err(Error::Type(c"URL is not trustworthy".to_owned()));
396396
}
397-
// Step 10. If request’s body is not null, and request’s body length is null or zero, then throw a TypeError.
398-
if let Some(body) = request.body.as_ref() {
399-
if body.len().is_none_or(|len| len == 0) {
400-
return Err(Error::Type(c"Body is empty".to_owned()));
401-
}
397+
// Step 10. If request’s body is not null, and request’s body length is null, then throw a TypeError.
398+
if request
399+
.body
400+
.as_ref()
401+
.is_some_and(|body| body.len().is_none())
402+
{
403+
return Err(Error::Type(c"Body is empty".to_owned()));
402404
}
403405
// Step 11. If the available deferred-fetch quota given request’s client and request’s URL’s
404406
// origin is less than request’s total request length, then throw a "QuotaExceededError" DOMException.

tests/wpt/meta/MANIFEST.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -714491,7 +714491,7 @@
714491714491
]
714492714492
],
714493714493
"empty-payload.https.window.js": [
714494-
"6c7becfacaf45048c69c815940460d1dbe084a67",
714494+
"9edf32d179d7f50e849ccca1bb3d766bb586200e",
714495714495
[
714496714496
"fetch/fetch-later/quota/cross-origin-iframe/empty-payload.https.window.html",
714497714497
{
@@ -714640,7 +714640,7 @@
714640714640
]
714641714641
},
714642714642
"empty-payload.https.window.js": [
714643-
"c2c4dd50326c0a75b2c82d152995329ccc0cd252",
714643+
"e7da9053ddbc8739e2bae2b2edb75e85ecd2e483",
714644714644
[
714645714645
"fetch/fetch-later/quota/empty-payload.https.window.html",
714646714646
{
@@ -714767,7 +714767,7 @@
714767714767
]
714768714768
],
714769714769
"empty-payload.https.window.js": [
714770-
"53cae60047eaefd2b01a3bd45c84239fa3752bf9",
714770+
"c41bf88dd7fe7e61500e7ea673895fe278cbfb6a",
714771714771
[
714772714772
"fetch/fetch-later/quota/same-origin-iframe/empty-payload.https.window.html",
714773714773
{

tests/wpt/tests/fetch/fetch-later/quota/cross-origin-iframe/empty-payload.https.window.js

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,13 @@ const {HTTPS_ORIGIN, HTTPS_NOTSAMESITE_ORIGIN} = get_host_info();
88
// In a cross-origin iframe, test making a POST request with empty
99
// payload, which is not accepted by fetchLater API.
1010
for (const dataType in BeaconDataType) {
11-
if (dataType === BeaconDataType.FormData) {
12-
// An empty FormData object serializes to non-empty String. Hence, there
13-
// will be no error thrown from fetchLater.
14-
parallelPromiseTest(
15-
async _ => await loadFetchLaterIframe(HTTPS_NOTSAMESITE_ORIGIN, {
16-
activateAfter: 0,
17-
method: 'POST',
18-
bodyType: dataType,
19-
bodySize: 0,
20-
}),
21-
`fetchLater() accepts a non-empty POST request body of ${
22-
dataType} in a default cross-origin iframe.`);
23-
continue;
24-
}
25-
2611
parallelPromiseTest(
2712
async _ => await loadFetchLaterIframe(HTTPS_NOTSAMESITE_ORIGIN, {
2813
activateAfter: 0,
2914
method: 'POST',
3015
bodyType: dataType,
3116
bodySize: 0,
32-
expect: new FetchLaterIframeExpectation(
33-
FetchLaterExpectationType.ERROR_JS, TypeError),
3417
}),
35-
`fetchLater() does not accept empty POST request body of ${
18+
`fetchLater() accepts a non-empty POST request body of ${
3619
dataType} in a default cross-origin iframe.`);
3720
}

tests/wpt/tests/fetch/fetch-later/quota/empty-payload.https.window.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,9 @@ for (const dataType in BeaconDataType) {
1414
body: makeBeaconData('', dataType)
1515
};
1616

17-
if (dataType === BeaconDataType.FormData) {
18-
// An empty FormData object serializes to non-empty String. Hence, there
19-
// will be no error thrown from fetchLater.
20-
parallelPromiseTest(async _ => {
21-
expectFetchLater(requestInit);
22-
}, `fetchLater() accepts a non-empty POST request body of ${dataType}.`);
23-
continue;
24-
}
25-
test(
26-
() => assert_throws_js(TypeError, () => fetchLater('/', requestInit)),
27-
`fetchLater() does not accept an empty POST request body of ${
28-
dataType}.`);
17+
parallelPromiseTest(async _ => {
18+
expectFetchLater(requestInit);
19+
}, `fetchLater() accepts a non-empty POST request body of ${dataType}.`);
2920
}
3021

3122
// Test making HTTP non-POST requests, which has no payload and should be

tests/wpt/tests/fetch/fetch-later/quota/same-origin-iframe/empty-payload.https.window.js

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,13 @@ const {HTTPS_ORIGIN, HTTPS_NOTSAMESITE_ORIGIN} = get_host_info();
88
// In a same-origin iframe, test making a POST request with empty payload,
99
// which is not accepted by fetchLater API.
1010
for (const dataType in BeaconDataType) {
11-
if (dataType === BeaconDataType.FormData) {
12-
// An empty FormData object serializes to non-empty String. Hence, there
13-
// will be no error thrown from fetchLater.
14-
parallelPromiseTest(
15-
async _ => await loadFetchLaterIframe(HTTPS_ORIGIN, {
16-
activateAfter: 0,
17-
method: 'POST',
18-
bodyType: dataType,
19-
bodySize: 0,
20-
}),
21-
`fetchLater() accepts a non-empty POST request body of ${
22-
dataType} in same-origin iframe.`);
23-
continue;
24-
}
25-
2611
parallelPromiseTest(
2712
async _ => await loadFetchLaterIframe(HTTPS_ORIGIN, {
2813
activateAfter: 0,
2914
method: 'POST',
3015
bodyType: dataType,
3116
bodySize: 0,
32-
expect: new FetchLaterIframeExpectation(
33-
FetchLaterExpectationType.ERROR_JS, TypeError),
3417
}),
35-
`fetchLater() does not accept empty POST request body of ${
18+
`fetchLater() accepts a non-empty POST request body of ${
3619
dataType} in same-origin iframe.`);
3720
}

0 commit comments

Comments
 (0)