Skip to content

Commit 1dbe587

Browse files
JerrySievertDTrejo
authored andcommitted
remove null for rewind and use throw mechanism, should help with #273
Fix #275 Signed-off-by: DTrejo <[email protected]>
1 parent 0391b95 commit 1dbe587

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/parser/javascript.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ ReplyParser.prototype._parseResult = function (type) {
4646
// include the delimiter
4747
this._offset = end + 2;
4848

49+
if (end > this._buffer.length) {
50+
this._offset = start;
51+
throw new Error("too far");
52+
}
53+
4954
if (this.options.return_buffers) {
5055
return this._buffer.slice(start, end);
5156
} else {
@@ -63,6 +68,11 @@ ReplyParser.prototype._parseResult = function (type) {
6368
// include the delimiter
6469
this._offset = end + 2;
6570

71+
if (end > this._buffer.length) {
72+
this._offset = start;
73+
throw new Error("too far");
74+
}
75+
6676
// return the coerced numeric value
6777
return +small_toString(this._buffer, start, end);
6878
} else if (type === 36) { // $
@@ -85,7 +95,7 @@ ReplyParser.prototype._parseResult = function (type) {
8595

8696
if (end > this._buffer.length) {
8797
this._offset = offset;
88-
return null;
98+
throw new Error("too far");
8999
}
90100

91101
if (this.options.return_buffers) {

0 commit comments

Comments
 (0)