diff --git a/index.js b/index.js index 7684d23..efa8fee 100644 --- a/index.js +++ b/index.js @@ -40,7 +40,7 @@ function hasBinary(data) { } } } else if (obj && 'object' == typeof obj) { - if (obj.toJSON) { + if (obj.toJSON && 'function' == typeof obj.toJSON) { obj = obj.toJSON(); } diff --git a/test.js b/test.js index 5320d4f..8d9247c 100644 --- a/test.js +++ b/test.js @@ -22,12 +22,12 @@ describe('has-binarydata', function(){ }); it('should work with an object that does not contain binary', function() { - var ob = {a: 'a', b: [], c: 1234}; + var ob = {a: 'a', b: [], c: 1234, toJSON: '{\"a\": \"a\"}'}; assert(!hasBinary(ob)); }); it('should work with an object that contains a buffer', function() { - var ob = {a: 'a', b: new Buffer('abc'), c: 1234}; + var ob = {a: 'a', b: new Buffer('abc'), c: 1234, toJSON: '{\"a\": \"a\"}'}; assert(hasBinary(ob)); });