From a948d27fa5ff0a0bac6e1be2dc2dcb2254f4d4ee Mon Sep 17 00:00:00 2001 From: Saiyam Jain Date: Thu, 29 Oct 2026 00:34:46 +0530 Subject: [PATCH 1/2] test: cover unsatisfiable and invalid ranges in req.range Signed-off-by: Saiyam Jain --- test/req.range.js | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/test/req.range.js b/test/req.range.js index 111441736eb..727b172904c 100644 --- a/test/req.range.js +++ b/test/req.range.js @@ -81,6 +81,32 @@ describe('req', function(){ .get('/') .expect(200, 'undefined', done) }) + + it('should return -1 if range is unsatisfiable', function (done) { + var app = express() + + app.use(function (req, res) { + res.json(req.range(120)) + }) + + request(app) + .get('/') + .set('Range', 'bytes=200-300') + .expect(200, '-1', done) + }) + + it('should return -2 if range is syntactically invalid', function (done) { + var app = express() + + app.use(function (req, res) { + res.json(req.range(120)) + }) + + request(app) + .get('/') + .set('Range', 'bytes 0-2') + .expect(200, '-2', done) + }) }) describe('.range(size, options)', function(){ @@ -100,5 +126,35 @@ describe('req', function(){ .expect(200, '[{"start":0,"end":100}]', done) }) }) + + it('should return -1 if range is unsatisfiable with options', function (done) { + var app = express() + + app.use(function (req, res) { + res.json(req.range(120, { + combine: true + })) + }) + + request(app) + .get('/') + .set('Range', 'bytes=200-300') + .expect(200, '-1', done) + }) + + it('should return -2 if range is syntactically invalid with options', function (done) { + var app = express() + + app.use(function (req, res) { + res.json(req.range(120, { + combine: true + })) + }) + + request(app) + .get('/') + .set('Range', 'bytes 0-2') + .expect(200, '-2', done) + }) }) }) From 542ff1b61af9cb66b54089ba0b8a3f3d5ec359ca Mon Sep 17 00:00:00 2001 From: Saiyam Jain Date: Wed, 25 Nov 2026 12:30:05 +0530 Subject: [PATCH 2/2] test(req.range): move options error tests inside combine describe block --- test/req.range.js | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/test/req.range.js b/test/req.range.js index 727b172904c..73f02c3d776 100644 --- a/test/req.range.js +++ b/test/req.range.js @@ -125,36 +125,36 @@ describe('req', function(){ .set('Range', 'bytes=0-50,51-100') .expect(200, '[{"start":0,"end":100}]', done) }) - }) - it('should return -1 if range is unsatisfiable with options', function (done) { - var app = express() + it('should return -1 if range is unsatisfiable', function (done) { + var app = express() - app.use(function (req, res) { - res.json(req.range(120, { - combine: true - })) + app.use(function (req, res) { + res.json(req.range(120, { + combine: true + })) + }) + + request(app) + .get('/') + .set('Range', 'bytes=200-300') + .expect(200, '-1', done) }) - request(app) - .get('/') - .set('Range', 'bytes=200-300') - .expect(200, '-1', done) - }) + it('should return -2 if range is syntactically invalid', function (done) { + var app = express() - it('should return -2 if range is syntactically invalid with options', function (done) { - var app = express() + app.use(function (req, res) { + res.json(req.range(120, { + combine: true + })) + }) - app.use(function (req, res) { - res.json(req.range(120, { - combine: true - })) + request(app) + .get('/') + .set('Range', 'bytes 0-2') + .expect(200, '-2', done) }) - - request(app) - .get('/') - .set('Range', 'bytes 0-2') - .expect(200, '-2', done) }) }) })