Skip to content

test: cover unsatisfiable and invalid ranges in req.range - #7572

Open
saiyam-jain-dev wants to merge 2 commits into
expressjs:masterfrom
saiyam-jain-dev:test/req-range-error-codes
Open

saiyam-jain-dev wants to merge 2 commits into
expressjs:masterfrom
saiyam-jain-dev:test/req-range-error-codes

Conversation

@saiyam-jain-dev

@saiyam-jain-dev saiyam-jain-dev commented Oct 28, 2026 •

Copy link
Copy Markdown

Add unit test coverage in test/req.range.js for the error return values documented in lib/request.js:

If the Range header field is not given undefined is returned, -1 when unsatisfiable, and -2 when syntactically invalid.

The existing test suite verified parsed ranges, size capping, .type, and undefined returns when no header is present, but lacked coverage for:

  • Returning -1 when the range is unsatisfiable (e.g. bytes=200-300 for size 120)
  • Returning -2 when the range is syntactically invalid (e.g. bytes 0-2 missing =)
  • Both error return values when options are provided (e.g. { combine: true })

All 1,294 tests pass (npm test) and npm run lint passes with zero errors.

@zengks

zengks commented Oct 28, 2026

Copy link
Copy Markdown

These tests pass with range-parser 1.3.0, but Express currently allows ^1.2.1. With 1.2.1, bytes=invalid returns -1, so both new -2 tests fail. Could the malformed-header cases use an input such as bytes 0-2, which returns -2 in both versions, or should the minimum parser version be updated?

Signed-off-by: Saiyam Jain <jimisierra2@gmail.com>
@saiyam-jain-dev
saiyam-jain-dev force-pushed the test/req-range-error-codes branch from de760e6 to a948d27 Compare October 28, 2026 20:25
@saiyam-jain-dev

saiyam-jain-dev commented Oct 28, 2026 •

Copy link
Copy Markdown
Author

Good catch! I've updated both invalid cases to use bytes 0-2 (missing the = delimiter), which returns -2 consistently across both range-parser@1.2.1 and range-parser@1.3.0 without requiring a dependency bump.

@yxshee yxshee left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verified the update for @zengks's point: with range-parser@1.2.1 (the minimum Express allows) and 1.3.0 (what installs today), bytes 0-2 returns -2 and bytes=200-300 returns -1 for size 120, both with and without { combine: true }. So the four new assertions hold across the supported range.

Full suite on this branch: 1294 passing. LGTM.

@subhiandrews subhiandrews left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

code-check review

1 suggestion

Reviewed with code-check · Apache-2.0

Comment thread test/req.range.js Resolved
@saiyam-jain-dev

saiyam-jain-dev commented Nov 25, 2026 •

Copy link
Copy Markdown
Author

Updated in 542ff1b: moved both tests inside describe('with "combine: true" option', ...) per review feedback and verified npm run lint and npm test (1294 passing) locally.

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.

4 participants