Skip to content

Commit

Permalink
fix: molnarg#38
Browse files Browse the repository at this point in the history
not equivalent rafactoring of code. fixes issue with empty object validataion
  • Loading branch information
vedmalex committed Jun 1, 2015
1 parent 7cbbd0a commit 487d9dc
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions lib/patterns/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var ObjectSchema = module.exports = Schema.patterns.ObjectSchema = Schema.extend
if (error = self.stringProps[key].value.errors(instance[key])) {
errors[key] = error
}
} else if (self.stringProps[key].min > 0) {
} else if (self.stringProps[key].min > 0 && self.stringProps[key].value.validate(instance[key])) {
errors[key] = 'key is not present in the object'
}
})
Expand Down Expand Up @@ -88,11 +88,8 @@ var ObjectSchema = module.exports = Schema.patterns.ObjectSchema = Schema.extend

// Simple string properties
var stringPropsValid = Object.keys(this.stringProps).every(function(key) {
if (key in instance) {
return self.stringProps[key].value.validate(instance[key])
} else {
return self.stringProps[key].min === 0
}
return (self.stringProps[key].min === 0 && !(key in instance)) ||
(self.stringProps[key].value.validate(instance[key]));
})
if (!stringPropsValid) return false

Expand Down

0 comments on commit 487d9dc

Please sign in to comment.