Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix($http): throw if url passed is not a string
Browse files Browse the repository at this point in the history
Throw to prevent hard to debug errors in functions that are
called later.

Fixes #12925
Closes #13444
  • Loading branch information
Utsav Shah authored and Narretz committed Dec 3, 2015
1 parent be01ceb commit c5bf9da
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ng/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,10 @@ function $HttpProvider() {
throw minErr('$http')('badreq', 'Http request configuration must be an object. Received: {0}', requestConfig);
}

if (!isString(requestConfig.url)) {
throw minErr('$http')('badreq', 'Http request configuration url must be a string. Received: {0}', requestConfig.url);
}

var config = extend({
method: 'get',
transformRequest: defaults.transformRequest,
Expand Down
7 changes: 7 additions & 0 deletions test/ng/httpSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,13 @@ describe('$http', function() {
}).toThrowMinErr('$http','badreq', 'Http request configuration must be an object. Received: /url');
});

it('should throw error if the request configuration url is not a string', function() {
expect(function() {
$http({url: false});
}).toThrowMinErr('$http','badreq', 'Http request configuration url must be a string. Received: false');
});


it('should send GET requests if no method specified', function() {
$httpBackend.expect('GET', '/url').respond('');
$http({url: '/url'});
Expand Down

0 comments on commit c5bf9da

Please sign in to comment.