Skip to content

Commit 4e9ff43

Browse files
committed
offset string extract on larger buffers
1 parent 365b0d0 commit 4e9ff43

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

.jshintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"freeze": true, // prohibit overwriting prototypes of native objects
1010
"maxdepth": 4,
1111
"latedef": true,
12-
"maxparams": 3,
12+
"maxparams": 4,
1313

1414
// Environment options
1515
"node": true, // Enable globals available when code is running inside of the NodeJS runtime environment.

lib/javascript.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ function parseSimpleString(parser) {
3333
* @param parser
3434
* @param start
3535
* @param end
36+
* @param noBuffer
3637
* @returns {*}
3738
*/
38-
function convertBufferRange(parser, start, end) {
39+
function convertBufferRange(parser, start, end, noBuffer) {
3940
// If returnBuffers is active, all return values are returned as buffers besides numbers and errors
40-
if (parser.optionReturnBuffers === true) {
41+
if (!noBuffer && parser.optionReturnBuffers === true) {
4142
return parser.buffer.slice(start, end);
4243
}
4344

@@ -48,9 +49,10 @@ function convertBufferRange(parser, start, end) {
4849
* Parse a '+' redis simple string response but forward the offsets
4950
* onto convertBufferRange to generate a string.
5051
* @param parser
52+
* @param noBuffer
5153
* @returns {*}
5254
*/
53-
function parseSimpleStringViaOffset(parser) {
55+
function parseSimpleStringViaOffset(parser, noBuffer) {
5456
var start = parser.offset;
5557
var offset = parser.offset;
5658
var length = parser.buffer.length;
@@ -61,7 +63,7 @@ function parseSimpleStringViaOffset(parser) {
6163
var c2 = parser.buffer[offset++];
6264
if (c2 === 10) { // \n
6365
parser.offset = offset;
64-
return convertBufferRange(parser, start, offset - 2);
66+
return convertBufferRange(parser, start, offset - 2, noBuffer);
6567
}
6668
}
6769
}
@@ -74,7 +76,14 @@ function parseSimpleStringViaOffset(parser) {
7476
* @returns {*}
7577
*/
7678
function parseLength(parser) {
77-
var string = parseSimpleString(parser);
79+
var string;
80+
/* istanbul ignore if */
81+
if (parser.buffer.length > 4096) {
82+
string = parseSimpleStringViaOffset(parser, true);
83+
} else {
84+
string = parseSimpleString(parser);
85+
}
86+
7887
if (string !== undefined) {
7988
var length = +string;
8089
if (length === -1) {

0 commit comments

Comments
 (0)