Skip to content

Commit

Permalink
fix($http): fix double-quoted date issue when encoding params
Browse files Browse the repository at this point in the history
This commit special cases date handling rather than calling toJSON as we always need
a string representation of the object.

$http was wrapping dates in double quotes leading to query strings like this:
  ?date=%222014-07-07T23:00:00.000Z%22

Closes angular#8150
Closes angular#6128
Closes angular#8154
  • Loading branch information
danbarua authored and Cameron Knight committed Jul 16, 2014
1 parent 3c4001a commit 82c67ae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ng/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,11 @@ function $HttpProvider() {

forEach(value, function(v) {
if (isObject(v)) {
v = toJson(v);
if (isDate(v)){
v = v.toISOString();
} else if (isObject(v)) {
v = toJson(v);
}
}
parts.push(encodeUriQuery(key) + '=' +
encodeUriQuery(v));
Expand Down
5 changes: 5 additions & 0 deletions test/ng/httpSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ describe('$http', function() {
$httpBackend.expect('GET', '/url').respond('');
$http({url: '/url', params: {}, method: 'GET'});
});

it('should not double quote dates', function() {
$httpBackend.expect('GET', '/url?date=2014-07-15T17:30:00.000Z').respond('');
$http({url: '/url', params: {date:new Date('2014-07-15T17:30:00.000Z')}, method: 'GET'});
});
});


Expand Down

0 comments on commit 82c67ae

Please sign in to comment.