Browse Source

Include *all* object keys, not just enumerable string keys

master
Sven Slootweg 10 months ago
parent
commit
b21051e8b4
1 changed files with 4 additions and 3 deletions
  1. +4
    -3
      index.js

+ 4
- 3
index.js View File

@ -33,7 +33,7 @@ module.exports = function hasShape(rules) {
let unexpectedPropertyErrors = asExpression(() => {
if (!allowExtraProperties) {
return Object.keys(object).map((propertyName) => {
return Reflect.ownKeys(object).map((propertyName) => {
if (!containsRules(rules[propertyName])) {
return new ValidationError(`Encountered an unexpected property '${propertyName}'`);
} else {
@ -58,8 +58,8 @@ module.exports = function hasShape(rules) {
// We need to consider the keys from the ruleset (for detecting missing required properties) *and* the keys from the actual object (for handling extraneous values).
let allKeys = arrayUnion(
Object.keys(rules),
Object.keys(object)
Reflect.ownKeys(rules),
Reflect.ownKeys(object)
);
for (let key of allKeys) {
@ -82,6 +82,7 @@ module.exports = function hasShape(rules) {
}
} else {
// Extraneous property
// FIXME: Assign non-enumerable if the source property was non-enumerable!
newObject[key] = value;
}
}


Loading…
Cancel
Save