diff --git a/changelog.md b/changelog.md index d0cc69f8b6..ef585e082d 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,10 @@ Changelog ========= +Bugfixes + +- Fixed a js parser error that could result in a timeout ([@BridgeAR](https://github.com/BridgeAR)) + ## v.2.2.5 - 18 Oct, 2015 Bugfixes diff --git a/lib/parsers/javascript.js b/lib/parsers/javascript.js index 7da5c3ed14..5d0208b46b 100644 --- a/lib/parsers/javascript.js +++ b/lib/parsers/javascript.js @@ -117,9 +117,7 @@ JavascriptReplyParser.prototype.execute = function (buffer) { offset = this._offset - 1; this.send_reply(this._parseResult(type)); - } else if (type === 10 || type === 13) { - break; - } else { + } else if (type !== 10 && type !== 13) { var err = new Error('Protocol error, got "' + String.fromCharCode(type) + '" as reply type byte'); this.send_error(err); } diff --git a/test/parser.spec.js b/test/parser.spec.js index f54181ba78..01dd38e539 100644 --- a/test/parser.spec.js +++ b/test/parser.spec.js @@ -55,7 +55,7 @@ describe('parsers', function () { return done(); }); - it('line breaks in the beginning', function (done) { + it('line breaks in the beginning of the last chunk', function (done) { var parser = new Parser(); var reply_count = 0; function check_reply(reply) { @@ -68,10 +68,7 @@ describe('parsers', function () { parser.execute(new Buffer('*1\r\n*1\r\n$1\r\na')); parser.execute(new Buffer('\r\n*1\r\n*1\r')); - parser.execute(new Buffer('\n$1\r\na\r\n')); - - parser.execute(new Buffer('*1\r\n*1\r\n')); - parser.execute(new Buffer('$1\r\na\r\n')); + parser.execute(new Buffer('\n$1\r\na\r\n*1\r\n*1\r\n$1\r\na\r\n')); assert.equal(reply_count, 3, "check reply should have been called three times"); return done();