-
-
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
Merged
+63
−6
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
53dfd91
fix: still show ranges if there are multiple ranges, even if some are…
bjohansebas 7622b94
test: add case for range missing dash in parseRange
bjohansebas c0bb7ea
refactor
bjohansebas 0acd73c
add cases for handling empty and whitespace-only ranges in parseRange
bjohansebas 1cbffb1
Remove extra conditions
blakeembrey 4d89644
Remove invalid test
blakeembrey 87b3c8a
Add mixed invalids test back
blakeembrey 2718a65
Change to -1 for invalids + unsatisfied
blakeembrey cd769d6
Update test name
blakeembrey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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,16 @@ 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) | ||
| assert.strictEqual(parse(200, 'bytes=100-200,100200'), -2) | ||
| }) | ||
|
Comment on lines
15
to
18
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| it('should return -2 for invalid str', function () { | ||
| assert.strictEqual(parse(200, 'malformed'), -2) | ||
| }) | ||
|
|
@@ -28,6 +37,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 +56,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 +76,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,x-'), -1) | ||
| assert.strictEqual(parse(200, 'bytes=x-,500-600'), -1) | ||
| }) | ||
|
|
||
| it('should parse str', function () { | ||
| var range = parse(1000, 'bytes=0-499') | ||
| assert.strictEqual(range.type, 'bytes') | ||
|
|
@@ -111,6 +137,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 +209,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 }) | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 handles a case where the range can be
'bytes= , 0-10', which before the two PRs was valid and returned ranges, but without this patch it returns-2.