From 3525d8a3947b81eddb8ecdbc309e085d6950b3fe Mon Sep 17 00:00:00 2001 From: Brian Yarger Date: Fri, 18 Sep 2015 13:30:05 -0700 Subject: [PATCH] fix(http): throw if url is not string or Request Closes #4245 Closes #4257 --- modules/angular2/src/http/http.ts | 4 ++++ modules/angular2/test/http/http_spec.ts | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/modules/angular2/src/http/http.ts b/modules/angular2/src/http/http.ts index 5fc4c1d808..773b191760 100644 --- a/modules/angular2/src/http/http.ts +++ b/modules/angular2/src/http/http.ts @@ -120,6 +120,8 @@ export class Http { new Request(mergeOptions(this._defaultOptions, options, RequestMethods.Get, url))); } else if (url instanceof Request) { responseObservable = httpRequest(this._backend, url); + } else { + throw makeTypeError('First argument must be a url string or Request instance.'); } return responseObservable; } @@ -201,6 +203,8 @@ export class Jsonp extends Http { makeTypeError('JSONP requests must use GET request method.'); } responseObservable = httpRequest(this._backend, url); + } else { + throw makeTypeError('First argument must be a url string or Request instance.'); } return responseObservable; } diff --git a/modules/angular2/test/http/http_spec.ts b/modules/angular2/test/http/http_spec.ts index 7f099ae1f7..4e61760340 100644 --- a/modules/angular2/test/http/http_spec.ts +++ b/modules/angular2/test/http/http_spec.ts @@ -103,6 +103,7 @@ export function main() { var injector: Injector; var backend: MockBackend; var baseResponse; + var jsonp: Jsonp; beforeEach(() => { injector = Injector.resolveAndCreate([ BaseRequestOptions, @@ -111,9 +112,15 @@ export function main() { function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) { return new Http(backend, defaultOptions); }, + [MockBackend, BaseRequestOptions]), + bind(Jsonp).toFactory( + function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) { + return new Jsonp(backend, defaultOptions); + }, [MockBackend, BaseRequestOptions]) ]); http = injector.get(Http); + jsonp = injector.get(Jsonp); backend = injector.get(MockBackend); baseResponse = new Response(new ResponseOptions({body: 'base response'})); }); @@ -160,6 +167,13 @@ export function main() { // async.done(); // }); // })); + + + it('should throw if url is not a string or Request', () => { + var req = {}; + expect(() => http.request(req)) + .toThrowError('First argument must be a url string or Request instance.'); + }); }); @@ -306,5 +320,15 @@ export function main() { })); }); }); + + describe('Jsonp', () => { + describe('.request()', () => { + it('should throw if url is not a string or Request', () => { + var req = {}; + expect(() => jsonp.request(req)) + .toThrowError('First argument must be a url string or Request instance.'); + }); + }); + }); }); }