Skip to content

Emit function crash if my data contain a toJSON attribute #2284

@ghost

Description

Hello,

I'm using socket.io 1.3.7:
When I'm doing :
io.to(channel).emit('subject', { toJSON: '{"myString": "As Json"}' });

I receive this :

TypeError: obj.toJSON is not a function
at _hasBinary (/home/jderuere/Repository/pup/pup-activity-logging/node_modules/socket.io/node_modules/has-binary-data/index.js:43:19)
at _hasBinary (/home/jderuere/Repository/pup/pup-activity-logging/node_modules/socket.io/node_modules/has-binary-data/index.js:47:40)
at _hasBinary (/home/jderuere/Repository/pup/pup-activity-logging/node_modules/socket.io/node_modules/has-binary-data/index.js:47:40)
at _hasBinary (/home/jderuere/Repository/pup/pup-activity-logging/node_modules/socket.io/node_modules/has-binary-data/index.js:47:40)
at _hasBinary (/home/jderuere/Repository/pup/pup-activity-logging/node_modules/socket.io/node_modules/has-binary-data/index.js:37:15)
at _hasBinary (/home/jderuere/Repository/pup/pup-activity-logging/node_modules/socket.io/node_modules/has-binary-data/index.js:47:40)
at _hasBinary (/home/jderuere/Repository/pup/pup-activity-logging/node_modules/socket.io/node_modules/has-binary-data/index.js:37:15)
at _hasBinary (/home/jderuere/Repository/pup/pup-activity-logging/node_modules/socket.io/node_modules/has-binary-data/index.js:47:40)
at _hasBinary (/home/jderuere/Repository/pup/pup-activity-logging/node_modules/socket.io/node_modules/has-binary-data/index.js:47:40)
at _hasBinary (/home/jderuere/Repository/pup/pup-activity-logging/node_modules/socket.io/node_modules/has-binary-data/index.js:37:15)
at hasBinary (/home/jderuere/Repository/pup/pup-activity-logging/node_modules/socket.io/node_modules/has-binary-data/index.js:56:10)
at Namespace.emit (/my-project/node_modules/socket.io/lib/namespace.js:210:9)

I think it should be :
if (obj.toJSON && typeof obj.toJSON == 'function')

Thanks for all the works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions