From 1dbe587fcabe4cf2ee99a6774484279790608c2f Mon Sep 17 00:00:00 2001 From: Jerry Sievert Date: Fri, 14 Sep 2012 13:51:49 -0700 Subject: [PATCH] remove null for rewind and use throw mechanism, should help with #273 Fix #275 Signed-off-by: DTrejo --- lib/parser/javascript.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/parser/javascript.js b/lib/parser/javascript.js index b2d6cb2387..dd70cf0987 100644 --- a/lib/parser/javascript.js +++ b/lib/parser/javascript.js @@ -46,6 +46,11 @@ ReplyParser.prototype._parseResult = function (type) { // include the delimiter this._offset = end + 2; + if (end > this._buffer.length) { + this._offset = start; + throw new Error("too far"); + } + if (this.options.return_buffers) { return this._buffer.slice(start, end); } else { @@ -63,6 +68,11 @@ ReplyParser.prototype._parseResult = function (type) { // include the delimiter this._offset = end + 2; + if (end > this._buffer.length) { + this._offset = start; + throw new Error("too far"); + } + // return the coerced numeric value return +small_toString(this._buffer, start, end); } else if (type === 36) { // $ @@ -85,7 +95,7 @@ ReplyParser.prototype._parseResult = function (type) { if (end > this._buffer.length) { this._offset = offset; - return null; + throw new Error("too far"); } if (this.options.return_buffers) {