fix(httpParamSerializerJQLike): Follow jQuery for null and undefined

Follow jQuery when serializing `null` and `undefined`.

Closes: #15969
Closes: #15971
This commit is contained in:
Lucas Mirelmann
2017-05-07 18:05:20 +02:00
parent 1069086299
commit 301fdda648
2 changed files with 8 additions and 2 deletions
+2 -2
View File
@@ -110,7 +110,6 @@ function $HttpParamSerializerJQLikeProvider() {
return parts.join('&');
function serialize(toSerialize, prefix, topLevel) {
if (toSerialize === null || isUndefined(toSerialize)) return;
if (isArray(toSerialize)) {
forEach(toSerialize, function(value, index) {
serialize(value, prefix + '[' + (isObject(value) ? index : '') + ']');
@@ -123,7 +122,8 @@ function $HttpParamSerializerJQLikeProvider() {
(topLevel ? '' : ']'));
});
} else {
parts.push(encodeUriQuery(prefix) + '=' + encodeUriQuery(serializeValue(toSerialize)));
parts.push(encodeUriQuery(prefix) + '=' +
(toSerialize == null ? '' : encodeUriQuery(serializeValue(toSerialize))));
}
}
};
+6
View File
@@ -2306,5 +2306,11 @@ describe('$http param serializers', function() {
'a%5B%5D=b&a%5B%5D=c&d%5B0%5D%5Be%5D=f&d%5B0%5D%5Bg%5D=h&d%5B%5D=i&d%5B2%5D%5Bj%5D=k');
//a[]=b&a[]=c&d[0][e]=f&d[0][g]=h&d[]=i&d[2][j]=k
});
it('should serialize `null` and `undefined` elements as empty', function() {
expect(jqrSer({items:['foo', 'bar', null, undefined, 'baz'], x: null, y: undefined})).toEqual(
'items%5B%5D=foo&items%5B%5D=bar&items%5B%5D=&items%5B%5D=&items%5B%5D=baz&x=&y=');
//items[]=foo&items[]=bar&items[]=&items[]=&items[]=baz&x=&y=
});
});
});