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

fix($http): do not add trailing question #6342

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/ng/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,10 @@ function $HttpProvider() {
encodeUriQuery(v));
});
});
return url + ((url.indexOf('?') == -1) ? '?' : '&') + parts.join('&');
if(parts.length > 0) {
url += ((url.indexOf('?') == -1) ? '?' : '&') + parts.join('&');
}
return url;
}


Expand Down
5 changes: 5 additions & 0 deletions test/ng/httpSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,11 @@ describe('$http', function() {
$httpBackend.expect('GET', '/Path?!do%26h=g%3Da+h&:bar=$baz@1').respond('');
$http({url: '/Path', params: {':bar': '$baz@1', '!do&h': 'g=a h'}, method: 'GET'});
});

it('should not add question mark when params is empty', function() {
$httpBackend.expect('GET', '/url').respond('');
$http({url: '/url', params: {}, method: 'GET'});
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

semicolon missing. we'll start automatically validating this in the future. just fyi

});


Expand Down
2 changes: 1 addition & 1 deletion test/ngResource/resourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ describe("resource", function() {


it('should not throw TypeError on null default params', function() {
$httpBackend.expect('GET', '/Path?').respond('{}');
$httpBackend.expect('GET', '/Path').respond('{}');
var R = $resource('/Path', {param: null}, {get: {method: 'GET'}});

expect(function() {
Expand Down