Skip to content

Commit

Permalink
fix(validation): Be able to take in and validate null object event/us…
Browse files Browse the repository at this point in the history
…er properties
  • Loading branch information
kelvin-lu committed Nov 11, 2020
1 parent 77a01ee commit 1ed41a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ var truncate = function truncate(value) {
}
} else if (type(value) === 'object') {
for (var key in value) {
if (value.hasOwnProperty(key)) {
if (key in value) {
value[key] = truncate(value[key]);
}
}
Expand Down Expand Up @@ -110,7 +110,7 @@ var validateProperties = function validateProperties(properties) {

var copy = {}; // create a copy with all of the valid properties
for (var property in properties) {
if (!properties.hasOwnProperty(property)) {
if (!(property in properties)) {
continue;
}

Expand Down
14 changes: 14 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,5 +239,19 @@ describe('utils', function() {
}
assert.deepEqual(utils.validateProperties(properties), {});
});

it('should validate properties on null objects', function() {
var properties = Object.create(null);
properties['test'] = 'yes';
properties['key'] = 'value';
properties['15'] = '16';

var expected = {
'test': 'yes',
'key': 'value',
'15': '16'
};
assert.deepEqual(utils.validateProperties(properties), expected);
});
});
});

0 comments on commit 1ed41a3

Please sign in to comment.