Skip to content

Commit 3f945db

Browse files
author
Ruben Bridgewater
committed
Fix parser regression
Add regression test Rename big_offset to big_str_size Fixes #924
1 parent 97e699b commit 3f945db

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

changelog.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
Changelog
22
=========
33

4+
## v.2.4.1 - 25 Nov, 2015
5+
6+
Bugfixes
7+
8+
- Fixed a js parser regression introduced in 2.4.0 ([@BridgeAR](https://github.com/BridgeAR))
9+
410
## v.2.4.0 - 25 Nov, 2015
511

612
Features
713

8-
- Added `tls` option to iniate a connection to a redis server behind a TLS proxy. Thanks ([@paddybyers](https://github.com/paddybyers))
14+
- Added `tls` option to initiate a connection to a redis server behind a TLS proxy. Thanks ([@paddybyers](https://github.com/paddybyers))
915
- Added `prefix` option to auto key prefix any command with the provided prefix ([@luin](https://github.com/luin) & [@BridgeAR](https://github.com/BridgeAR))
1016
- Added `url` option to pass the connection url with the options object ([@BridgeAR](https://github.com/BridgeAR))
1117
- Added `client.duplicate([options])` to duplicate the current client and return a new one with the same options ([@BridgeAR](https://github.com/BridgeAR))

lib/parsers/javascript.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function JavascriptReplyParser() {
66
this.name = exports.name;
77
this._buffer = new Buffer(0);
88
this._offset = 0;
9-
this._big_offset = 0;
9+
this._big_str_size = 0;
1010
this._chunks_size = 0;
1111
this._buffers = [];
1212
this._type = 0;
@@ -53,7 +53,7 @@ JavascriptReplyParser.prototype._parseResult = function (type) {
5353

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

8787
JavascriptReplyParser.prototype.execute = function (buffer) {
88-
if (this._chunks_size !== 0 && this._big_offset > this._chunks_size + buffer.length) {
89-
this._buffers.push(buffer);
90-
this._chunks_size += buffer.length;
91-
return;
92-
}
93-
if (this._buffers.length !== 0) {
88+
if (this._chunks_size !== 0) {
89+
if (this._big_str_size > this._chunks_size + buffer.length) {
90+
this._buffers.push(buffer);
91+
this._chunks_size += buffer.length;
92+
return;
93+
}
9494
this._buffers.unshift(this._offset === 0 ? this._buffer : this._buffer.slice(this._offset));
9595
this._buffers.push(buffer);
9696
this._buffer = Buffer.concat(this._buffers);
9797
this._buffers = [];
98-
this._big_offset = 0;
98+
this._big_str_size = 0;
9999
this._chunks_size = 0;
100100
} else if (this._offset >= this._buffer.length) {
101101
this._buffer = buffer;

test/parser.spec.js

+17
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,23 @@ describe('parsers', function () {
256256
parser.execute(new Buffer('*1\r\n$4\r\ntest\r\n'));
257257
assert.strictEqual(reply_count, 3);
258258
});
259+
260+
it('regression test v.2.4.1', function () {
261+
var parser = new Parser(true);
262+
var reply_count = 0;
263+
var entries = ['test test ', 'test test test test ', '1234'];
264+
function check_reply(reply) {
265+
assert.strictEqual(reply.toString(), entries[reply_count]);
266+
reply_count++;
267+
}
268+
parser.send_reply = check_reply;
269+
parser.execute(new Buffer('$10\r\ntest '));
270+
assert.strictEqual(reply_count, 0);
271+
parser.execute(new Buffer('test \r\n$20\r\ntest test test test \r\n:1234\r'));
272+
assert.strictEqual(reply_count, 2);
273+
parser.execute(new Buffer('\n'));
274+
assert.strictEqual(reply_count, 3);
275+
});
259276
});
260277
});
261278
});

0 commit comments

Comments
 (0)