From 08ff2e52492b9543971ce58e62397eaec560e663 Mon Sep 17 00:00:00 2001 From: domusofsail Date: Sat, 10 Dec 2016 00:39:39 +0100 Subject: [PATCH] fix(http): check response body text against undefined (#13017) --- modules/@angular/http/src/body.ts | 2 +- modules/@angular/http/test/static_request_spec.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/@angular/http/src/body.ts b/modules/@angular/http/src/body.ts index 7e660a80e8..053a7e9475 100644 --- a/modules/@angular/http/src/body.ts +++ b/modules/@angular/http/src/body.ts @@ -47,7 +47,7 @@ export abstract class Body { return String.fromCharCode.apply(null, new Uint16Array(this._body)); } - if (this._body === null) { + if (this._body == null) { return ''; } diff --git a/modules/@angular/http/test/static_request_spec.ts b/modules/@angular/http/test/static_request_spec.ts index 5d8262d42a..25a1188154 100644 --- a/modules/@angular/http/test/static_request_spec.ts +++ b/modules/@angular/http/test/static_request_spec.ts @@ -88,5 +88,14 @@ export function main() { expect(req.text()).toEqual(''); }); + + it('should return empty string if body is undefined', () => { + const reqOptions = new RequestOptions( + {url: 'test', method: 'GET', headers: new Headers({'content-type': 'application/json'})}); + delete reqOptions.body; + const req = new Request(reqOptions); + + expect(req.text()).toEqual(''); + }); }); }