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

Commit 2f960f1

Browse files
danbaruaIgorMinar
authored andcommitted
fix($http): fix double-quoted date issue when encoding params
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
1 parent 3f5f20f commit 2f960f1

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/ng/http.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,11 @@ function $HttpProvider() {
10441044

10451045
forEach(value, function(v) {
10461046
if (isObject(v)) {
1047-
v = toJson(v);
1047+
if (isDate(v)){
1048+
v = v.toISOString();
1049+
} else if (isObject(v)) {
1050+
v = toJson(v);
1051+
}
10481052
}
10491053
parts.push(encodeUriQuery(key) + '=' +
10501054
encodeUriQuery(v));

test/ng/httpSpec.js

+5
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,11 @@ describe('$http', function() {
461461
$httpBackend.expect('GET', '/url').respond('');
462462
$http({url: '/url', params: {}, method: 'GET'});
463463
});
464+
465+
it('should not double quote dates', function() {
466+
$httpBackend.expect('GET', '/url?date=2014-07-15T17:30:00.000Z').respond('');
467+
$http({url: '/url', params: {date:new Date('2014-07-15T17:30:00.000Z')}, method: 'GET'});
468+
});
464469
});
465470

466471

0 commit comments

Comments
 (0)