Skip to content

Commit 1cbffb1

Browse files
committed
Remove extra conditions
1 parent 0acd73c commit 1cbffb1

2 files changed

Lines changed: 7 additions & 19 deletions

File tree

index.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,17 @@ function rangeParser (size, str, options) {
3838
// split the range string
3939
var arr = str.slice(index + 1).split(',')
4040
var ranges = []
41+
var code = -1
4142

4243
// add ranges type
4344
ranges.type = str.slice(0, index)
4445

45-
// check if there are multiple ranges
46-
var isMultiple = arr.length > 1
47-
var status = -2 // -2: all ranges invalid, -1: at least one valid but unsatisfiable
48-
4946
// parse all ranges
5047
for (var i = 0; i < arr.length; i++) {
5148
var indexOf = arr[i].indexOf('-')
5249
if (indexOf === -1) {
53-
// ignore empty/whitespace-only ranges if there are other valid ranges
54-
if (arr.length > 1 && arr[i].trim() === '') {
55-
continue
56-
}
57-
return -2
50+
code = -2
51+
continue
5852
}
5953

6054
var startStr = arr[i].slice(0, indexOf).trim()
@@ -77,15 +71,10 @@ function rangeParser (size, str, options) {
7771

7872
// invalid format range
7973
if (isNaN(start) || isNaN(end)) {
80-
if (!isMultiple) {
81-
return -2
82-
}
74+
code = -2
8375
continue
8476
}
8577

86-
// unsatisifiable
87-
status = -1
88-
8978
// skip unsatisfiable ranges
9079
if (start > end || start < 0) {
9180
continue
@@ -99,7 +88,7 @@ function rangeParser (size, str, options) {
9988
}
10089

10190
if (ranges.length < 1) {
102-
return status
91+
return code
10392
}
10493

10594
return options && options.combine

test/range-parser.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ describe('parseRange(len, str)', function () {
1515
it('should return -2 for range missing dash', function () {
1616
assert.strictEqual(parse(200, 'bytes=100200'), -2)
1717
assert.strictEqual(parse(200, 'bytes=,100200'), -2)
18-
assert.strictEqual(parse(200, 'bytes=100-200,100200'), -2)
1918
})
2019

2120
it('should return -2 for invalid str', function () {
@@ -77,8 +76,8 @@ describe('parseRange(len, str)', function () {
7776
})
7877

7978
it('should return -1 when invalid format mixed with unsatisfiable ranges', function () {
80-
assert.strictEqual(parse(200, 'bytes=500-600,x-'), -1)
81-
assert.strictEqual(parse(200, 'bytes=x-,500-600'), -1)
79+
assert.strictEqual(parse(200, 'bytes=500-600,900-'), -1)
80+
assert.strictEqual(parse(200, 'bytes=900-,500-600'), -1)
8281
})
8382

8483
it('should parse str', function () {

0 commit comments

Comments
 (0)