Skip to content

Commit 518747d

Browse files
fix(*): fix the case when toJSON() returns a Buffer (#6)
1 parent bb1825b commit 518747d

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function hasBinary (obj) {
4545

4646
// see: https://github.com/Automattic/has-binary/pull/4
4747
if (obj.toJSON && typeof obj.toJSON === 'function') {
48-
obj = obj.toJSON();
48+
return hasBinary(obj.toJSON());
4949
}
5050

5151
for (var key in obj) {

test.js

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ describe('has-binarydata', function () {
2929
assert(hasBinary(ob));
3030
});
3131

32+
it('should work with an object whose toJSON() returns a buffer', function () {
33+
var ob = {a: 'a', b: [], c: 1234, toJSON: function () { return new Buffer('abc'); }};
34+
assert(hasBinary(ob));
35+
});
36+
3237
it('should work with null', function () {
3338
assert(!hasBinary(null));
3439
});

0 commit comments

Comments
 (0)