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

Commit 9dce42b

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 8881606 commit 9dce42b

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
@@ -985,7 +985,11 @@ function $HttpProvider() {
985985

986986
forEach(value, function(v) {
987987
if (isObject(v)) {
988-
v = toJson(v);
988+
if (isDate(v)){
989+
v = v.toISOString();
990+
} else if (isObject(v)) {
991+
v = toJson(v);
992+
}
989993
}
990994
parts.push(encodeUriQuery(key) + '=' +
991995
encodeUriQuery(v));

test/ng/httpSpec.js

+5
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,11 @@ describe('$http', function() {
341341
$httpBackend.expect('GET', '/url').respond('');
342342
$http({url: '/url', params: {}, method: 'GET'});
343343
});
344+
345+
it('should not double quote dates', function() {
346+
$httpBackend.expect('GET', '/url?date=2014-07-15T17:30:00.000Z').respond('');
347+
$http({url: '/url', params: {date:new Date('2014-07-15T17:30:00.000Z')}, method: 'GET'});
348+
});
344349
});
345350

346351

0 commit comments

Comments
 (0)