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

Commit

Permalink
fix(httpParamSerializerJQLike): Follow jQuery for null and undefined
Browse files Browse the repository at this point in the history
Follow jQuery when serializing `null` and `undefined`.

Closes: #15969
Closes: #15971
  • Loading branch information
lgalfaso committed May 7, 2017
1 parent 1069086 commit 301fdda
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ng/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 : '') + ']');
Expand All @@ -123,7 +122,8 @@ function $HttpParamSerializerJQLikeProvider() {
(topLevel ? '' : ']'));
});
} else {
parts.push(encodeUriQuery(prefix) + '=' + encodeUriQuery(serializeValue(toSerialize)));
parts.push(encodeUriQuery(prefix) + '=' +
(toSerialize == null ? '' : encodeUriQuery(serializeValue(toSerialize))));
}
}
};
Expand Down
6 changes: 6 additions & 0 deletions test/ng/httpSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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=
});
});
});

0 comments on commit 301fdda

Please sign in to comment.