-
-
Notifications
You must be signed in to change notification settings - Fork 23
fix: still show ranges if there are multiple ranges, even if some are invalid #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
53dfd91
7622b94
c0bb7ea
0acd73c
1cbffb1
4d89644
87b3c8a
2718a65
cd769d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
|
|
||
| var assert = require('assert') | ||
| var deepEqual = require('deep-equal') | ||
| var parse = require('..') | ||
|
|
@@ -9,6 +8,15 @@ describe('parseRange(len, str)', function () { | |
| /TypeError: argument str must be a string/) | ||
| }) | ||
|
|
||
| it('should return -2 for completely empty header', function () { | ||
| assert.strictEqual(parse(200, ''), -2) | ||
| }) | ||
|
|
||
| it('should return -2 for range missing dash', function () { | ||
| assert.strictEqual(parse(200, 'bytes=100200'), -2) | ||
| assert.strictEqual(parse(200, 'bytes=,100200'), -2) | ||
| }) | ||
|
|
||
| it('should return -2 for invalid str', function () { | ||
| assert.strictEqual(parse(200, 'malformed'), -2) | ||
| }) | ||
|
|
@@ -28,6 +36,12 @@ describe('parseRange(len, str)', function () { | |
| assert.strictEqual(parse(200, 'bytes= - '), -2) | ||
| }) | ||
|
|
||
| it('should return -2 for empty range value', function () { | ||
| assert.strictEqual(parse(200, 'bytes='), -2) | ||
| assert.strictEqual(parse(200, 'bytes=,'), -2) | ||
| assert.strictEqual(parse(200, 'bytes= , , '), -2) | ||
| }) | ||
|
|
||
| it('should return -2 with multiple dashes in range', function () { | ||
| assert.strictEqual(parse(200, 'bytes=100-200-300'), -2) | ||
| }) | ||
|
|
@@ -41,6 +55,12 @@ describe('parseRange(len, str)', function () { | |
| assert.strictEqual(parse(200, 'bytes=100-15b0'), -2) | ||
| }) | ||
|
|
||
| it('should return -2 when all multiple ranges have invalid format', function () { | ||
| assert.strictEqual(parse(200, 'bytes=y-v,x-'), -2) | ||
| assert.strictEqual(parse(200, 'bytes=abc-def,ghi-jkl'), -2) | ||
| assert.strictEqual(parse(200, 'bytes=x-,y-,z-'), -2) | ||
| }) | ||
|
|
||
| it('should return -1 for unsatisfiable range', function () { | ||
| assert.strictEqual(parse(200, 'bytes=500-600'), -1) | ||
| }) | ||
|
|
@@ -55,6 +75,11 @@ describe('parseRange(len, str)', function () { | |
| assert.strictEqual(parse(200, 'bytes=500-999,1000-1499'), -1) | ||
| }) | ||
|
|
||
| it('should return -1 when invalid format mixed with unsatisfiable ranges', function () { | ||
| assert.strictEqual(parse(200, 'bytes=500-600,900-'), -1) | ||
| assert.strictEqual(parse(200, 'bytes=900-,500-600'), -1) | ||
|
||
| }) | ||
|
|
||
| it('should parse str', function () { | ||
| var range = parse(1000, 'bytes=0-499') | ||
| assert.strictEqual(range.type, 'bytes') | ||
|
|
@@ -111,6 +136,28 @@ describe('parseRange(len, str)', function () { | |
| deepEqual(range[0], { start: 999, end: 999 }) | ||
| }) | ||
|
|
||
| it('should ignore invalid format range when valid range exists', function () { | ||
| var range = parse(1000, 'bytes=100-200,x-') | ||
| assert.strictEqual(range.type, 'bytes') | ||
| assert.strictEqual(range.length, 1) | ||
| deepEqual(range[0], { start: 100, end: 200 }) | ||
| }) | ||
|
|
||
| it('should ignore invalid format ranges when some are valid', function () { | ||
| var range = parse(1000, 'bytes=x-,0-100,y-') | ||
| assert.strictEqual(range.type, 'bytes') | ||
| assert.strictEqual(range.length, 1) | ||
| deepEqual(range[0], { start: 0, end: 100 }) | ||
| }) | ||
|
|
||
| it('should ignore invalid format ranges at different positions', function () { | ||
| var range = parse(1000, 'bytes=0-50,abc-def,100-150') | ||
| assert.strictEqual(range.type, 'bytes') | ||
| assert.strictEqual(range.length, 2) | ||
| deepEqual(range[0], { start: 0, end: 50 }) | ||
| deepEqual(range[1], { start: 100, end: 150 }) | ||
| }) | ||
|
|
||
| it('should parse str with multiple ranges', function () { | ||
| var range = parse(1000, 'bytes=40-80,81-90,-1') | ||
| assert.strictEqual(range.type, 'bytes') | ||
|
|
@@ -161,4 +208,11 @@ describe('parseRange(len, str)', function () { | |
| deepEqual(range[2], { start: 0, end: 1 }) | ||
| }) | ||
| }) | ||
|
|
||
| it('should ignore whitespace-only invalid ranges when valid present', function () { | ||
| var range = parse(1000, 'bytes= , 0-10') | ||
| assert.strictEqual(range.type, 'bytes') | ||
| assert.strictEqual(range.length, 1) | ||
| deepEqual(range[0], { start: 0, end: 10 }) | ||
| }) | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to get the coverage to 100%, it has nothing to do with my changes