From debe81e5d2a5d02c4b64d6addbb407f8d29984c2 Mon Sep 17 00:00:00 2001 From: Kostas Chatzikokolakis Date: Fri, 8 Jan 2016 18:04:57 +0100 Subject: [PATCH 1/2] add test for object whose toJSON() returns a Buffer --- test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test.js b/test.js index e818ec8..fc2f4f9 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)); }); From e8e8382b61a930fc6c3984469558a768f626c497 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Tue, 28 Feb 2017 21:55:34 +0100 Subject: [PATCH 2/2] fix --- index.js | 2 +- test.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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 fc2f4f9..bbe12f1 100644 --- a/test.js +++ b/test.js @@ -29,8 +29,8 @@ 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') }}; + 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)); });