From 574a052dc1f76046bd97010e1ec6fb2d4739c677 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Thu, 16 Aug 2012 06:54:03 -0400 Subject: [PATCH] use strings for empty message part check. --- lib/sockets/rep.js | 2 +- lib/sockets/req.js | 2 +- test/test.reqrep.json.js | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 test/test.reqrep.json.js diff --git a/lib/sockets/rep.js b/lib/sockets/rep.js index ea423a8..5eae59c 100644 --- a/lib/sockets/rep.js +++ b/lib/sockets/rep.js @@ -43,7 +43,7 @@ RepSocket.prototype.onmessage = function(sock){ var envelopes = []; for (var i = 0; i < msg.length; ++i) { - if (0x00 === msg[i][0]) { + if ('\u0000' === String(msg[i])) { envelopes = msg.splice(0, ++i); } } diff --git a/lib/sockets/req.js b/lib/sockets/req.js index a71a693..1a6e73f 100644 --- a/lib/sockets/req.js +++ b/lib/sockets/req.js @@ -44,7 +44,7 @@ ReqSocket.prototype.onmessage = function(){ var self = this; return function(msg, multipart){ if (!multipart) return debug('expected multipart'); - if (0x00 !== msg[0][0]) return debug('malformed message'); + if ('\u0000' != String(msg[0])) return debug('malformed message'); self.emit.apply(self, ['message'].concat(msg.slice(1))); }; }; diff --git a/test/test.reqrep.json.js b/test/test.reqrep.json.js new file mode 100644 index 0000000..39c5193 --- /dev/null +++ b/test/test.reqrep.json.js @@ -0,0 +1,31 @@ + +var ss = require('../') + , should = require('should'); + +var server = ss.socket('rep') + , client = ss.socket('req'); + +server.format('json'); +client.format('json'); + +server.bind(3000); +client.connect(3000); + +server.on('message', function(msg, reply){ + msg.should.have.property('cmd', 'hello'); + reply({ + error: null, + result: 'thanks' + }); +}); + +client.on('message', function(msg){ + msg.should.have.property('error', null); + msg.should.have.property('result', 'thanks'); + client.close(); + server.close(); +}); + +client.send({ + cmd: 'hello' +}); \ No newline at end of file