1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00

Fix parser regression

Add regression test
Rename big_offset to big_str_size

Fixes #924
This commit is contained in:
Ruben Bridgewater
2015-11-25 20:13:57 +01:00
parent 97e699b5d2
commit 3f945dbf3e
3 changed files with 33 additions and 10 deletions

View File

@@ -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))

View File

@@ -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;
@@ -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
@@ -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) {
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;
}
if (this._buffers.length !== 0) {
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;

View File

@@ -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);
});
});
});
});