revert: fix(Angular.js): toKeyValue is not serializing null values

This commit contained broken tests and was not ready to be merged.

(reverted from commit 814c9847e8)
This commit is contained in:
Peter Bacon Darwin
2014-12-01 12:42:18 +00:00
parent 814c9847e8
commit b264be40bc
2 changed files with 7 additions and 17 deletions

View File

@@ -1062,16 +1062,14 @@ function parseKeyValue(/**string*/keyValue) {
function toKeyValue(obj) {
var parts = [];
forEach(obj, function(value, key) {
if (value !== null) {
if (isArray(value)) {
forEach(value, function(arrayValue) {
parts.push(encodeUriQuery(key, true) +
(arrayValue === true ? '' : '=' + encodeUriQuery(arrayValue, true)));
});
} else {
if (isArray(value)) {
forEach(value, function(arrayValue) {
parts.push(encodeUriQuery(key, true) +
(value === true ? '' : '=' + encodeUriQuery(value, true)));
}
(arrayValue === true ? '' : '=' + encodeUriQuery(arrayValue, true)));
});
} else {
parts.push(encodeUriQuery(key, true) +
(value === true ? '' : '=' + encodeUriQuery(value, true)));
}
});
return parts.length ? parts.join('&') : '';

View File

@@ -491,14 +491,6 @@ describe('angular', function() {
expect(toKeyValue({key: [323,'value',true, 1234]})).
toEqual('key=323&key=value&key&key=1234');
});
it('should not serialize null values', function() {
expect(toKeyValue({nullKey: null, key: 'value'})).toEqual('key=value');
});
it('should not serialize undefined', function() {
expect(toKeyValue({undefinedKey: undefined, key: 'value'})).toEqual('key=value');
});
});