From 2f960f1530ed936c57df612a352a0d996368f6a1 Mon Sep 17 00:00:00 2001 From: Dan Barua Date: Fri, 11 Jul 2014 17:34:52 +0100 Subject: [PATCH] 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 --- src/ng/http.js | 6 +++++- test/ng/httpSpec.js | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ng/http.js b/src/ng/http.js index c7f43e221702..19d71c900e66 100644 --- a/src/ng/http.js +++ b/src/ng/http.js @@ -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)); diff --git a/test/ng/httpSpec.js b/test/ng/httpSpec.js index a583f13f005d..fdea7f30b784 100644 --- a/test/ng/httpSpec.js +++ b/test/ng/httpSpec.js @@ -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() { + $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'}); + }); });