diff --git a/index.js b/index.js index b7dc5c0..56f7c0b 100644 --- a/index.js +++ b/index.js @@ -50,10 +50,18 @@ function rangeParser (size, str, options) { // -nnn if (isNaN(start)) { + if (range[0].length > 0) { + return -2 + } + start = size - end end = size - 1 // nnn- } else if (isNaN(end)) { + if (range[1].length > 0) { + return -2 + } + end = size - 1 } diff --git a/test/range-parser.js b/test/range-parser.js index e2af8b4..0d75354 100644 --- a/test/range-parser.js +++ b/test/range-parser.js @@ -13,6 +13,14 @@ describe('parseRange(len, str)', function () { assert.strictEqual(parse(200, 'malformed'), -2) }) + it('should return -2 for invalid start byte position', function () { + assert.strictEqual(parse(200, 'bytes=x-100'), -2) + }) + + it('should return -2 for invalid end byte position', function () { + assert.strictEqual(parse(200, 'bytes=100-x'), -2) + }) + it('should return -1 if all specified ranges are invalid', function () { assert.strictEqual(parse(200, 'bytes=500-20'), -1) assert.strictEqual(parse(200, 'bytes=500-999'), -1)