Skip to content

fix: do not reject open-ended Range values in simpleRangeHeaderValue#5490

Merged
mcollina merged 1 commit into
nodejs:mainfrom
spokodev:w33/undici-range-open-ended
Jul 2, 2026
Merged

fix: do not reject open-ended Range values in simpleRangeHeaderValue#5490
mcollina merged 1 commit into
nodejs:mainfrom
spokodev:w33/undici-range-open-ended

Conversation

@spokodev

@spokodev spokodev commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

The "simple range header value" parser rejected valid open-ended ranges such
as bytes=5-.

Per https://fetch.spec.whatwg.org/#simple-range-header-value step 18, the
"start greater than end" failure only applies when rangeStartValue and
rangeEndValue are both numbers. For an open-ended range like bytes=5-,
rangeEndValue is null. The code compared rangeStartValue > rangeEndValue
directly, and JavaScript coerces null to 0 in that comparison, so 5 > null
becomes 5 > 0, which is true, and the parser returned failure.

The effect is that fetch() of a blob: URL with Range: bytes=5- returned a
network error and the promise rejected, instead of returning a 206 Partial
Content. bytes=0- worked only by accident because 0 does not exceed 0.

This change guards the comparison so it runs only when both values are numbers,
matching the spec. A genuinely inverted range such as bytes=5-3 still returns
failure, and the null-null case is already handled by step 17.

Added a test that fetches a blob URL with Range: bytes=5- and asserts a 206
response with the correct body and Content-Range.

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.46%. Comparing base (782ad38) to head (f1fcded).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5490   +/-   ##
=======================================
  Coverage   93.45%   93.46%           
=======================================
  Files         110      110           
  Lines       37147    37150    +3     
=======================================
+ Hits        34716    34721    +5     
+ Misses       2431     2429    -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mcollina mcollina merged commit 838b6cd into nodejs:main Jul 2, 2026
38 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants