fix(httpParamSerializerJQLike): Follow jQuery for null and undefined
Follow jQuery when serializing `null` and `undefined`. Closes: #15969 Closes: #15971
This commit is contained in:
+2
-2
@@ -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))));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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=
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user