Skip to content

Commit

Permalink
fix: prevent from calling Date.prototype.toJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjake committed Aug 5, 2021
1 parent 6d0ac83 commit 81368fc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/bone.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ class Bone {
if (typeof this[key] !== 'function') {
const value = this[key];
if (value != null) {
obj[key] = typeof value.toJSON === 'function' ? value.toJSON() : value;
obj[key] = value instanceof Bone ? value.toJSON() : value;
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions test/integration/suite/basics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,11 @@ describe('=> Integration', function() {
const post = await Post.findOne({ title: 'New Post' });
const result = post.toJSON();

delete result.updatedAt;
delete result.createdAt;

expect(result).to.be.an('object');
expect(result.id).to.be.ok();
expect(result.title).to.equal('New Post');
expect(result.extra).to.eql({ versions: [2, 3] });
assert(result.createdAt instanceof Date);
});

it('bone.toJSON() with missing attributes', async function() {
Expand Down

0 comments on commit 81368fc

Please sign in to comment.