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

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 #8150
Closes #6128
Closes #8154
  • Loading branch information
danbarua authored and IgorMinar committed Jul 16, 2014
1 parent 3f5f20f commit 2f960f1
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 @@ -1044,7 +1044,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 @@ -461,6 +461,11 @@ describe('$http', function() {
$httpBackend.expect('GET', '/url').respond('');
$http({url: '/url', params: {}, method: 'GET'});
});

it('should not double quote dates', function() {

This comment has been minimized.

Copy link
@caitp

caitp Jul 16, 2014

Contributor

This comment has been minimized.

Copy link
@caitp

caitp Jul 16, 2014

Contributor

Reason: IE8 does not implement Date.prototype.toISOString() --- we should probably just not test this in IE8, since we need people to polyfill this method there.

This comment has been minimized.

Copy link
@caitp

caitp Jul 16, 2014

Contributor

added a PR for this --- we could land it in master too just to keep the trees in sync

$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 2f960f1

Please sign in to comment.