Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 301fdda

Browse files
committedMay 7, 2017
fix(httpParamSerializerJQLike): Follow jQuery for null and undefined
Follow jQuery when serializing `null` and `undefined`. Closes: #15969 Closes: #15971
1 parent 1069086 commit 301fdda

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed
 

‎src/ng/http.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ function $HttpParamSerializerJQLikeProvider() {
110110
return parts.join('&');
111111

112112
function serialize(toSerialize, prefix, topLevel) {
113-
if (toSerialize === null || isUndefined(toSerialize)) return;
114113
if (isArray(toSerialize)) {
115114
forEach(toSerialize, function(value, index) {
116115
serialize(value, prefix + '[' + (isObject(value) ? index : '') + ']');
@@ -123,7 +122,8 @@ function $HttpParamSerializerJQLikeProvider() {
123122
(topLevel ? '' : ']'));
124123
});
125124
} else {
126-
parts.push(encodeUriQuery(prefix) + '=' + encodeUriQuery(serializeValue(toSerialize)));
125+
parts.push(encodeUriQuery(prefix) + '=' +
126+
(toSerialize == null ? '' : encodeUriQuery(serializeValue(toSerialize))));
127127
}
128128
}
129129
};

‎test/ng/httpSpec.js

+6
Original file line numberDiff line numberDiff line change
@@ -2306,5 +2306,11 @@ describe('$http param serializers', function() {
23062306
'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');
23072307
//a[]=b&a[]=c&d[0][e]=f&d[0][g]=h&d[]=i&d[2][j]=k
23082308
});
2309+
2310+
it('should serialize `null` and `undefined` elements as empty', function() {
2311+
expect(jqrSer({items:['foo', 'bar', null, undefined, 'baz'], x: null, y: undefined})).toEqual(
2312+
'items%5B%5D=foo&items%5B%5D=bar&items%5B%5D=&items%5B%5D=&items%5B%5D=baz&x=&y=');
2313+
//items[]=foo&items[]=bar&items[]=&items[]=&items[]=baz&x=&y=
2314+
});
23092315
});
23102316
});

0 commit comments

Comments
 (0)
This repository has been archived.