Skip to content

Commit

Permalink
backport #3764 fix to 3.8.x
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Jan 15, 2016
1 parent 37c2c68 commit 2ff7d36
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/schema/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ SchemaBuffer.prototype.cast = function (value, doc, init) {

var type = typeof value;
if ('string' == type || 'number' == type || Array.isArray(value)) {
if (type === 'number') {
value = [value];
}
var ret = new MongooseBuffer(value, [this.path, doc]);
return ret;
}
Expand Down
9 changes: 9 additions & 0 deletions test/types.buffer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,5 +449,14 @@ describe('types.buffer', function(){
})
})
})

it('cast from number (gh-3764)', function(done) {
var schema = new Schema({ buf: Buffer });
var MyModel = mongoose.model('gh3764', schema);

var doc = new MyModel({ buf: 9001 });
assert.equal(doc.buf.length, 1);
done();
});
})
})

0 comments on commit 2ff7d36

Please sign in to comment.