From 5060234f4558dde502a661e863477464b4caa60b Mon Sep 17 00:00:00 2001 From: Carl Date: Thu, 27 Jul 2017 11:43:45 +0200 Subject: [PATCH 1/4] Update http.js Avoid that functions in `params` object (like getter or setter) will be encoded in the url. --- src/ng/http.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ng/http.js b/src/ng/http.js index f2c597c452a7..2ed5005c9cae 100644 --- a/src/ng/http.js +++ b/src/ng/http.js @@ -42,6 +42,7 @@ function $HttpParamSerializerProvider() { var parts = []; forEachSorted(params, function(value, key) { if (value === null || isUndefined(value)) return; + if (typeof value === 'function') return; if (isArray(value)) { forEach(value, function(v) { parts.push(encodeUriQuery(key) + '=' + encodeUriQuery(serializeValue(v))); From cbfafade0a62ce5d2a0fd77a4889cd295cf01ecd Mon Sep 17 00:00:00 2001 From: Carl Date: Thu, 27 Jul 2017 13:44:44 +0200 Subject: [PATCH 2/4] fix($http): add check for functions in params when submitting params as class-object checks and remove functions --- src/ng/http.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ng/http.js b/src/ng/http.js index 2ed5005c9cae..a4e2094ab203 100644 --- a/src/ng/http.js +++ b/src/ng/http.js @@ -41,8 +41,7 @@ function $HttpParamSerializerProvider() { if (!params) return ''; var parts = []; forEachSorted(params, function(value, key) { - if (value === null || isUndefined(value)) return; - if (typeof value === 'function') return; + if (value === null || isUndefined(value) || isFunction(value)) return; if (isArray(value)) { forEach(value, function(v) { parts.push(encodeUriQuery(key) + '=' + encodeUriQuery(serializeValue(v))); From 7ee320a9fbdac516732e8e21f55369466011a811 Mon Sep 17 00:00:00 2001 From: Carl Date: Thu, 27 Jul 2017 14:02:23 +0200 Subject: [PATCH 3/4] test($http): serialize functions default serializer should NOT serialize functions --- test/ng/httpSpec.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/ng/httpSpec.js b/test/ng/httpSpec.js index 5b21ee15a56b..6abab53dc52e 100644 --- a/test/ng/httpSpec.js +++ b/test/ng/httpSpec.js @@ -2344,6 +2344,10 @@ describe('$http param serializers', function() { expect(defSer({someDate: new Date('2014-07-15T17:30:00.000Z')})).toEqual('someDate=2014-07-15T17:30:00.000Z'); expect(jqrSer({someDate: new Date('2014-07-15T17:30:00.000Z')})).toEqual('someDate=2014-07-15T17:30:00.000Z'); }); + + it('should NOT serialize functions', function() { + expect(defSer({foo: 'foov', bar: function(){}})).toEqual('bar=barv'); + }); }); From a787ece14c65d3b96a155b399ad469c65c99478d Mon Sep 17 00:00:00 2001 From: Carl Date: Thu, 27 Jul 2017 14:10:35 +0200 Subject: [PATCH 4/4] test($http): default serializer default serializer shoud not serialize functions --- test/ng/httpSpec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/ng/httpSpec.js b/test/ng/httpSpec.js index 6abab53dc52e..dc17a207681f 100644 --- a/test/ng/httpSpec.js +++ b/test/ng/httpSpec.js @@ -2344,9 +2344,9 @@ describe('$http param serializers', function() { expect(defSer({someDate: new Date('2014-07-15T17:30:00.000Z')})).toEqual('someDate=2014-07-15T17:30:00.000Z'); expect(jqrSer({someDate: new Date('2014-07-15T17:30:00.000Z')})).toEqual('someDate=2014-07-15T17:30:00.000Z'); }); - + it('should NOT serialize functions', function() { - expect(defSer({foo: 'foov', bar: function(){}})).toEqual('bar=barv'); + expect(defSer({foo: 'foov', bar: function() {}})).toEqual('bar=barv'); }); });