Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Fix JSON.stringify causing TypeErrors #2029
Fix JSON.stringify throwing TypeError if Model object is placed as object property or in an array.
JSON.stringify calls .toJSON on object to be serialized. When called in array, it passes index as parameter to .toJSON. When called in object it passes the property name as parameter:
Bookshelf model accepts options object as parameter for toJSON, it however does not check if passed parameter is object before trying to put properties in it. This results in
The proposed solution is to check if options is really an object by checking it with lodash.isPlainObject.
Current PR Issues
Not benchmarked this, so can't know the performance implications.
Simpler Object check might be more performant. One from redux: