Chore: Fix logical operator priority (regression) to disallow GET/HEAD with non-empty body (#1369)

This commit is contained in:
Maxim Shirshin 2021-12-06 17:14:42 +01:00 committed by GitHub
parent 7ba5bc9e0a
commit eb33090b81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -59,7 +59,7 @@ export default class Request extends Body {
method = method.toUpperCase();
// eslint-disable-next-line no-eq-null, eqeqeq
if (((init.body != null || isRequest(input)) && input.body !== null) &&
if ((init.body != null || (isRequest(input) && input.body !== null)) &&
(method === 'GET' || method === 'HEAD')) {
throw new TypeError('Request with GET/HEAD method cannot have body');
}

View File

@ -123,6 +123,8 @@ describe('Request', () => {
.to.throw(TypeError);
expect(() => new Request(base, {body: 'a', method: 'head'}))
.to.throw(TypeError);
expect(() => new Request(new Request(base), {body: 'a'}))
.to.throw(TypeError);
});
it('should throw error when including credentials', () => {