diff --git a/index.js b/index.js index 4fc7415..4a57ffc 100644 --- a/index.js +++ b/index.js @@ -45,7 +45,7 @@ function hasBinary (obj) { // see: https://github.com/Automattic/has-binary/pull/4 if (obj.toJSON && typeof obj.toJSON === 'function') { - obj = obj.toJSON(); + return hasBinary(obj.toJSON()); } for (var key in obj) { diff --git a/test.js b/test.js index e818ec8..bbe12f1 100644 --- a/test.js +++ b/test.js @@ -29,6 +29,11 @@ describe('has-binarydata', function () { assert(hasBinary(ob)); }); + it('should work with an object whose toJSON() returns a buffer', function () { + var ob = {a: 'a', b: [], c: 1234, toJSON: function () { return new Buffer('abc'); }}; + assert(hasBinary(ob)); + }); + it('should work with null', function () { assert(!hasBinary(null)); });