Skip to content

Commit

Permalink
Fix parser regression
Browse files Browse the repository at this point in the history
Add regression test
Rename big_offset to big_str_size

Fixes #924
  • Loading branch information
Ruben Bridgewater committed Nov 25, 2015
1 parent 97e699b commit 3f945db
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
8 changes: 7 additions & 1 deletion changelog.md
@@ -1,11 +1,17 @@
Changelog
=========

## v.2.4.1 - 25 Nov, 2015

Bugfixes

- Fixed a js parser regression introduced in 2.4.0 ([@BridgeAR](https://github.com/BridgeAR))

## v.2.4.0 - 25 Nov, 2015

Features

- Added `tls` option to iniate a connection to a redis server behind a TLS proxy. Thanks ([@paddybyers](https://github.com/paddybyers))
- Added `tls` option to initiate a connection to a redis server behind a TLS proxy. Thanks ([@paddybyers](https://github.com/paddybyers))
- Added `prefix` option to auto key prefix any command with the provided prefix ([@luin](https://github.com/luin) & [@BridgeAR](https://github.com/BridgeAR))
- Added `url` option to pass the connection url with the options object ([@BridgeAR](https://github.com/BridgeAR))
- Added `client.duplicate([options])` to duplicate the current client and return a new one with the same options ([@BridgeAR](https://github.com/BridgeAR))
Expand Down
18 changes: 9 additions & 9 deletions lib/parsers/javascript.js
Expand Up @@ -6,7 +6,7 @@ function JavascriptReplyParser() {
this.name = exports.name;
this._buffer = new Buffer(0);
this._offset = 0;
this._big_offset = 0;
this._big_str_size = 0;
this._chunks_size = 0;
this._buffers = [];
this._type = 0;
Expand Down Expand Up @@ -53,7 +53,7 @@ JavascriptReplyParser.prototype._parseResult = function (type) {

if (end + 2 > this._buffer.length) {
this._chunks_size = this._buffer.length - this._offset - 2;
this._big_offset = packetHeader;
this._big_str_size = packetHeader;
throw new IncompleteReadBuffer('Wait for more data.');
}
// Set the offset to after the delimiter
Expand Down Expand Up @@ -85,17 +85,17 @@ JavascriptReplyParser.prototype._parseResult = function (type) {
};

JavascriptReplyParser.prototype.execute = function (buffer) {
if (this._chunks_size !== 0 && this._big_offset > this._chunks_size + buffer.length) {
this._buffers.push(buffer);
this._chunks_size += buffer.length;
return;
}
if (this._buffers.length !== 0) {
if (this._chunks_size !== 0) {
if (this._big_str_size > this._chunks_size + buffer.length) {
this._buffers.push(buffer);
this._chunks_size += buffer.length;
return;
}
this._buffers.unshift(this._offset === 0 ? this._buffer : this._buffer.slice(this._offset));
this._buffers.push(buffer);
this._buffer = Buffer.concat(this._buffers);
this._buffers = [];
this._big_offset = 0;
this._big_str_size = 0;
this._chunks_size = 0;
} else if (this._offset >= this._buffer.length) {
this._buffer = buffer;
Expand Down
17 changes: 17 additions & 0 deletions test/parser.spec.js
Expand Up @@ -256,6 +256,23 @@ describe('parsers', function () {
parser.execute(new Buffer('*1\r\n$4\r\ntest\r\n'));
assert.strictEqual(reply_count, 3);
});

it('regression test v.2.4.1', function () {
var parser = new Parser(true);
var reply_count = 0;
var entries = ['test test ', 'test test test test ', '1234'];
function check_reply(reply) {
assert.strictEqual(reply.toString(), entries[reply_count]);
reply_count++;
}
parser.send_reply = check_reply;
parser.execute(new Buffer('$10\r\ntest '));
assert.strictEqual(reply_count, 0);
parser.execute(new Buffer('test \r\n$20\r\ntest test test test \r\n:1234\r'));
assert.strictEqual(reply_count, 2);
parser.execute(new Buffer('\n'));
assert.strictEqual(reply_count, 3);
});
});
});
});

0 comments on commit 3f945db

Please sign in to comment.