Skip to content

Commit

Permalink
fix(document): pass default array as actual array rather than taking …
Browse files Browse the repository at this point in the history
…first element

Fix #5780
  • Loading branch information
vkarpov15 committed Nov 4, 2017
1 parent 4ff5f52 commit e8a29bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/schema/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function SchemaArray(key, cast, options, schemaOptions) {
if (fn) {
arr = defaultArr();
} else if (defaultArr != null) {
arr = defaultArr;
arr = arr.concat(defaultArr);
}
// Leave it up to `cast()` to convert the array
return arr;
Expand Down
19 changes: 12 additions & 7 deletions lib/schematype.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,23 @@ function SchemaType(path, options, instance) {
this._index = null;
this.selected;

for (var i in options) {
if (this[i] && typeof this[i] === 'function') {
for (var prop in options) {
if (this[prop] && typeof this[prop] === 'function') {
// { unique: true, index: true }
if (i === 'index' && this._index) {
if (prop === 'index' && this._index) {
continue;
}

var opts = Array.isArray(options[i])
? options[i]
: [options[i]];
var val = options[prop];
// Special case so we don't screw up array defaults, see gh-5780
if (prop === 'default') {
this.default(val);
continue;
}

var opts = Array.isArray(val) ? val : [val];

this[i].apply(this, opts);
this[prop].apply(this, opts);
}
}

Expand Down

0 comments on commit e8a29bb

Please sign in to comment.