Skip to content

Commit 097d42d

Browse files
committed
fix($http): fix double-quoted date issue when encoding params
$http was wrapping dates in double quotes leading to query strings like this: ?date=%222014-07-07T23:00:00.000Z%22 Instead of calling JSON.stringify, this fix checks to see if a param object has a toJSON() function and uses that for encoding, falling back to JSON.stringify as per the previous behaviour. Closes angular#8150 and angular#6128
1 parent 363fb4f commit 097d42d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/ng/http.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use strict';
1+
'use strict';
22

33
/**
44
* Parse headers into key value object
@@ -990,7 +990,12 @@ function $HttpProvider() {
990990

991991
forEach(value, function(v) {
992992
if (isObject(v)) {
993-
v = toJson(v);
993+
if (isDefined(v.toJSON)){
994+
v = v.toJSON();
995+
}
996+
else {
997+
v = toJson(v);
998+
}
994999
}
9951000
parts.push(encodeUriQuery(key) + '=' +
9961001
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)