Repository navigation
Always expose ranges with return code - #71
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #71 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 1 1
Lines 68 81 +13
Branches 17 23 +6
=========================================
+ Hits 68 81 +13 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
yxshee
left a comment
There was a problem hiding this comment.
I like the fixed return shape. Callers like send currently branch on -1/-2 and then on .length, so one object with a code is easier to get right. I ran the branch and found two things:
-
Empty list elements set
code: 1, but only when they aren't at the end.parse(100, "bytes=0-1,,2-3") // code 1, both ranges returned parse(100, "bytes=,0-1") // code 1 parse(100, "bytes=0-1,") // code 0
RFC 9110 section 5.6.1.2 says a recipient MUST accept and ignore empty list elements, so all three should probably be
code: 0. Otherwise a caller that takes the "reject any non-zero code" option rejects a valid header. I thinkbytes= , ,(no elements at all) should stay malformed. -
The README example checks
subranges.length, which is alwaysundefinedon the result object, so theforEachnever runs. It should besubranges.ranges.length, like thecombineRangesexample below it.
Also, #72 changes the same two whitespace lines (it accepts HTAB as OWS), so whichever lands second will need a small rebase. I'm happy to do that on my side.
bjohansebas
left a comment
There was a problem hiding this comment.
I like this way of returning the data
yxshee
left a comment
There was a problem hiding this comment.
I like the fixed return shape. Callers like send currently branch on -1/-2 and then on .length, so one object with a code is easier to get right. I ran the branch and found two things:
-
Empty list elements set
code: 1, but only when they aren't at the end.parse(100, "bytes=0-1,,2-3") // code 1, both ranges returned parse(100, "bytes=,0-1") // code 1 parse(100, "bytes=0-1,") // code 0
RFC 9110 section 5.6.1.2 says a recipient MUST accept and ignore empty list elements, so all three should probably be
code: 0. Otherwise a caller that takes the "reject any non-zero code" option rejects a valid header. I thinkbytes= , ,(no elements at all) should stay malformed. -
The README example checks
subranges.length, which is alwaysundefinedon the result object, so theforEachnever runs. It should besubranges.ranges.length, like thecombineRangesexample below it.
Also, #72 changes the same two whitespace lines (it accepts HTAB as OWS), so whichever lands second will need a small rebase. I'm happy to do that on my side.
|
Rolled the fixes into this PR, it was necessary to better handle some other edge cases too. The only awkward feature now is that inclusive start/end makes it zero length files required to have an empty Personally exclusive end is more intuitive, but inclusive lines it up with the spec better and avoids foot guns during the major upgrade. |
Opening to get opinions, but I prefer this approach as the output shape doesn't get changed on you and it gives the caller more flexibility.
Current behavior is to always return an object when anything is parsed successfully, and silently drop the ranges that failed. If nothing parsed or is valid, return a negative number.
With this approach, the shape always stays the same and a caller can choose either to reject things that parse incorrectly (any non-zero code) or use
ranges.lengthlike we currently do.