mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1187011 - Don't allow response body with null body status. r=bkelly
This commit is contained in:
parent
6862ae67d8
commit
fffe1fa002
@ -68,6 +68,7 @@ MSG_DEF(MSG_FETCH_BODY_CONSUMED_ERROR, 0, JSEXN_TYPEERR, "Body has already been
|
||||
MSG_DEF(MSG_RESPONSE_INVALID_STATUSTEXT_ERROR, 0, JSEXN_TYPEERR, "Response statusText may not contain newline or carriage return.")
|
||||
MSG_DEF(MSG_FETCH_FAILED, 0, JSEXN_TYPEERR, "NetworkError when attempting to fetch resource.")
|
||||
MSG_DEF(MSG_NO_BODY_ALLOWED_FOR_GET_AND_HEAD, 0, JSEXN_TYPEERR, "HEAD or GET Request cannot have a body.")
|
||||
MSG_DEF(MSG_RESPONSE_NULL_STATUS_WITH_BODY, 0, JSEXN_TYPEERR, "Response body is given with a null body status.")
|
||||
MSG_DEF(MSG_DEFINE_NON_CONFIGURABLE_PROP_ON_WINDOW, 0, JSEXN_TYPEERR, "Not allowed to define a non-configurable property on the WindowProxy object")
|
||||
MSG_DEF(MSG_INVALID_ZOOMANDPAN_VALUE_ERROR, 0, JSEXN_RANGEERR, "Invalid zoom and pan value.")
|
||||
MSG_DEF(MSG_INVALID_TRANSFORM_ANGLE_ERROR, 0, JSEXN_RANGEERR, "Invalid transform angle.")
|
||||
|
@ -198,6 +198,11 @@ Response::Constructor(const GlobalObject& aGlobal,
|
||||
}
|
||||
|
||||
if (aBody.WasPassed()) {
|
||||
if (aInit.mStatus == 204 || aInit.mStatus == 205 || aInit.mStatus == 304) {
|
||||
aRv.ThrowTypeError(MSG_RESPONSE_NULL_STATUS_WITH_BODY);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIInputStream> bodyStream;
|
||||
nsCString contentType;
|
||||
aRv = ExtractByteStreamFromBody(aBody.Value(), getter_AddRefs(bodyStream), contentType);
|
||||
|
@ -108,16 +108,16 @@ function testRedirect() {
|
||||
}
|
||||
|
||||
function testOk() {
|
||||
var r1 = new Response("", { status: 200});
|
||||
var r1 = new Response("", { status: 200 });
|
||||
ok(r1.ok, "Response with status 200 should have ok true");
|
||||
|
||||
var r2 = new Response("", { status: 204});
|
||||
var r2 = new Response(undefined, { status: 204 });
|
||||
ok(r2.ok, "Response with status 204 should have ok true");
|
||||
|
||||
var r3 = new Response("", { status: 299});
|
||||
var r3 = new Response("", { status: 299 });
|
||||
ok(r3.ok, "Response with status 299 should have ok true");
|
||||
|
||||
var r4 = new Response("", { status: 302});
|
||||
var r4 = new Response("", { status: 302 });
|
||||
ok(!r4.ok, "Response with status 302 should have ok false");
|
||||
}
|
||||
|
||||
@ -202,11 +202,32 @@ function testBodyExtraction() {
|
||||
})
|
||||
}
|
||||
|
||||
function testNullBodyStatus() {
|
||||
[204, 205, 304].forEach(function(status) {
|
||||
try {
|
||||
var res = new Response(new Blob(), { "status": status });
|
||||
ok(false, "Response body provided but status code does not permit a body");
|
||||
} catch(e) {
|
||||
ok(true, "Response body provided but status code does not permit a body");
|
||||
}
|
||||
});
|
||||
|
||||
[204, 205, 304].forEach(function(status) {
|
||||
try {
|
||||
var res = new Response(undefined, { "status": status });
|
||||
ok(true, "Response body provided but status code does not permit a body");
|
||||
} catch(e) {
|
||||
ok(false, "Response body provided but status code does not permit a body");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function runTest() {
|
||||
testDefaultCtor();
|
||||
testError();
|
||||
testRedirect();
|
||||
testOk();
|
||||
testNullBodyStatus();
|
||||
|
||||
return Promise.resolve()
|
||||
.then(testBodyCreation)
|
||||
|
Loading…
Reference in New Issue
Block a user