You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Escape js parser protocol error characters
This commit is contained in:
@@ -137,7 +137,7 @@ JavascriptReplyParser.prototype.run = function (buffer) {
|
|||||||
if (this._type !== undefined && this._protocol_error === true) {
|
if (this._type !== undefined && this._protocol_error === true) {
|
||||||
// Reset the buffer so the parser can handle following commands properly
|
// Reset the buffer so the parser can handle following commands properly
|
||||||
this._buffer = new Buffer(0);
|
this._buffer = new Buffer(0);
|
||||||
this.send_error(new Error('Protocol error, got "' + String.fromCharCode(this._type) + '" as reply type byte'));
|
this.send_error(new Error('Protocol error, got ' + JSON.stringify(String.fromCharCode(this._type)) + ' as reply type byte'));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -73,6 +73,45 @@ describe('parsers', function () {
|
|||||||
assert.strictEqual(err_count, 1);
|
assert.strictEqual(err_count, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('parser error v3', function () {
|
||||||
|
var parser = new Parser();
|
||||||
|
var reply_count = 0;
|
||||||
|
var err_count = 0;
|
||||||
|
function check_reply (reply) {
|
||||||
|
reply = utils.reply_to_strings(reply);
|
||||||
|
assert.strictEqual(reply[0], 'OK');
|
||||||
|
reply_count++;
|
||||||
|
}
|
||||||
|
function check_error (err) {
|
||||||
|
assert.strictEqual(err.message, 'Protocol error, got "\\n" as reply type byte');
|
||||||
|
err_count++;
|
||||||
|
}
|
||||||
|
parser.send_error = check_error;
|
||||||
|
parser.send_reply = check_reply;
|
||||||
|
|
||||||
|
parser.execute(new Buffer('*1\r\n+OK\r\n\n+zasd\r\n'));
|
||||||
|
assert.strictEqual(reply_count, 1);
|
||||||
|
assert.strictEqual(err_count, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle \\r and \\n characters properly', function () {
|
||||||
|
// If a string contains \r or \n characters it will always be send as a bulk string
|
||||||
|
var parser = new Parser();
|
||||||
|
var reply_count = 0;
|
||||||
|
var entries = ['foo\r', 'foo\r\nbar', '\r\nfoo', 'foo\r\n'];
|
||||||
|
function check_reply (reply) {
|
||||||
|
reply = utils.reply_to_strings(reply);
|
||||||
|
assert.strictEqual(reply, entries[reply_count]);
|
||||||
|
reply_count++;
|
||||||
|
}
|
||||||
|
parser.send_reply = check_reply;
|
||||||
|
|
||||||
|
parser.execute(new Buffer('$4\r\nfoo\r\r\n$8\r\nfoo\r\nbar\r\n$5\r\n\r\n'));
|
||||||
|
assert.strictEqual(reply_count, 2);
|
||||||
|
parser.execute(new Buffer('foo\r\n$5\r\nfoo\r\n\r\n'));
|
||||||
|
assert.strictEqual(reply_count, 4);
|
||||||
|
});
|
||||||
|
|
||||||
it('line breaks in the beginning of the last chunk', function () {
|
it('line breaks in the beginning of the last chunk', function () {
|
||||||
var parser = new Parser();
|
var parser = new Parser();
|
||||||
var reply_count = 0;
|
var reply_count = 0;
|
||||||
|
Reference in New Issue
Block a user