From c221b8596e5ff783bbedadb2d7696f90817b0c85 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 27 Jan 2022 19:02:58 -0500 Subject: [PATCH 001/158] build: mocha@9.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b5db814094..ebb7425d9a 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,7 @@ "istanbul": "0.4.5", "marked": "0.7.0", "method-override": "3.0.0", - "mocha": "9.1.3", + "mocha": "9.2.0", "morgan": "1.10.0", "multiparty": "4.2.2", "pbkdf2-password": "1.2.1", From 69997cbdbef83c5cf1a419d6e86519af432d68a8 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 2 Feb 2022 00:44:28 -0500 Subject: [PATCH 002/158] examples: fix error handling in auth example --- examples/auth/index.js | 7 ++++--- test/acceptance/auth.js | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/examples/auth/index.js b/examples/auth/index.js index b8e854300c..70110891ad 100644 --- a/examples/auth/index.js +++ b/examples/auth/index.js @@ -59,14 +59,14 @@ function authenticate(name, pass, fn) { if (!module.parent) console.log('authenticating %s:%s', name, pass); var user = users[name]; // query the db for the given username - if (!user) return fn(new Error('cannot find user')); + if (!user) return fn(null, null) // apply the same algorithm to the POSTed password, applying // the hash against the pass / salt, if there is a match we // found the user hash({ password: pass, salt: user.salt }, function (err, pass, salt, hash) { if (err) return fn(err); if (hash === user.hash) return fn(null, user) - fn(new Error('invalid password')); + fn(null, null) }); } @@ -99,8 +99,9 @@ app.get('/login', function(req, res){ res.render('login'); }); -app.post('/login', function(req, res){ +app.post('/login', function (req, res, next) { authenticate(req.body.username, req.body.password, function(err, user){ + if (err) return next(err) if (user) { // Regenerate session when signing in // to prevent fixation diff --git a/test/acceptance/auth.js b/test/acceptance/auth.js index 9a36ea45fe..d7838755a0 100644 --- a/test/acceptance/auth.js +++ b/test/acceptance/auth.js @@ -22,7 +22,7 @@ describe('auth', function(){ .expect(200, /
Date: Wed, 2 Feb 2022 01:23:40 -0500 Subject: [PATCH 003/158] tests: add test for hello-world example --- examples/hello-world/index.js | 2 +- test/acceptance/hello-world.js | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 test/acceptance/hello-world.js diff --git a/examples/hello-world/index.js b/examples/hello-world/index.js index 04382ac3d0..d82452f331 100644 --- a/examples/hello-world/index.js +++ b/examples/hello-world/index.js @@ -1,6 +1,6 @@ var express = require('../../'); -var app = express(); +var app = module.exports = express() app.get('/', function(req, res){ res.send('Hello World'); diff --git a/test/acceptance/hello-world.js b/test/acceptance/hello-world.js new file mode 100644 index 0000000000..db90349c49 --- /dev/null +++ b/test/acceptance/hello-world.js @@ -0,0 +1,21 @@ + +var app = require('../../examples/hello-world') +var request = require('supertest') + +describe('hello-world', function () { + describe('GET /', function () { + it('should respond with hello world', function (done) { + request(app) + .get('/') + .expect(200, 'Hello World', done) + }) + }) + + describe('GET /missing', function () { + it('should respond with 404', function (done) { + request(app) + .get('/missing') + .expect(404, done) + }) + }) +}) From 8b9757e8b80d5fd1a5105f9caed8ce5f9aea6c46 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 2 Feb 2022 01:25:55 -0500 Subject: [PATCH 004/158] build: fix running linter in CI --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 80248fab69..e2a4945645 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -133,6 +133,7 @@ jobs: echo "node@$(node -v)" echo "npm@$(npm -v)" npm -s ls ||: + (npm -s ls --depth=0 ||:) | awk -F'[ @]' 'NR>1 && $2 { print "::set-output name=" $2 "::" $3 }' - name: Run tests shell: bash From 20047bb6e40e76aa855632fb423905c4d0b038c3 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 2 Feb 2022 01:30:51 -0500 Subject: [PATCH 005/158] examples: use strict mode --- examples/auth/index.js | 2 ++ examples/content-negotiation/db.js | 2 ++ examples/content-negotiation/index.js | 2 ++ examples/content-negotiation/users.js | 1 + examples/cookie-sessions/index.js | 2 ++ examples/cookies/index.js | 2 ++ examples/downloads/index.js | 2 ++ examples/ejs/index.js | 2 ++ examples/error-pages/index.js | 2 ++ examples/error/index.js | 2 ++ examples/hello-world/index.js | 2 ++ examples/markdown/index.js | 2 ++ examples/multi-router/controllers/api_v1.js | 2 ++ examples/multi-router/controllers/api_v2.js | 2 ++ examples/multi-router/index.js | 2 ++ examples/multipart/index.js | 2 ++ examples/mvc/controllers/main/index.js | 2 ++ examples/mvc/controllers/pet/index.js | 2 ++ examples/mvc/controllers/user-pet/index.js | 2 ++ examples/mvc/controllers/user/index.js | 2 ++ examples/mvc/db.js | 2 ++ examples/mvc/index.js | 2 ++ examples/mvc/lib/boot.js | 2 ++ examples/online/index.js | 1 + examples/params/index.js | 2 ++ examples/resource/index.js | 2 ++ examples/route-map/index.js | 2 ++ examples/route-middleware/index.js | 2 ++ examples/route-separation/index.js | 2 ++ examples/route-separation/post.js | 2 ++ examples/route-separation/site.js | 2 ++ examples/route-separation/user.js | 2 ++ examples/search/index.js | 1 + examples/search/public/client.js | 2 ++ examples/session/index.js | 1 + examples/session/redis.js | 2 ++ examples/static-files/index.js | 2 ++ examples/vhost/index.js | 2 ++ examples/view-constructor/github-view.js | 2 ++ examples/view-constructor/index.js | 2 ++ examples/view-locals/index.js | 2 ++ examples/view-locals/user.js | 2 ++ examples/web-service/index.js | 2 ++ 43 files changed, 82 insertions(+) diff --git a/examples/auth/index.js b/examples/auth/index.js index 70110891ad..36205d0f99 100644 --- a/examples/auth/index.js +++ b/examples/auth/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/content-negotiation/db.js b/examples/content-negotiation/db.js index 43fb04baa1..f59b23bf18 100644 --- a/examples/content-negotiation/db.js +++ b/examples/content-negotiation/db.js @@ -1,3 +1,5 @@ +'use strict' + var users = []; users.push({ name: 'Tobi' }); diff --git a/examples/content-negotiation/index.js b/examples/content-negotiation/index.js index 348929e852..280a4e2299 100644 --- a/examples/content-negotiation/index.js +++ b/examples/content-negotiation/index.js @@ -1,3 +1,5 @@ +'use strict' + var express = require('../../'); var app = module.exports = express(); var users = require('./db'); diff --git a/examples/content-negotiation/users.js b/examples/content-negotiation/users.js index fe511072ec..fe703e73a9 100644 --- a/examples/content-negotiation/users.js +++ b/examples/content-negotiation/users.js @@ -1,3 +1,4 @@ +'use strict' var users = require('./db'); diff --git a/examples/cookie-sessions/index.js b/examples/cookie-sessions/index.js index 1dda15de61..01c731c1c8 100644 --- a/examples/cookie-sessions/index.js +++ b/examples/cookie-sessions/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/cookies/index.js b/examples/cookies/index.js index 93515e5961..04093591f7 100644 --- a/examples/cookies/index.js +++ b/examples/cookies/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/downloads/index.js b/examples/downloads/index.js index 9321f3bf95..91c52bb87c 100644 --- a/examples/downloads/index.js +++ b/examples/downloads/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/ejs/index.js b/examples/ejs/index.js index 7278091293..a39d805a16 100644 --- a/examples/ejs/index.js +++ b/examples/ejs/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/error-pages/index.js b/examples/error-pages/index.js index 44333cb08f..efa815c474 100644 --- a/examples/error-pages/index.js +++ b/examples/error-pages/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/error/index.js b/examples/error/index.js index 07814d8520..d922de06cc 100644 --- a/examples/error/index.js +++ b/examples/error/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/hello-world/index.js b/examples/hello-world/index.js index d82452f331..8c1855c2eb 100644 --- a/examples/hello-world/index.js +++ b/examples/hello-world/index.js @@ -1,3 +1,5 @@ +'use strict' + var express = require('../../'); var app = module.exports = express() diff --git a/examples/markdown/index.js b/examples/markdown/index.js index df8c195fb4..74ac05e77f 100644 --- a/examples/markdown/index.js +++ b/examples/markdown/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/multi-router/controllers/api_v1.js b/examples/multi-router/controllers/api_v1.js index 08b7b5e6fd..a301e3ee72 100644 --- a/examples/multi-router/controllers/api_v1.js +++ b/examples/multi-router/controllers/api_v1.js @@ -1,3 +1,5 @@ +'use strict' + var express = require('../../..'); var apiv1 = express.Router(); diff --git a/examples/multi-router/controllers/api_v2.js b/examples/multi-router/controllers/api_v2.js index 4dd708281c..e997fb1f88 100644 --- a/examples/multi-router/controllers/api_v2.js +++ b/examples/multi-router/controllers/api_v2.js @@ -1,3 +1,5 @@ +'use strict' + var express = require('../../..'); var apiv2 = express.Router(); diff --git a/examples/multi-router/index.js b/examples/multi-router/index.js index 78bae9d6e3..dbfd284126 100644 --- a/examples/multi-router/index.js +++ b/examples/multi-router/index.js @@ -1,3 +1,5 @@ +'use strict' + var express = require('../..'); var app = module.exports = express(); diff --git a/examples/multipart/index.js b/examples/multipart/index.js index 42c2af23f7..ea7b86e0c9 100644 --- a/examples/multipart/index.js +++ b/examples/multipart/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/mvc/controllers/main/index.js b/examples/mvc/controllers/main/index.js index 031862d345..74cde191cd 100644 --- a/examples/mvc/controllers/main/index.js +++ b/examples/mvc/controllers/main/index.js @@ -1,3 +1,5 @@ +'use strict' + exports.index = function(req, res){ res.redirect('/users'); }; diff --git a/examples/mvc/controllers/pet/index.js b/examples/mvc/controllers/pet/index.js index 157a98e84e..214160f9a4 100644 --- a/examples/mvc/controllers/pet/index.js +++ b/examples/mvc/controllers/pet/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/mvc/controllers/user-pet/index.js b/examples/mvc/controllers/user-pet/index.js index 416b00741a..42a29adebe 100644 --- a/examples/mvc/controllers/user-pet/index.js +++ b/examples/mvc/controllers/user-pet/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/mvc/controllers/user/index.js b/examples/mvc/controllers/user/index.js index a7b0208c8e..ec3ae4c811 100644 --- a/examples/mvc/controllers/user/index.js +++ b/examples/mvc/controllers/user/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/mvc/db.js b/examples/mvc/db.js index c992afcfd7..94d1480f9b 100644 --- a/examples/mvc/db.js +++ b/examples/mvc/db.js @@ -1,3 +1,5 @@ +'use strict' + // faux database var pets = exports.pets = []; diff --git a/examples/mvc/index.js b/examples/mvc/index.js index 77885a60ca..da4727b282 100644 --- a/examples/mvc/index.js +++ b/examples/mvc/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/mvc/lib/boot.js b/examples/mvc/lib/boot.js index 422330dc06..0216e5d76d 100644 --- a/examples/mvc/lib/boot.js +++ b/examples/mvc/lib/boot.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/online/index.js b/examples/online/index.js index f14474c08d..0b5fdffc86 100644 --- a/examples/online/index.js +++ b/examples/online/index.js @@ -1,3 +1,4 @@ +'use strict' // install redis first: // https://redis.io/ diff --git a/examples/params/index.js b/examples/params/index.js index 5b57573d1e..b153b93b98 100644 --- a/examples/params/index.js +++ b/examples/params/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/resource/index.js b/examples/resource/index.js index b79ad923d2..ff1f6fe11f 100644 --- a/examples/resource/index.js +++ b/examples/resource/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/route-map/index.js b/examples/route-map/index.js index e7adf5fcb4..2bc28bd4b2 100644 --- a/examples/route-map/index.js +++ b/examples/route-map/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/route-middleware/index.js b/examples/route-middleware/index.js index e7a0901fa8..44ec13a95b 100644 --- a/examples/route-middleware/index.js +++ b/examples/route-middleware/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/route-separation/index.js b/examples/route-separation/index.js index 6512109134..5d48381111 100644 --- a/examples/route-separation/index.js +++ b/examples/route-separation/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/route-separation/post.js b/examples/route-separation/post.js index e3f12e7884..3a8e3a2d22 100644 --- a/examples/route-separation/post.js +++ b/examples/route-separation/post.js @@ -1,3 +1,5 @@ +'use strict' + // Fake posts database var posts = [ diff --git a/examples/route-separation/site.js b/examples/route-separation/site.js index a3d20bc8a1..aee36d1bd7 100644 --- a/examples/route-separation/site.js +++ b/examples/route-separation/site.js @@ -1,3 +1,5 @@ +'use strict' + exports.index = function(req, res){ res.render('index', { title: 'Route Separation Example' }); }; diff --git a/examples/route-separation/user.js b/examples/route-separation/user.js index ef79b343a2..1c2aec7cd2 100644 --- a/examples/route-separation/user.js +++ b/examples/route-separation/user.js @@ -1,3 +1,5 @@ +'use strict' + // Fake user database var users = [ diff --git a/examples/search/index.js b/examples/search/index.js index 246993caa5..0d19444e52 100644 --- a/examples/search/index.js +++ b/examples/search/index.js @@ -1,3 +1,4 @@ +'use strict' // install redis first: // https://redis.io/ diff --git a/examples/search/public/client.js b/examples/search/public/client.js index 75c37d8e00..cd43faf71e 100644 --- a/examples/search/public/client.js +++ b/examples/search/public/client.js @@ -1,3 +1,5 @@ +'use strict' + var search = document.querySelector('[type=search]'); var code = document.querySelector('pre'); diff --git a/examples/session/index.js b/examples/session/index.js index 9bae48b8d3..2bb2b109c8 100644 --- a/examples/session/index.js +++ b/examples/session/index.js @@ -1,3 +1,4 @@ +'use strict' // install redis first: // https://redis.io/ diff --git a/examples/session/redis.js b/examples/session/redis.js index 1338d6e95e..bbbdc7fd3e 100644 --- a/examples/session/redis.js +++ b/examples/session/redis.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/static-files/index.js b/examples/static-files/index.js index 0e44313d15..609c546b47 100644 --- a/examples/static-files/index.js +++ b/examples/static-files/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/vhost/index.js b/examples/vhost/index.js index 4a0c17b850..a9499356b4 100644 --- a/examples/vhost/index.js +++ b/examples/vhost/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/view-constructor/github-view.js b/examples/view-constructor/github-view.js index 0a98a90843..43d29336ca 100644 --- a/examples/view-constructor/github-view.js +++ b/examples/view-constructor/github-view.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/view-constructor/index.js b/examples/view-constructor/index.js index 175a254e4e..3d673670e3 100644 --- a/examples/view-constructor/index.js +++ b/examples/view-constructor/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/view-locals/index.js b/examples/view-locals/index.js index cb41509606..bf52d2a85a 100644 --- a/examples/view-locals/index.js +++ b/examples/view-locals/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/view-locals/user.js b/examples/view-locals/user.js index 90ab1f389d..aaa6f85ff0 100644 --- a/examples/view-locals/user.js +++ b/examples/view-locals/user.js @@ -1,3 +1,5 @@ +'use strict' + module.exports = User; // faux model diff --git a/examples/web-service/index.js b/examples/web-service/index.js index 3685619d10..c22fea4032 100644 --- a/examples/web-service/index.js +++ b/examples/web-service/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ From 215f484fb4d8b71ae079f3d8a9d43e3470dacc5c Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 2 Feb 2022 01:42:35 -0500 Subject: [PATCH 006/158] tests: fix wording of req.accepts* test cases --- test/req.acceptsEncoding.js | 34 ++++++++++++----------- test/req.acceptsEncodings.js | 34 ++++++++++++----------- test/req.acceptsLanguage.js | 53 +++++++++++++++++++----------------- test/req.acceptsLanguages.js | 53 +++++++++++++++++++----------------- 4 files changed, 92 insertions(+), 82 deletions(-) diff --git a/test/req.acceptsEncoding.js b/test/req.acceptsEncoding.js index 9ed9197829..f2af68da22 100644 --- a/test/req.acceptsEncoding.js +++ b/test/req.acceptsEncoding.js @@ -4,33 +4,35 @@ var express = require('../') describe('req', function(){ describe('.acceptsEncoding', function(){ - it('should be true if encoding accepted', function(done){ + it('should return encoding if accepted', function (done) { var app = express(); - app.use(function(req, res){ - req.acceptsEncoding('gzip').should.be.ok() - req.acceptsEncoding('deflate').should.be.ok() - res.end(); - }); + app.get('/', function (req, res) { + res.send({ + gzip: req.acceptsEncoding('gzip'), + deflate: req.acceptsEncoding('deflate') + }) + }) request(app) - .get('/') - .set('Accept-Encoding', ' gzip, deflate') - .expect(200, done); + .get('/') + .set('Accept-Encoding', ' gzip, deflate') + .expect(200, { gzip: 'gzip', deflate: 'deflate' }, done) }) it('should be false if encoding not accepted', function(done){ var app = express(); - app.use(function(req, res){ - req.acceptsEncoding('bogus').should.not.be.ok() - res.end(); - }); + app.get('/', function (req, res) { + res.send({ + bogus: req.acceptsEncoding('bogus') + }) + }) request(app) - .get('/') - .set('Accept-Encoding', ' gzip, deflate') - .expect(200, done); + .get('/') + .set('Accept-Encoding', ' gzip, deflate') + .expect(200, { bogus: false }, done) }) }) }) diff --git a/test/req.acceptsEncodings.js b/test/req.acceptsEncodings.js index a5cf747d41..dc21c4edda 100644 --- a/test/req.acceptsEncodings.js +++ b/test/req.acceptsEncodings.js @@ -4,33 +4,35 @@ var express = require('../') describe('req', function(){ describe('.acceptsEncodings', function () { - it('should be true if encoding accepted', function(done){ + it('should return encoding if accepted', function (done) { var app = express(); - app.use(function(req, res){ - req.acceptsEncodings('gzip').should.be.ok() - req.acceptsEncodings('deflate').should.be.ok() - res.end(); - }); + app.get('/', function (req, res) { + res.send({ + gzip: req.acceptsEncoding('gzip'), + deflate: req.acceptsEncoding('deflate') + }) + }) request(app) - .get('/') - .set('Accept-Encoding', ' gzip, deflate') - .expect(200, done); + .get('/') + .set('Accept-Encoding', ' gzip, deflate') + .expect(200, { gzip: 'gzip', deflate: 'deflate' }, done) }) it('should be false if encoding not accepted', function(done){ var app = express(); - app.use(function(req, res){ - req.acceptsEncodings('bogus').should.not.be.ok() - res.end(); - }); + app.get('/', function (req, res) { + res.send({ + bogus: req.acceptsEncoding('bogus') + }) + }) request(app) - .get('/') - .set('Accept-Encoding', ' gzip, deflate') - .expect(200, done); + .get('/') + .set('Accept-Encoding', ' gzip, deflate') + .expect(200, { bogus: false }, done) }) }) }) diff --git a/test/req.acceptsLanguage.js b/test/req.acceptsLanguage.js index 1c7c5fd86f..616e723946 100644 --- a/test/req.acceptsLanguage.js +++ b/test/req.acceptsLanguage.js @@ -4,49 +4,52 @@ var express = require('../') describe('req', function(){ describe('.acceptsLanguage', function(){ - it('should be true if language accepted', function(done){ + it('should return language if accepted', function (done) { var app = express(); - app.use(function(req, res){ - req.acceptsLanguage('en-us').should.be.ok() - req.acceptsLanguage('en').should.be.ok() - res.end(); - }); + app.get('/', function (req, res) { + res.send({ + 'en-us': req.acceptsLanguages('en-us'), + en: req.acceptsLanguages('en') + }) + }) request(app) - .get('/') - .set('Accept-Language', 'en;q=.5, en-us') - .expect(200, done); + .get('/') + .set('Accept-Language', 'en;q=.5, en-us') + .expect(200, { 'en-us': 'en-us', en: 'en' }, done) }) it('should be false if language not accepted', function(done){ var app = express(); - app.use(function(req, res){ - req.acceptsLanguage('es').should.not.be.ok() - res.end(); - }); + app.get('/', function (req, res) { + res.send({ + es: req.acceptsLanguages('es') + }) + }) request(app) - .get('/') - .set('Accept-Language', 'en;q=.5, en-us') - .expect(200, done); + .get('/') + .set('Accept-Language', 'en;q=.5, en-us') + .expect(200, { es: false }, done) }) describe('when Accept-Language is not present', function(){ - it('should always return true', function(done){ + it('should always return language', function (done) { var app = express(); - app.use(function(req, res){ - req.acceptsLanguage('en').should.be.ok() - req.acceptsLanguage('es').should.be.ok() - req.acceptsLanguage('jp').should.be.ok() - res.end(); - }); + app.get('/', function (req, res) { + res.send({ + en: req.acceptsLanguages('en'), + es: req.acceptsLanguages('es'), + jp: req.acceptsLanguages('jp') + }) + }) request(app) - .get('/') - .expect(200, done); + .get('/') + .expect(200, { en: 'en', es: 'es', jp: 'jp' }, done) }) }) }) diff --git a/test/req.acceptsLanguages.js b/test/req.acceptsLanguages.js index 1d92f44b2b..87bf7b25df 100644 --- a/test/req.acceptsLanguages.js +++ b/test/req.acceptsLanguages.js @@ -4,49 +4,52 @@ var express = require('../') describe('req', function(){ describe('.acceptsLanguages', function(){ - it('should be true if language accepted', function(done){ + it('should return language if accepted', function (done) { var app = express(); - app.use(function(req, res){ - req.acceptsLanguages('en-us').should.be.ok() - req.acceptsLanguages('en').should.be.ok() - res.end(); - }); + app.get('/', function (req, res) { + res.send({ + 'en-us': req.acceptsLanguages('en-us'), + en: req.acceptsLanguages('en') + }) + }) request(app) - .get('/') - .set('Accept-Language', 'en;q=.5, en-us') - .expect(200, done); + .get('/') + .set('Accept-Language', 'en;q=.5, en-us') + .expect(200, { 'en-us': 'en-us', en: 'en' }, done) }) it('should be false if language not accepted', function(done){ var app = express(); - app.use(function(req, res){ - req.acceptsLanguages('es').should.not.be.ok() - res.end(); - }); + app.get('/', function (req, res) { + res.send({ + es: req.acceptsLanguages('es') + }) + }) request(app) - .get('/') - .set('Accept-Language', 'en;q=.5, en-us') - .expect(200, done); + .get('/') + .set('Accept-Language', 'en;q=.5, en-us') + .expect(200, { es: false }, done) }) describe('when Accept-Language is not present', function(){ - it('should always return true', function(done){ + it('should always return language', function (done) { var app = express(); - app.use(function(req, res){ - req.acceptsLanguages('en').should.be.ok() - req.acceptsLanguages('es').should.be.ok() - req.acceptsLanguages('jp').should.be.ok() - res.end(); - }); + app.get('/', function (req, res) { + res.send({ + en: req.acceptsLanguages('en'), + es: req.acceptsLanguages('es'), + jp: req.acceptsLanguages('jp') + }) + }) request(app) - .get('/') - .expect(200, done); + .get('/') + .expect(200, { en: 'en', es: 'es', jp: 'jp' }, done) }) }) }) From bd4fdfe5f771d07ef544c4a91bd6bfc4cc711f9b Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 2 Feb 2022 01:55:16 -0500 Subject: [PATCH 007/158] tests: remove global dependency on should fixes #4797 --- test/app.engine.js | 13 ++++---- test/app.js | 24 +++++++-------- test/app.locals.js | 14 +++++---- test/app.param.js | 30 +++++++++---------- test/app.render.js | 54 ++++++++++++++++----------------- test/app.router.js | 4 +-- test/app.routes.error.js | 14 +++++---- test/app.use.js | 8 ++--- test/req.query.js | 4 ++- test/req.route.js | 10 ++++--- test/req.xhr.js | 65 ++++++++++++++-------------------------- test/res.cookie.js | 28 ++++++----------- test/res.send.js | 2 +- test/utils.js | 37 ++++++++++++----------- 14 files changed, 142 insertions(+), 165 deletions(-) diff --git a/test/app.engine.js b/test/app.engine.js index b198292fa0..0d54c90d56 100644 --- a/test/app.engine.js +++ b/test/app.engine.js @@ -1,4 +1,5 @@ +var assert = require('assert') var express = require('../') , fs = require('fs'); var path = require('path') @@ -22,16 +23,16 @@ describe('app', function(){ app.render('user.html', function(err, str){ if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) it('should throw when the callback is missing', function(){ var app = express(); - (function(){ + assert.throws(function () { app.engine('.html', null); - }).should.throw('callback function required'); + }, /callback function required/) }) it('should work without leading "."', function(done){ @@ -43,7 +44,7 @@ describe('app', function(){ app.render('user.html', function(err, str){ if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) @@ -58,7 +59,7 @@ describe('app', function(){ app.render('user', function(err, str){ if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) @@ -73,7 +74,7 @@ describe('app', function(){ app.render('user', function(err, str){ if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) diff --git a/test/app.js b/test/app.js index e52365c36b..d0756795d3 100644 --- a/test/app.js +++ b/test/app.js @@ -32,8 +32,8 @@ describe('app.parent', function(){ blog.use('/admin', blogAdmin); assert(!app.parent, 'app.parent'); - blog.parent.should.equal(app); - blogAdmin.parent.should.equal(blog); + assert.strictEqual(blog.parent, app) + assert.strictEqual(blogAdmin.parent, blog) }) }) @@ -48,10 +48,10 @@ describe('app.mountpath', function(){ app.use(fallback); blog.use('/admin', admin); - admin.mountpath.should.equal('/admin'); - app.mountpath.should.equal('/'); - blog.mountpath.should.equal('/blog'); - fallback.mountpath.should.equal('/'); + assert.strictEqual(admin.mountpath, '/admin') + assert.strictEqual(app.mountpath, '/') + assert.strictEqual(blog.mountpath, '/blog') + assert.strictEqual(fallback.mountpath, '/') }) }) @@ -76,9 +76,9 @@ describe('app.path()', function(){ app.use('/blog', blog); blog.use('/admin', blogAdmin); - app.path().should.equal(''); - blog.path().should.equal('/blog'); - blogAdmin.path().should.equal('/blog/admin'); + assert.strictEqual(app.path(), '') + assert.strictEqual(blog.path(), '/blog') + assert.strictEqual(blogAdmin.path(), '/blog/admin') }) }) @@ -86,7 +86,7 @@ describe('in development', function(){ it('should disable "view cache"', function(){ process.env.NODE_ENV = 'development'; var app = express(); - app.enabled('view cache').should.be.false() + assert.ok(!app.enabled('view cache')) process.env.NODE_ENV = 'test'; }) }) @@ -95,7 +95,7 @@ describe('in production', function(){ it('should enable "view cache"', function(){ process.env.NODE_ENV = 'production'; var app = express(); - app.enabled('view cache').should.be.true() + assert.ok(app.enabled('view cache')) process.env.NODE_ENV = 'test'; }) }) @@ -104,7 +104,7 @@ describe('without NODE_ENV', function(){ it('should default to development', function(){ process.env.NODE_ENV = ''; var app = express(); - app.get('env').should.equal('development'); + assert.strictEqual(app.get('env'), 'development') process.env.NODE_ENV = 'test'; }) }) diff --git a/test/app.locals.js b/test/app.locals.js index d8bfb5a987..0b14ac9070 100644 --- a/test/app.locals.js +++ b/test/app.locals.js @@ -1,16 +1,18 @@ +var assert = require('assert') var express = require('../') +var should = require('should') describe('app', function(){ describe('.locals(obj)', function(){ it('should merge locals', function(){ var app = express(); - Object.keys(app.locals).should.eql(['settings']); + should(Object.keys(app.locals)).eql(['settings']) app.locals.user = 'tobi'; app.locals.age = 2; - Object.keys(app.locals).should.eql(['settings', 'user', 'age']); - app.locals.user.should.equal('tobi'); - app.locals.age.should.equal(2); + should(Object.keys(app.locals)).eql(['settings', 'user', 'age']) + assert.strictEqual(app.locals.user, 'tobi') + assert.strictEqual(app.locals.age, 2) }) }) @@ -19,8 +21,8 @@ describe('app', function(){ var app = express(); app.set('title', 'House of Manny'); var obj = app.locals.settings; - obj.should.have.property('env', 'test'); - obj.should.have.property('title', 'House of Manny'); + should(obj).have.property('env', 'test') + should(obj).have.property('title', 'House of Manny') }) }) }) diff --git a/test/app.param.js b/test/app.param.js index 577b00710b..7dbe3ffb61 100644 --- a/test/app.param.js +++ b/test/app.param.js @@ -1,4 +1,5 @@ +var assert = require('assert') var express = require('../') , request = require('supertest'); @@ -40,7 +41,7 @@ describe('app', function(){ it('should fail if not given fn', function(){ var app = express(); - app.param.bind(app, ':name', 'bob').should.throw(); + assert.throws(app.param.bind(app, ':name', 'bob')) }) }) @@ -57,24 +58,22 @@ describe('app', function(){ app.get('/post/:id', function(req, res){ var id = req.params.id; - id.should.be.a.Number() - res.send('' + id); + res.send((typeof id) + ':' + id) }); app.get('/user/:uid', function(req, res){ var id = req.params.id; - id.should.be.a.Number() - res.send('' + id); + res.send((typeof id) + ':' + id) }); request(app) - .get('/user/123') - .expect(200, '123', function (err) { - if (err) return done(err) - request(app) - .get('/post/123') - .expect('123', done); - }) + .get('/user/123') + .expect(200, 'number:123', function (err) { + if (err) return done(err) + request(app) + .get('/post/123') + .expect('number:123', done) + }) }) }) @@ -91,13 +90,12 @@ describe('app', function(){ app.get('/user/:id', function(req, res){ var id = req.params.id; - id.should.be.a.Number() - res.send('' + id); + res.send((typeof id) + ':' + id) }); request(app) - .get('/user/123') - .expect('123', done); + .get('/user/123') + .expect(200, 'number:123', done) }) it('should only call once per request', function(done) { diff --git a/test/app.render.js b/test/app.render.js index 54f6c2ca82..d0b367189b 100644 --- a/test/app.render.js +++ b/test/app.render.js @@ -13,7 +13,7 @@ describe('app', function(){ app.render(path.join(__dirname, 'fixtures', 'user.tmpl'), function (err, str) { if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) @@ -26,7 +26,7 @@ describe('app', function(){ app.render(path.join(__dirname, 'fixtures', 'user'), function (err, str) { if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) @@ -39,7 +39,7 @@ describe('app', function(){ app.render('user.tmpl', function (err, str) { if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) @@ -52,7 +52,7 @@ describe('app', function(){ app.render('blog/post', function (err, str) { if (err) return done(err); - str.should.equal('

blog post

'); + assert.strictEqual(str, '

blog post

') done(); }) }) @@ -72,8 +72,8 @@ describe('app', function(){ app.set('view', View); app.render('something', function(err, str){ - err.should.be.ok() - err.message.should.equal('err!'); + assert.ok(err) + assert.strictEqual(err.message, 'err!') done(); }) }) @@ -113,7 +113,7 @@ describe('app', function(){ app.render('email.tmpl', function (err, str) { if (err) return done(err); - str.should.equal('

This is an email

'); + assert.strictEqual(str, '

This is an email

') done(); }) }) @@ -128,7 +128,7 @@ describe('app', function(){ app.render('email', function(err, str){ if (err) return done(err); - str.should.equal('

This is an email

'); + assert.strictEqual(str, '

This is an email

') done(); }) }) @@ -143,7 +143,7 @@ describe('app', function(){ app.render('user.tmpl', function (err, str) { if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) @@ -161,7 +161,7 @@ describe('app', function(){ app.render('user.tmpl', function (err, str) { if (err) return done(err); - str.should.equal('tobi'); + assert.strictEqual(str, 'tobi') done(); }) }) @@ -178,7 +178,7 @@ describe('app', function(){ app.render('name.tmpl', function (err, str) { if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) @@ -219,7 +219,7 @@ describe('app', function(){ app.render('something', function(err, str){ if (err) return done(err); - str.should.equal('abstract engine'); + assert.strictEqual(str, 'abstract engine') done(); }) }) @@ -245,12 +245,12 @@ describe('app', function(){ app.render('something', function(err, str){ if (err) return done(err); - count.should.equal(1); - str.should.equal('abstract engine'); + assert.strictEqual(count, 1) + assert.strictEqual(str, 'abstract engine') app.render('something', function(err, str){ if (err) return done(err); - count.should.equal(2); - str.should.equal('abstract engine'); + assert.strictEqual(count, 2) + assert.strictEqual(str, 'abstract engine') done(); }) }) @@ -275,12 +275,12 @@ describe('app', function(){ app.render('something', function(err, str){ if (err) return done(err); - count.should.equal(1); - str.should.equal('abstract engine'); + assert.strictEqual(count, 1) + assert.strictEqual(str, 'abstract engine') app.render('something', function(err, str){ if (err) return done(err); - count.should.equal(1); - str.should.equal('abstract engine'); + assert.strictEqual(count, 1) + assert.strictEqual(str, 'abstract engine') done(); }) }) @@ -298,7 +298,7 @@ describe('app', function(){ app.render('user.tmpl', { user: user }, function (err, str) { if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) @@ -311,7 +311,7 @@ describe('app', function(){ app.render('user.tmpl', {}, function (err, str) { if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) @@ -325,7 +325,7 @@ describe('app', function(){ app.render('user.tmpl', { user: jane }, function (err, str) { if (err) return done(err); - str.should.equal('

jane

'); + assert.strictEqual(str, '

jane

') done(); }) }) @@ -350,12 +350,12 @@ describe('app', function(){ app.render('something', {cache: true}, function(err, str){ if (err) return done(err); - count.should.equal(1); - str.should.equal('abstract engine'); + assert.strictEqual(count, 1) + assert.strictEqual(str, 'abstract engine') app.render('something', {cache: true}, function(err, str){ if (err) return done(err); - count.should.equal(1); - str.should.equal('abstract engine'); + assert.strictEqual(count, 1) + assert.strictEqual(str, 'abstract engine') done(); }) }) diff --git a/test/app.router.js b/test/app.router.js index a4fe57cc2b..6edb93d6ea 100644 --- a/test/app.router.js +++ b/test/app.router.js @@ -51,7 +51,7 @@ describe('app.router', function(){ it('should reject numbers for app.' + method, function(){ var app = express(); - app[method].bind(app, '/', 3).should.throw(/Number/); + assert.throws(app[method].bind(app, '/', 3), /Number/) }) }); @@ -1102,6 +1102,6 @@ describe('app.router', function(){ it('should be chainable', function(){ var app = express(); - app.get('/', function(){}).should.equal(app); + assert.strictEqual(app.get('/', function () {}), app) }) }) diff --git a/test/app.routes.error.js b/test/app.routes.error.js index cbbc23ef57..b1f95d0d6e 100644 --- a/test/app.routes.error.js +++ b/test/app.routes.error.js @@ -1,3 +1,5 @@ + +var assert = require('assert') var express = require('../') , request = require('supertest'); @@ -34,20 +36,20 @@ describe('app', function(){ next(); }, function(err, req, res, next){ b = true; - err.message.should.equal('fabricated error'); + assert.strictEqual(err.message, 'fabricated error') next(err); }, function(err, req, res, next){ c = true; - err.message.should.equal('fabricated error'); + assert.strictEqual(err.message, 'fabricated error') next(); }, function(err, req, res, next){ d = true; next(); }, function(req, res){ - a.should.be.false() - b.should.be.true() - c.should.be.true() - d.should.be.false() + assert.ok(!a) + assert.ok(b) + assert.ok(c) + assert.ok(!d) res.send(204); }); diff --git a/test/app.use.js b/test/app.use.js index 347937fbb3..7987405a8b 100644 --- a/test/app.use.js +++ b/test/app.use.js @@ -10,7 +10,7 @@ describe('app', function(){ , app = express(); blog.on('mount', function(arg){ - arg.should.equal(app); + assert.strictEqual(arg, app) done(); }); @@ -63,7 +63,7 @@ describe('app', function(){ , app = express(); app.use('/blog', blog); - blog.parent.should.equal(app); + assert.strictEqual(blog.parent, app) }) it('should support dynamic routes', function(done){ @@ -102,11 +102,11 @@ describe('app', function(){ }); blog.once('mount', function (parent) { - parent.should.equal(app); + assert.strictEqual(parent, app) cb(); }); other.once('mount', function (parent) { - parent.should.equal(app); + assert.strictEqual(parent, app) cb(); }); diff --git a/test/req.query.js b/test/req.query.js index 0e810b8ef9..f3e8df8a18 100644 --- a/test/req.query.js +++ b/test/req.query.js @@ -1,4 +1,5 @@ +var assert = require('assert') var express = require('../') , request = require('supertest'); @@ -99,7 +100,8 @@ describe('req', function(){ describe('when "query parser" an unknown value', function () { it('should throw', function () { - createApp.bind(null, 'bogus').should.throw(/unknown value.*query parser/); + assert.throws(createApp.bind(null, 'bogus'), + /unknown value.*query parser/) }); }); }) diff --git a/test/req.route.js b/test/req.route.js index 2947b7c3d0..b32d470bd6 100644 --- a/test/req.route.js +++ b/test/req.route.js @@ -8,18 +8,20 @@ describe('req', function(){ var app = express(); app.get('/user/:id/:op?', function(req, res, next){ - req.route.path.should.equal('/user/:id/:op?'); + res.header('path-1', req.route.path) next(); }); app.get('/user/:id/edit', function(req, res){ - req.route.path.should.equal('/user/:id/edit'); + res.header('path-2', req.route.path) res.end(); }); request(app) - .get('/user/12/edit') - .expect(200, done); + .get('/user/12/edit') + .expect('path-1', '/user/:id/:op?') + .expect('path-2', '/user/:id/edit') + .expect(200, done) }) }) }) diff --git a/test/req.xhr.js b/test/req.xhr.js index 94af9170cb..3ad1c6fb72 100644 --- a/test/req.xhr.js +++ b/test/req.xhr.js @@ -4,59 +4,38 @@ var express = require('../') describe('req', function(){ describe('.xhr', function(){ - it('should return true when X-Requested-With is xmlhttprequest', function(done){ - var app = express(); - - app.use(function(req, res){ - req.xhr.should.be.true() - res.end(); - }); + before(function () { + this.app = express() + this.app.get('/', function (req, res) { + res.send(req.xhr) + }) + }) - request(app) - .get('/') - .set('X-Requested-With', 'xmlhttprequest') - .expect(200, done) + it('should return true when X-Requested-With is xmlhttprequest', function(done){ + request(this.app) + .get('/') + .set('X-Requested-With', 'xmlhttprequest') + .expect(200, 'true', done) }) it('should case-insensitive', function(done){ - var app = express(); - - app.use(function(req, res){ - req.xhr.should.be.true() - res.end(); - }); - - request(app) - .get('/') - .set('X-Requested-With', 'XMLHttpRequest') - .expect(200, done) + request(this.app) + .get('/') + .set('X-Requested-With', 'XMLHttpRequest') + .expect(200, 'true', done) }) it('should return false otherwise', function(done){ - var app = express(); - - app.use(function(req, res){ - req.xhr.should.be.false() - res.end(); - }); - - request(app) - .get('/') - .set('X-Requested-With', 'blahblah') - .expect(200, done) + request(this.app) + .get('/') + .set('X-Requested-With', 'blahblah') + .expect(200, 'false', done) }) it('should return false when not present', function(done){ - var app = express(); - - app.use(function(req, res){ - req.xhr.should.be.false() - res.end(); - }); - - request(app) - .get('/') - .expect(200, done) + request(this.app) + .get('/') + .expect(200, 'false', done) }) }) }) diff --git a/test/res.cookie.js b/test/res.cookie.js index d8e6b7ca85..8f8662c217 100644 --- a/test/res.cookie.js +++ b/test/res.cookie.js @@ -1,7 +1,6 @@ var express = require('../') , request = require('supertest') - , cookie = require('cookie') , cookieParser = require('cookie-parser') var merge = require('utils-merge'); @@ -46,12 +45,9 @@ describe('res', function(){ }); request(app) - .get('/') - .end(function(err, res){ - var val = ['name=tobi; Path=/', 'age=1; Path=/', 'gender=%3F; Path=/']; - res.headers['set-cookie'].should.eql(val); - done(); - }) + .get('/') + .expect('Set-Cookie', 'name=tobi; Path=/,age=1; Path=/,gender=%3F; Path=/') + .expect(200, done) }) }) @@ -80,11 +76,9 @@ describe('res', function(){ }); request(app) - .get('/') - .end(function(err, res){ - res.headers['set-cookie'][0].should.not.containEql('Thu, 01 Jan 1970 00:00:01 GMT'); - done(); - }) + .get('/') + .expect('Set-Cookie', /name=tobi; Max-Age=1; Path=\/; Expires=/) + .expect(200, done) }) it('should set max-age', function(done){ @@ -141,13 +135,9 @@ describe('res', function(){ }); request(app) - .get('/') - .end(function(err, res){ - var val = res.headers['set-cookie'][0]; - val = cookie.parse(val.split('.')[0]); - val.user.should.equal('s:j:{"name":"tobi"}'); - done(); - }) + .get('/') + .expect('Set-Cookie', 'user=s%3Aj%3A%7B%22name%22%3A%22tobi%22%7D.K20xcwmDS%2BPb1rsD95o5Jm5SqWs1KteqdnynnB7jkTE; Path=/') + .expect(200, done) }) }) diff --git a/test/res.send.js b/test/res.send.js index b836b5e4dc..e62caf95dc 100644 --- a/test/res.send.js +++ b/test/res.send.js @@ -544,7 +544,7 @@ describe('res', function(){ var chunk = !Buffer.isBuffer(body) ? Buffer.from(body, encoding) : body; - chunk.toString().should.equal('hello, world!'); + assert.strictEqual(chunk.toString(), 'hello, world!') return '"custom"'; }); diff --git a/test/utils.js b/test/utils.js index b51d223af9..a0fac7a722 100644 --- a/test/utils.js +++ b/test/utils.js @@ -1,27 +1,28 @@ var assert = require('assert'); var Buffer = require('safe-buffer').Buffer +var should = require('should') var utils = require('../lib/utils'); describe('utils.etag(body, encoding)', function(){ it('should support strings', function(){ - utils.etag('express!') - .should.eql('"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"') + assert.strictEqual(utils.etag('express!'), + '"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"') }) it('should support utf8 strings', function(){ - utils.etag('express❤', 'utf8') - .should.eql('"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"') + assert.strictEqual(utils.etag('express❤', 'utf8'), + '"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"') }) it('should support buffer', function(){ - utils.etag(Buffer.from('express!')) - .should.eql('"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"') + assert.strictEqual(utils.etag(Buffer.from('express!')), + '"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"') }) it('should support empty string', function(){ - utils.etag('') - .should.eql('"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"') + assert.strictEqual(utils.etag(''), + '"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"') }) }) @@ -49,23 +50,23 @@ describe('utils.setCharset(type, charset)', function () { describe('utils.wetag(body, encoding)', function(){ it('should support strings', function(){ - utils.wetag('express!') - .should.eql('W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"') + assert.strictEqual(utils.wetag('express!'), + 'W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"') }) it('should support utf8 strings', function(){ - utils.wetag('express❤', 'utf8') - .should.eql('W/"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"') + assert.strictEqual(utils.wetag('express❤', 'utf8'), + 'W/"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"') }) it('should support buffer', function(){ - utils.wetag(Buffer.from('express!')) - .should.eql('W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"') + assert.strictEqual(utils.wetag(Buffer.from('express!')), + 'W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"') }) it('should support empty string', function(){ - utils.wetag('') - .should.eql('W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"') + assert.strictEqual(utils.wetag(''), + 'W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"') }) }) @@ -89,7 +90,7 @@ describe('utils.isAbsolute()', function(){ describe('utils.flatten(arr)', function(){ it('should flatten an array', function(){ var arr = ['one', ['two', ['three', 'four'], 'five']]; - utils.flatten(arr) - .should.eql(['one', 'two', 'three', 'four', 'five']); + should(utils.flatten(arr)) + .eql(['one', 'two', 'three', 'four', 'five']) }) }) From 141914e8172f5d1a08825fc60a54d944121b1ec0 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 2 Feb 2022 14:16:20 -0500 Subject: [PATCH 008/158] tests: fix tests that did not bubble errors --- test/app.all.js | 12 +++++++----- test/app.head.js | 15 ++++++--------- test/app.router.js | 33 ++++++++++++++++++--------------- test/app.use.js | 11 ++++++----- 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/test/app.all.js b/test/app.all.js index e9ef08831d..45c3ddb93b 100644 --- a/test/app.all.js +++ b/test/app.all.js @@ -1,22 +1,24 @@ +var after = require('after') var express = require('../') , request = require('supertest'); describe('app.all()', function(){ it('should add a router per method', function(done){ var app = express(); + var cb = after(2, done) app.all('/tobi', function(req, res){ res.end(req.method); }); request(app) - .put('/tobi') - .expect('PUT', function(){ - request(app) + .put('/tobi') + .expect(200, 'PUT', cb) + + request(app) .get('/tobi') - .expect('GET', done); - }); + .expect(200, 'GET', cb) }) it('should run the callback for a method just once', function(done){ diff --git a/test/app.head.js b/test/app.head.js index b417ca0c92..6aa1bb8003 100644 --- a/test/app.head.js +++ b/test/app.head.js @@ -46,23 +46,20 @@ describe('HEAD', function(){ describe('app.head()', function(){ it('should override', function(done){ var app = express() - , called; app.head('/tobi', function(req, res){ - called = true; - res.end(''); + res.header('x-method', 'head') + res.end() }); app.get('/tobi', function(req, res){ - assert(0, 'should not call GET'); + res.header('x-method', 'get') res.send('tobi'); }); request(app) - .head('/tobi') - .expect(200, function(){ - assert(called); - done(); - }); + .head('/tobi') + .expect('x-method', 'head') + .expect(200, done) }) }) diff --git a/test/app.router.js b/test/app.router.js index 6edb93d6ea..8c98aa869b 100644 --- a/test/app.router.js +++ b/test/app.router.js @@ -636,18 +636,19 @@ describe('app.router', function(){ it('should work cross-segment', function(done){ var app = express(); + var cb = after(2, done) app.get('/api*', function(req, res){ res.send(req.params[0]); }); request(app) - .get('/api') - .expect('', function(){ - request(app) + .get('/api') + .expect(200, '', cb) + + request(app) .get('/api/hey') - .expect('/hey', done); - }); + .expect(200, '/hey', cb) }) it('should allow naming', function(done){ @@ -863,36 +864,38 @@ describe('app.router', function(){ describe('.:name', function(){ it('should denote a format', function(done){ var app = express(); + var cb = after(2, done) app.get('/:name.:format', function(req, res){ res.end(req.params.name + ' as ' + req.params.format); }); request(app) - .get('/foo.json') - .expect('foo as json', function(){ - request(app) + .get('/foo.json') + .expect(200, 'foo as json', cb) + + request(app) .get('/foo') - .expect(404, done); - }); + .expect(404, cb) }) }) describe('.:name?', function(){ it('should denote an optional format', function(done){ var app = express(); + var cb = after(2, done) app.get('/:name.:format?', function(req, res){ res.end(req.params.name + ' as ' + (req.params.format || 'html')); }); request(app) - .get('/foo') - .expect('foo as html', function(){ - request(app) + .get('/foo') + .expect(200, 'foo as html', cb) + + request(app) .get('/foo.json') - .expect('foo as json', done); - }); + .expect(200, 'foo as json', done) }) }) diff --git a/test/app.use.js b/test/app.use.js index 7987405a8b..55ba0689c8 100644 --- a/test/app.use.js +++ b/test/app.use.js @@ -37,6 +37,7 @@ describe('app', function(){ var blog = express() , forum = express() , app = express(); + var cb = after(2, done) blog.get('/', function(req, res){ res.end('blog'); @@ -50,12 +51,12 @@ describe('app', function(){ app.use('/forum', forum); request(app) - .get('/blog') - .expect('blog', function(){ - request(app) + .get('/blog') + .expect(200, 'blog', cb) + + request(app) .get('/forum') - .expect('forum', done); - }); + .expect(200, 'forum', done) }) it('should set the child\'s .parent', function(){ From 00ad5bee96bade1b776be62c7f1912eefc41793d Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 2 Feb 2022 15:02:46 -0500 Subject: [PATCH 009/158] tests: add more tests for app.request & app.response --- test/app.request.js | 119 ++++++++++++++++++++++++++++++++++++++++ test/app.response.js | 128 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 232 insertions(+), 15 deletions(-) diff --git a/test/app.request.js b/test/app.request.js index 728043a5a3..0288f80b09 100644 --- a/test/app.request.js +++ b/test/app.request.js @@ -1,4 +1,5 @@ +var after = require('after') var express = require('../') , request = require('supertest'); @@ -19,5 +20,123 @@ describe('app', function(){ .get('/foo?name=tobi') .expect('name=tobi', done); }) + + it('should only extend for the referenced app', function (done) { + var app1 = express() + var app2 = express() + var cb = after(2, done) + + app1.request.foobar = function () { + return 'tobi' + } + + app1.get('/', function (req, res) { + res.send(req.foobar()) + }) + + app2.get('/', function (req, res) { + res.send(req.foobar()) + }) + + request(app1) + .get('/') + .expect(200, 'tobi', cb) + + request(app2) + .get('/') + .expect(500, /(?:not a function|has no method)/, cb) + }) + + it('should inherit to sub apps', function (done) { + var app1 = express() + var app2 = express() + var cb = after(2, done) + + app1.request.foobar = function () { + return 'tobi' + } + + app1.use('/sub', app2) + + app1.get('/', function (req, res) { + res.send(req.foobar()) + }) + + app2.get('/', function (req, res) { + res.send(req.foobar()) + }) + + request(app1) + .get('/') + .expect(200, 'tobi', cb) + + request(app1) + .get('/sub') + .expect(200, 'tobi', cb) + }) + + it('should allow sub app to override', function (done) { + var app1 = express() + var app2 = express() + var cb = after(2, done) + + app1.request.foobar = function () { + return 'tobi' + } + + app2.request.foobar = function () { + return 'loki' + } + + app1.use('/sub', app2) + + app1.get('/', function (req, res) { + res.send(req.foobar()) + }) + + app2.get('/', function (req, res) { + res.send(req.foobar()) + }) + + request(app1) + .get('/') + .expect(200, 'tobi', cb) + + request(app1) + .get('/sub') + .expect(200, 'loki', cb) + }) + + it('should not pollute parent app', function (done) { + var app1 = express() + var app2 = express() + var cb = after(2, done) + + app1.request.foobar = function () { + return 'tobi' + } + + app2.request.foobar = function () { + return 'loki' + } + + app1.use('/sub', app2) + + app1.get('/sub/foo', function (req, res) { + res.send(req.foobar()) + }) + + app2.get('/', function (req, res) { + res.send(req.foobar()) + }) + + request(app1) + .get('/sub') + .expect(200, 'loki', cb) + + request(app1) + .get('/sub/foo') + .expect(200, 'tobi', cb) + }) }) }) diff --git a/test/app.response.js b/test/app.response.js index c6ea77c820..ea696b566f 100644 --- a/test/app.response.js +++ b/test/app.response.js @@ -1,4 +1,5 @@ +var after = require('after') var express = require('../') , request = require('supertest'); @@ -20,25 +21,122 @@ describe('app', function(){ .expect('HEY', done); }) - it('should not be influenced by other app protos', function(done){ - var app = express() - , app2 = express(); + it('should only extend for the referenced app', function (done) { + var app1 = express() + var app2 = express() + var cb = after(2, done) - app.response.shout = function(str){ - this.send(str.toUpperCase()); - }; + app1.response.shout = function (str) { + this.send(str.toUpperCase()) + } - app2.response.shout = function(str){ - this.send(str); - }; + app1.get('/', function (req, res) { + res.shout('foo') + }) - app.use(function(req, res){ - res.shout('hey'); - }); + app2.get('/', function (req, res) { + res.shout('foo') + }) - request(app) - .get('/') - .expect('HEY', done); + request(app1) + .get('/') + .expect(200, 'FOO', cb) + + request(app2) + .get('/') + .expect(500, /(?:not a function|has no method)/, cb) + }) + + it('should inherit to sub apps', function (done) { + var app1 = express() + var app2 = express() + var cb = after(2, done) + + app1.response.shout = function (str) { + this.send(str.toUpperCase()) + } + + app1.use('/sub', app2) + + app1.get('/', function (req, res) { + res.shout('foo') + }) + + app2.get('/', function (req, res) { + res.shout('foo') + }) + + request(app1) + .get('/') + .expect(200, 'FOO', cb) + + request(app1) + .get('/sub') + .expect(200, 'FOO', cb) + }) + + it('should allow sub app to override', function (done) { + var app1 = express() + var app2 = express() + var cb = after(2, done) + + app1.response.shout = function (str) { + this.send(str.toUpperCase()) + } + + app2.response.shout = function (str) { + this.send(str + '!') + } + + app1.use('/sub', app2) + + app1.get('/', function (req, res) { + res.shout('foo') + }) + + app2.get('/', function (req, res) { + res.shout('foo') + }) + + request(app1) + .get('/') + .expect(200, 'FOO', cb) + + request(app1) + .get('/sub') + .expect(200, 'foo!', cb) + }) + + it('should not pollute parent app', function (done) { + var app1 = express() + var app2 = express() + var cb = after(2, done) + + app1.response.shout = function (str) { + this.send(str.toUpperCase()) + } + + app2.response.shout = function (str) { + this.send(str + '!') + } + + app1.use('/sub', app2) + + app1.get('/sub/foo', function (req, res) { + res.shout('foo') + }) + + app2.get('/', function (req, res) { + res.shout('foo') + }) + + request(app1) + .get('/sub') + .expect(200, 'foo!', cb) + + request(app1) + .get('/sub/foo') + .expect(200, 'FOO', cb) }) }) }) From da6cb0ed8a4c9a5048cf391a32f9fab1960d9284 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 2 Feb 2022 15:15:41 -0500 Subject: [PATCH 010/158] tests: add range tests to res.download --- test/res.download.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/res.download.js b/test/res.download.js index cf3b3ca53e..658d80af4f 100644 --- a/test/res.download.js +++ b/test/res.download.js @@ -20,6 +20,33 @@ describe('res', function(){ .expect('Content-Disposition', 'attachment; filename="user.html"') .expect(200, '

{{user.name}}

', done) }) + + it('should accept range requests', function (done) { + var app = express() + + app.get('/', function (req, res) { + res.download('test/fixtures/user.html') + }) + + request(app) + .get('/') + .expect('Accept-Ranges', 'bytes') + .expect(200, '

{{user.name}}

', done) + }) + + it('should respond with requested byte range', function (done) { + var app = express() + + app.get('/', function (req, res) { + res.download('test/fixtures/user.html') + }) + + request(app) + .get('/') + .set('Range', 'bytes=0-2') + .expect('Content-Range', 'bytes 0-2/20') + .expect(206, '

', done) + }) }) describe('.download(path, filename)', function(){ From 744564fcf806311fdc88fb1d8b4097560d514ad7 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 2 Feb 2022 16:19:01 -0500 Subject: [PATCH 011/158] tests: add test for multiple ips in "trust proxy" --- test/req.ip.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test/req.ip.js b/test/req.ip.js index 1cd255216b..23623cfce6 100644 --- a/test/req.ip.js +++ b/test/req.ip.js @@ -21,7 +21,7 @@ describe('req', function(){ .expect('client', done); }) - it('should return the addr after trusted proxy', function(done){ + it('should return the addr after trusted proxy based on count', function (done) { var app = express(); app.set('trust proxy', 2); @@ -36,6 +36,21 @@ describe('req', function(){ .expect('p1', done); }) + it('should return the addr after trusted proxy based on list', function (done) { + var app = express() + + app.set('trust proxy', '10.0.0.1, 10.0.0.2, 127.0.0.1, ::1') + + app.get('/', function (req, res) { + res.send(req.ip) + }) + + request(app) + .get('/') + .set('X-Forwarded-For', '10.0.0.2, 10.0.0.3, 10.0.0.1', '10.0.0.4') + .expect('10.0.0.3', done) + }) + it('should return the addr after trusted proxy, from sub app', function (done) { var app = express(); var sub = express(); From 89bb531b311e2670a12dc020d69adb91327aa7e0 Mon Sep 17 00:00:00 2001 From: caioagiani Date: Thu, 3 Feb 2022 23:54:57 -0300 Subject: [PATCH 012/158] docs: fix typo in res.download jsdoc closes #4805 --- lib/response.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/response.js b/lib/response.js index 48239a475a..ba02008522 100644 --- a/lib/response.js +++ b/lib/response.js @@ -524,7 +524,7 @@ res.sendfile = deprecate.function(res.sendfile, * Optionally providing an alternate attachment `filename`, * and optional callback `callback(err)`. The callback is invoked * when the data transfer is complete, or when an error has - * ocurred. Be sure to check `res.headersSent` if you plan to respond. + * occurred. Be sure to check `res.headersSent` if you plan to respond. * * Optionally providing an `options` object to use with `res.sendFile()`. * This function will set the `Content-Disposition` header, overriding From 2bc734aa3f76db2984368134736e1ddf2d325e6a Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 4 Feb 2022 16:21:11 -0500 Subject: [PATCH 013/158] deps: accepts@~1.3.8 --- History.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/History.md b/History.md index 41cacce786..57df902afe 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,10 @@ +unreleased +========== + + * deps: accepts@~1.3.8 + - deps: mime-types@~2.1.34 + - deps: negotiator@0.6.3 + 4.17.2 / 2021-12-16 =================== diff --git a/package.json b/package.json index ebb7425d9a..dc86d680cc 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "api" ], "dependencies": { - "accepts": "~1.3.7", + "accepts": "~1.3.8", "array-flatten": "1.1.1", "body-parser": "1.19.1", "content-disposition": "0.5.4", From 6fbc269563c53297d29b69b89fd71b74c1dbd6ce Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 4 Feb 2022 16:34:56 -0500 Subject: [PATCH 014/158] pref: remove unnecessary regexp for trust proxy --- History.md | 1 + lib/utils.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/History.md b/History.md index 57df902afe..493ea189ff 100644 --- a/History.md +++ b/History.md @@ -4,6 +4,7 @@ unreleased * deps: accepts@~1.3.8 - deps: mime-types@~2.1.34 - deps: negotiator@0.6.3 + * pref: remove unnecessary regexp for trust proxy 4.17.2 / 2021-12-16 =================== diff --git a/lib/utils.js b/lib/utils.js index a9ef259ff1..7797b06853 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -228,7 +228,8 @@ exports.compileTrust = function(val) { if (typeof val === 'string') { // Support comma-separated values - val = val.split(/ *, */); + val = val.split(',') + .map(function (v) { return v.trim() }) } return proxyaddr.compile(val || []); From 9cbbc8ae74c63ec79b04971923493533066bf4d2 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 4 Feb 2022 16:35:50 -0500 Subject: [PATCH 015/158] deps: cookie@0.4.2 --- History.md | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/History.md b/History.md index 493ea189ff..140756cd03 100644 --- a/History.md +++ b/History.md @@ -4,6 +4,7 @@ unreleased * deps: accepts@~1.3.8 - deps: mime-types@~2.1.34 - deps: negotiator@0.6.3 + * deps: cookie@0.4.2 * pref: remove unnecessary regexp for trust proxy 4.17.2 / 2021-12-16 diff --git a/package.json b/package.json index dc86d680cc..bc24d1a4f4 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "body-parser": "1.19.1", "content-disposition": "0.5.4", "content-type": "~1.0.4", - "cookie": "0.4.1", + "cookie": "0.4.2", "cookie-signature": "1.0.6", "debug": "2.6.9", "depd": "~1.1.2", From 1c7bbcc143296576e12ffe0fb9a35d43ede43ae7 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 4 Feb 2022 16:36:47 -0500 Subject: [PATCH 016/158] build: Node.js@14.19 --- .github/workflows/ci.yml | 2 +- appveyor.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e2a4945645..98314e57f8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -88,7 +88,7 @@ jobs: node-version: "13.14" - name: Node.js 14.x - node-version: "14.18" + node-version: "14.19" steps: - uses: actions/checkout@v2 diff --git a/appveyor.yml b/appveyor.yml index 785c799e8f..01e357f104 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -15,7 +15,7 @@ environment: - nodejs_version: "11.15" - nodejs_version: "12.22" - nodejs_version: "13.14" - - nodejs_version: "14.18" + - nodejs_version: "14.19" cache: - node_modules install: From 43cc56eb9e529774535a992422ee90b5c9e15ff9 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 4 Feb 2022 16:48:33 -0500 Subject: [PATCH 017/158] build: clean up gitignore --- .gitignore | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 5fee6a2dc9..a1e980205f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,27 +1,14 @@ -# OS X -.DS_Store* -Icon? -._* - -# Windows -Thumbs.db -ehthumbs.db -Desktop.ini - -# Linux -.directory -*~ - - # npm node_modules package-lock.json *.log *.gz - # Coveralls coverage # Benchmarking benchmarks/graphs + +# ignore additional files using core.excludesFile +# https://git-scm.com/docs/gitignore From 9d0976229d48c22e8f47dee6349bc4531035657f Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 4 Feb 2022 21:14:41 -0500 Subject: [PATCH 018/158] build: supertest@6.2.2 --- .github/workflows/ci.yml | 4 +-- appveyor.yml | 3 ++ package.json | 2 +- test/res.sendFile.js | 76 ++++++++++++++++++++++++---------------- 4 files changed, 52 insertions(+), 33 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 98314e57f8..c6eba737f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,11 +59,11 @@ jobs: - name: Node.js 6.x node-version: "6.17" - npm-i: mocha@6.2.2 + npm-i: mocha@6.2.2 supertest@6.1.6 - name: Node.js 7.x node-version: "7.10" - npm-i: mocha@6.2.2 + npm-i: mocha@6.2.2 supertest@6.1.6 - name: Node.js 8.x node-version: "8.17" diff --git a/appveyor.yml b/appveyor.yml index 01e357f104..ca108e24fb 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -58,10 +58,13 @@ install: # supertest for http calls # - use 2.0.0 for Node.js < 4 # - use 3.4.2 for Node.js < 6 + # - use 6.1.6 for Node.js < 8 if ([int]$env:nodejs_version.split(".")[0] -lt 4) { npm install --silent --save-dev supertest@2.0.0 } elseif ([int]$env:nodejs_version.split(".")[0] -lt 6) { npm install --silent --save-dev supertest@3.4.2 + } elseif ([int]$env:nodejs_version.split(".")[0] -lt 8) { + npm install --silent --save-dev supertest@6.1.6 } # Update Node.js modules - ps: | diff --git a/package.json b/package.json index bc24d1a4f4..b3eedce29c 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "multiparty": "4.2.2", "pbkdf2-password": "1.2.1", "should": "13.2.3", - "supertest": "6.1.6", + "supertest": "6.2.2", "vhost": "~3.0.2" }, "engines": { diff --git a/test/res.sendFile.js b/test/res.sendFile.js index 5f494f1e0b..183faceb1d 100644 --- a/test/res.sendFile.js +++ b/test/res.sendFile.js @@ -112,12 +112,11 @@ describe('res', function(){ app.use(function (req, res) { setImmediate(function () { res.sendFile(path.resolve(fixtures, 'name.txt')); - server.close(cb) setTimeout(function () { cb(error) }, 10) }) - test.abort(); + test.req.abort() }); app.use(function (err, req, res, next) { @@ -127,7 +126,10 @@ describe('res', function(){ var server = app.listen() var test = request(server).get('/') - test.end() + test.end(function (err) { + assert.ok(err) + server.close(cb) + }) }) describe('with "cacheControl" option', function () { @@ -272,43 +274,49 @@ describe('res', function(){ }) it('should invoke the callback when client aborts', function (done) { - var cb = after(1, done); + var cb = after(2, done) var app = express(); app.use(function (req, res) { setImmediate(function () { res.sendFile(path.resolve(fixtures, 'name.txt'), function (err) { - should(err).be.ok() - err.code.should.equal('ECONNABORTED'); - server.close(cb) + assert.ok(err) + assert.strictEqual(err.code, 'ECONNABORTED') + cb() }); }); - test.abort(); + test.req.abort() }); var server = app.listen() var test = request(server).get('/') - test.expect(200, cb); + test.end(function (err) { + assert.ok(err) + server.close(cb) + }) }) it('should invoke the callback when client already aborted', function (done) { - var cb = after(1, done); + var cb = after(2, done) var app = express(); app.use(function (req, res) { onFinished(res, function () { res.sendFile(path.resolve(fixtures, 'name.txt'), function (err) { - should(err).be.ok() - err.code.should.equal('ECONNABORTED'); - server.close(cb) + assert.ok(err) + assert.strictEqual(err.code, 'ECONNABORTED') + cb() }); }); - test.abort(); + test.req.abort() }); var server = app.listen() var test = request(server).get('/') - test.expect(200, cb); + test.end(function (err) { + assert.ok(err) + server.close(cb) + }) }) it('should invoke the callback without error when HEAD', function (done) { @@ -398,43 +406,49 @@ describe('res', function(){ }) it('should invoke the callback when client aborts', function (done) { - var cb = after(1, done); + var cb = after(2, done) var app = express(); app.use(function (req, res) { setImmediate(function () { res.sendfile('test/fixtures/name.txt', function (err) { - should(err).be.ok() - err.code.should.equal('ECONNABORTED'); - server.close(cb) + assert.ok(err) + assert.strictEqual(err.code, 'ECONNABORTED') + cb() }); }); - test.abort(); + test.req.abort() }); var server = app.listen() var test = request(server).get('/') - test.expect(200, cb); + test.end(function (err) { + assert.ok(err) + server.close(cb) + }) }) it('should invoke the callback when client already aborted', function (done) { - var cb = after(1, done); + var cb = after(2, done) var app = express(); app.use(function (req, res) { onFinished(res, function () { res.sendfile('test/fixtures/name.txt', function (err) { - should(err).be.ok() - err.code.should.equal('ECONNABORTED'); - server.close(cb) + assert.ok(err) + assert.strictEqual(err.code, 'ECONNABORTED') + cb() }); }); - test.abort(); + test.req.abort() }); var server = app.listen() var test = request(server).get('/') - test.expect(200, cb); + test.end(function (err) { + assert.ok(err) + server.close(cb) + }) }) it('should invoke the callback without error when HEAD', function (done) { @@ -652,12 +666,11 @@ describe('res', function(){ app.use(function (req, res) { setImmediate(function () { res.sendfile(path.resolve(fixtures, 'name.txt')); - server.close(cb) setTimeout(function () { cb(error) }, 10) }); - test.abort(); + test.req.abort() }); app.use(function (err, req, res, next) { @@ -667,7 +680,10 @@ describe('res', function(){ var server = app.listen() var test = request(server).get('/') - test.end() + test.end(function (err) { + assert.ok(err) + server.close(cb) + }) }) describe('with an absolute path', function(){ From 2585f209f98f91da68739bdb33b599df45b3a6e6 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 4 Feb 2022 21:18:47 -0500 Subject: [PATCH 019/158] tests: fix test missing assertion --- test/res.download.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/res.download.js b/test/res.download.js index 658d80af4f..579f8c67a9 100644 --- a/test/res.download.js +++ b/test/res.download.js @@ -88,7 +88,7 @@ describe('res', function(){ var cb = after(2, done); app.use(function(req, res){ - res.download('test/fixtures/user.html', 'document', done); + res.download('test/fixtures/user.html', 'document', cb) }); request(app) From 7511d083283529f865ade6fedac08716f0efde05 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 7 Feb 2022 17:46:47 -0500 Subject: [PATCH 020/158] build: use minimatch@3.0.4 for Node.js < 4 --- .github/workflows/ci.yml | 10 +++++----- appveyor.yml | 5 +++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c6eba737f9..416ece0959 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,23 +31,23 @@ jobs: include: - name: Node.js 0.10 node-version: "0.10" - npm-i: mocha@3.5.3 supertest@2.0.0 + npm-i: minimatch@3.0.4 mocha@3.5.3 supertest@2.0.0 - name: Node.js 0.12 node-version: "0.12" - npm-i: mocha@3.5.3 supertest@2.0.0 + npm-i: minimatch@3.0.4 mocha@3.5.3 supertest@2.0.0 - name: io.js 1.x node-version: "1.8" - npm-i: mocha@3.5.3 supertest@2.0.0 + npm-i: minimatch@3.0.4 mocha@3.5.3 supertest@2.0.0 - name: io.js 2.x node-version: "2.5" - npm-i: mocha@3.5.3 supertest@2.0.0 + npm-i: minimatch@3.0.4 mocha@3.5.3 supertest@2.0.0 - name: io.js 3.x node-version: "3.3" - npm-i: mocha@3.5.3 supertest@2.0.0 + npm-i: minimatch@3.0.4 mocha@3.5.3 supertest@2.0.0 - name: Node.js 4.x node-version: "4.9" diff --git a/appveyor.yml b/appveyor.yml index ca108e24fb..c1b51ca7cd 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -36,6 +36,11 @@ install: sls "^eslint(-|$)" | ` %{ npm rm --silent --save-dev $_ } # Setup Node.js version-specific dependencies + - ps: | + # minimatch for Node.js < 4 + if ([int]$env:nodejs_version.split(".")[0] -lt 4) { + npm install --silent --save-dev minimatch@3.0.4 + } - ps: | # mocha for testing # - use 3.x for Node.js < 4 From 884657d54665f323c236055d6e3d3e85d96e5f08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Strau=C3=9F?= <49093997+thst71@users.noreply.github.com> Date: Sun, 6 Feb 2022 16:59:17 +0100 Subject: [PATCH 021/158] examples: remove bitwise syntax for includes check closes #4814 --- examples/web-service/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/web-service/index.js b/examples/web-service/index.js index c22fea4032..a2cd2cb7f9 100644 --- a/examples/web-service/index.js +++ b/examples/web-service/index.js @@ -34,7 +34,7 @@ app.use('/api', function(req, res, next){ if (!key) return next(error(400, 'api key required')); // key is invalid - if (!~apiKeys.indexOf(key)) return next(error(401, 'invalid api key')); + if (apiKeys.indexOf(key) === -1) return next(error(401, 'invalid api key')) // all good, store req.key for route access req.key = key; From 12310c52947ee159f7ecd63d125243cdca891135 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 7 Feb 2022 23:08:12 -0500 Subject: [PATCH 022/158] build: use nyc for test coverage --- .github/workflows/ci.yml | 18 +++++++++--------- .gitignore | 1 + appveyor.yml | 12 ++++++++++++ package.json | 6 +++--- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 416ece0959..30da0e25c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,39 +31,39 @@ jobs: include: - name: Node.js 0.10 node-version: "0.10" - npm-i: minimatch@3.0.4 mocha@3.5.3 supertest@2.0.0 + npm-i: minimatch@3.0.4 mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 - name: Node.js 0.12 node-version: "0.12" - npm-i: minimatch@3.0.4 mocha@3.5.3 supertest@2.0.0 + npm-i: minimatch@3.0.4 mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 - name: io.js 1.x node-version: "1.8" - npm-i: minimatch@3.0.4 mocha@3.5.3 supertest@2.0.0 + npm-i: minimatch@3.0.4 mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 - name: io.js 2.x node-version: "2.5" - npm-i: minimatch@3.0.4 mocha@3.5.3 supertest@2.0.0 + npm-i: minimatch@3.0.4 mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 - name: io.js 3.x node-version: "3.3" - npm-i: minimatch@3.0.4 mocha@3.5.3 supertest@2.0.0 + npm-i: minimatch@3.0.4 mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 - name: Node.js 4.x node-version: "4.9" - npm-i: mocha@5.2.0 supertest@3.4.2 + npm-i: mocha@5.2.0 nyc@11.9.0 supertest@3.4.2 - name: Node.js 5.x node-version: "5.12" - npm-i: mocha@5.2.0 supertest@3.4.2 + npm-i: mocha@5.2.0 nyc@11.9.0 supertest@3.4.2 - name: Node.js 6.x node-version: "6.17" - npm-i: mocha@6.2.2 supertest@6.1.6 + npm-i: mocha@6.2.2 nyc@14.1.1 supertest@6.1.6 - name: Node.js 7.x node-version: "7.10" - npm-i: mocha@6.2.2 supertest@6.1.6 + npm-i: mocha@6.2.2 nyc@14.1.1 supertest@6.1.6 - name: Node.js 8.x node-version: "8.17" diff --git a/.gitignore b/.gitignore index a1e980205f..3a673d9cc0 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ package-lock.json *.gz # Coveralls +.nyc_output coverage # Benchmarking diff --git a/appveyor.yml b/appveyor.yml index c1b51ca7cd..1052be0097 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -59,6 +59,18 @@ install: } elseif ([int]$env:nodejs_version.split(".")[0] -lt 12) { npm install --silent --save-dev mocha@8.4.0 } + - ps: | + # nyc for test coverage + # - use 10.3.2 for Node.js < 4 + # - use 11.9.0 for Node.js < 6 + # - use 14.1.1 for Node.js < 8 + if ([int]$env:nodejs_version.split(".")[0] -lt 4) { + npm install --silent --save-dev nyc@10.3.2 + } elseif ([int]$env:nodejs_version.split(".")[0] -lt 6) { + npm install --silent --save-dev nyc@11.9.0 + } elseif ([int]$env:nodejs_version.split(".")[0] -lt 8) { + npm install --silent --save-dev nyc@14.1.1 + } - ps: | # supertest for http calls # - use 2.0.0 for Node.js < 4 diff --git a/package.json b/package.json index b3eedce29c..daa2f0d3a1 100644 --- a/package.json +++ b/package.json @@ -68,12 +68,12 @@ "eslint": "7.32.0", "express-session": "1.17.2", "hbs": "4.2.0", - "istanbul": "0.4.5", "marked": "0.7.0", "method-override": "3.0.0", "mocha": "9.2.0", "morgan": "1.10.0", "multiparty": "4.2.2", + "nyc": "15.1.0", "pbkdf2-password": "1.2.1", "should": "13.2.3", "supertest": "6.2.2", @@ -92,8 +92,8 @@ "scripts": { "lint": "eslint .", "test": "mocha --require test/support/env --reporter spec --bail --check-leaks test/ test/acceptance/", - "test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --require test/support/env --reporter spec --check-leaks test/ test/acceptance/", - "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --require test/support/env --reporter dot --check-leaks test/ test/acceptance/", + "test-ci": "nyc --reporter=lcovonly --reporter=text npm test", + "test-cov": "nyc --reporter=html --reporter=text npm test", "test-tap": "mocha --require test/support/env --reporter tap --check-leaks test/ test/acceptance/" } } From 82de4de5ab92e8237d713285104e4b8452927352 Mon Sep 17 00:00:00 2001 From: KoyamaSohei Date: Fri, 13 Dec 2019 14:38:56 +0900 Subject: [PATCH 023/158] examples: fix path traversal in downloads example closes #4120 --- examples/downloads/index.js | 7 ++++++- package.json | 1 + test/acceptance/downloads.js | 8 ++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/examples/downloads/index.js b/examples/downloads/index.js index 91c52bb87c..62e7fa6e3e 100644 --- a/examples/downloads/index.js +++ b/examples/downloads/index.js @@ -6,8 +6,13 @@ var express = require('../../'); var path = require('path'); +var resolvePath = require('resolve-path') + var app = module.exports = express(); +// path to where the files are stored on disk +var FILES_DIR = path.join(__dirname, 'files') + app.get('/', function(req, res){ res.send('

    ' + '
  • Download notes/groceries.txt.
  • ' + @@ -20,7 +25,7 @@ app.get('/', function(req, res){ // /files/* is accessed via req.params[0] // but here we name it :file app.get('/files/:file(*)', function(req, res, next){ - var filePath = path.join(__dirname, 'files', req.params.file); + var filePath = resolvePath(FILES_DIR, req.params.file) res.download(filePath, function (err) { if (!err) return; // file sent diff --git a/package.json b/package.json index daa2f0d3a1..fe5d07553f 100644 --- a/package.json +++ b/package.json @@ -75,6 +75,7 @@ "multiparty": "4.2.2", "nyc": "15.1.0", "pbkdf2-password": "1.2.1", + "resolve-path": "1.4.0", "should": "13.2.3", "supertest": "6.2.2", "vhost": "~3.0.2" diff --git a/test/acceptance/downloads.js b/test/acceptance/downloads.js index ae44388354..6db43b351e 100644 --- a/test/acceptance/downloads.js +++ b/test/acceptance/downloads.js @@ -36,4 +36,12 @@ describe('downloads', function(){ .expect(404, done) }) }) + + describe('GET /files/../index.js', function () { + it('should respond with 403', function (done) { + request(app) + .get('/files/../index.js') + .expect(403, done) + }) + }) }) From a39e409cf3739ef9c9b597a9680813a34c3931c2 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 8 Feb 2022 18:40:07 -0500 Subject: [PATCH 024/158] tests: prevent leaking changes to NODE_ENV --- test/app.js | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/test/app.js b/test/app.js index d0756795d3..70f72de7c7 100644 --- a/test/app.js +++ b/test/app.js @@ -83,28 +83,49 @@ describe('app.path()', function(){ }) describe('in development', function(){ + before(function () { + this.env = process.env.NODE_ENV + process.env.NODE_ENV = 'development' + }) + + after(function () { + process.env.NODE_ENV = this.env + }) + it('should disable "view cache"', function(){ - process.env.NODE_ENV = 'development'; var app = express(); assert.ok(!app.enabled('view cache')) - process.env.NODE_ENV = 'test'; }) }) describe('in production', function(){ + before(function () { + this.env = process.env.NODE_ENV + process.env.NODE_ENV = 'production' + }) + + after(function () { + process.env.NODE_ENV = this.env + }) + it('should enable "view cache"', function(){ - process.env.NODE_ENV = 'production'; var app = express(); assert.ok(app.enabled('view cache')) - process.env.NODE_ENV = 'test'; }) }) describe('without NODE_ENV', function(){ + before(function () { + this.env = process.env.NODE_ENV + process.env.NODE_ENV = '' + }) + + after(function () { + process.env.NODE_ENV = this.env + }) + it('should default to development', function(){ - process.env.NODE_ENV = ''; var app = express(); assert.strictEqual(app.get('env'), 'development') - process.env.NODE_ENV = 'test'; }) }) From a65913776d0b16837364ee66caa1a7f38a9997c0 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 9 Feb 2022 01:07:08 -0500 Subject: [PATCH 025/158] tests: use strict mode --- test/Route.js | 1 + test/Router.js | 1 + test/app.all.js | 1 + test/app.del.js | 1 + test/app.engine.js | 1 + test/app.head.js | 1 + test/app.js | 1 + test/app.listen.js | 1 + test/app.locals.js | 1 + test/app.options.js | 1 + test/app.param.js | 1 + test/app.render.js | 1 + test/app.request.js | 1 + test/app.response.js | 1 + test/app.route.js | 2 ++ test/app.router.js | 1 + test/app.routes.error.js | 1 + test/app.use.js | 1 + test/config.js | 1 + test/exports.js | 1 + test/express.json.js | 1 + test/express.raw.js | 1 + test/express.static.js | 1 + test/express.text.js | 1 + test/express.urlencoded.js | 1 + test/middleware.basic.js | 1 + test/regression.js | 1 + test/req.accepts.js | 1 + test/req.acceptsCharset.js | 1 + test/req.acceptsCharsets.js | 1 + test/req.acceptsEncoding.js | 1 + test/req.acceptsEncodings.js | 1 + test/req.acceptsLanguage.js | 1 + test/req.acceptsLanguages.js | 1 + test/req.baseUrl.js | 1 + test/req.fresh.js | 1 + test/req.get.js | 1 + test/req.host.js | 1 + test/req.hostname.js | 1 + test/req.ip.js | 1 + test/req.ips.js | 1 + test/req.is.js | 1 + test/req.param.js | 1 + test/req.path.js | 1 + test/req.protocol.js | 1 + test/req.query.js | 1 + test/req.range.js | 1 + test/req.route.js | 1 + test/req.secure.js | 1 + test/req.signedCookies.js | 1 + test/req.stale.js | 1 + test/req.subdomains.js | 1 + test/req.xhr.js | 1 + test/res.append.js | 1 + test/res.attachment.js | 1 + test/res.clearCookie.js | 1 + test/res.cookie.js | 1 + test/res.download.js | 1 + test/res.format.js | 1 + test/res.get.js | 1 + test/res.json.js | 1 + test/res.jsonp.js | 1 + test/res.links.js | 1 + test/res.locals.js | 1 + test/res.location.js | 1 + test/res.redirect.js | 1 + test/res.render.js | 1 + test/res.send.js | 1 + test/res.sendFile.js | 1 + test/res.sendStatus.js | 1 + test/res.set.js | 1 + test/res.status.js | 1 + test/res.type.js | 1 + test/res.vary.js | 1 + test/utils.js | 1 + 75 files changed, 76 insertions(+) diff --git a/test/Route.js b/test/Route.js index 8f90152d8c..005b4634e9 100644 --- a/test/Route.js +++ b/test/Route.js @@ -1,3 +1,4 @@ +'use strict' var after = require('after'); var should = require('should'); diff --git a/test/Router.js b/test/Router.js index 16522f6aa8..907b972636 100644 --- a/test/Router.js +++ b/test/Router.js @@ -1,3 +1,4 @@ +'use strict' var after = require('after'); var express = require('../') diff --git a/test/app.all.js b/test/app.all.js index 45c3ddb93b..185a8332fe 100644 --- a/test/app.all.js +++ b/test/app.all.js @@ -1,3 +1,4 @@ +'use strict' var after = require('after') var express = require('../') diff --git a/test/app.del.js b/test/app.del.js index d419fbb158..e9e5769d65 100644 --- a/test/app.del.js +++ b/test/app.del.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/app.engine.js b/test/app.engine.js index 0d54c90d56..214510a94c 100644 --- a/test/app.engine.js +++ b/test/app.engine.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var express = require('../') diff --git a/test/app.head.js b/test/app.head.js index 6aa1bb8003..fabb98795a 100644 --- a/test/app.head.js +++ b/test/app.head.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../'); var request = require('supertest'); diff --git a/test/app.js b/test/app.js index 70f72de7c7..6134717c33 100644 --- a/test/app.js +++ b/test/app.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var express = require('..') diff --git a/test/app.listen.js b/test/app.listen.js index 9d54ca5244..08eeaaa63c 100644 --- a/test/app.listen.js +++ b/test/app.listen.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') diff --git a/test/app.locals.js b/test/app.locals.js index 0b14ac9070..88f83c9483 100644 --- a/test/app.locals.js +++ b/test/app.locals.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var express = require('../') diff --git a/test/app.options.js b/test/app.options.js index 9c88abafe5..fdfd38c8a2 100644 --- a/test/app.options.js +++ b/test/app.options.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/app.param.js b/test/app.param.js index 7dbe3ffb61..8893851f9d 100644 --- a/test/app.param.js +++ b/test/app.param.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var express = require('../') diff --git a/test/app.render.js b/test/app.render.js index d0b367189b..9d202acfdd 100644 --- a/test/app.render.js +++ b/test/app.render.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var express = require('..'); diff --git a/test/app.request.js b/test/app.request.js index 0288f80b09..4930af84c2 100644 --- a/test/app.request.js +++ b/test/app.request.js @@ -1,3 +1,4 @@ +'use strict' var after = require('after') var express = require('../') diff --git a/test/app.response.js b/test/app.response.js index ea696b566f..5fb69f6275 100644 --- a/test/app.response.js +++ b/test/app.response.js @@ -1,3 +1,4 @@ +'use strict' var after = require('after') var express = require('../') diff --git a/test/app.route.js b/test/app.route.js index 75e5e0b842..eaf8a12051 100644 --- a/test/app.route.js +++ b/test/app.route.js @@ -1,3 +1,5 @@ +'use strict' + var express = require('../'); var request = require('supertest'); diff --git a/test/app.router.js b/test/app.router.js index 8c98aa869b..3069a22c77 100644 --- a/test/app.router.js +++ b/test/app.router.js @@ -1,3 +1,4 @@ +'use strict' var after = require('after'); var express = require('../') diff --git a/test/app.routes.error.js b/test/app.routes.error.js index b1f95d0d6e..56081b3112 100644 --- a/test/app.routes.error.js +++ b/test/app.routes.error.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var express = require('../') diff --git a/test/app.use.js b/test/app.use.js index 55ba0689c8..fd9b1751a3 100644 --- a/test/app.use.js +++ b/test/app.use.js @@ -1,3 +1,4 @@ +'use strict' var after = require('after'); var assert = require('assert') diff --git a/test/config.js b/test/config.js index 17a02b7eba..8386a4471c 100644 --- a/test/config.js +++ b/test/config.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert'); var express = require('..'); diff --git a/test/exports.js b/test/exports.js index 7624a8c864..98d7936594 100644 --- a/test/exports.js +++ b/test/exports.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var express = require('../'); diff --git a/test/express.json.js b/test/express.json.js index 907fa0cfeb..53a39565a9 100644 --- a/test/express.json.js +++ b/test/express.json.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var Buffer = require('safe-buffer').Buffer diff --git a/test/express.raw.js b/test/express.raw.js index 571c29ca9b..cbd0736e7c 100644 --- a/test/express.raw.js +++ b/test/express.raw.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var Buffer = require('safe-buffer').Buffer diff --git a/test/express.static.js b/test/express.static.js index 56d3657bff..245fd5929c 100644 --- a/test/express.static.js +++ b/test/express.static.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var Buffer = require('safe-buffer').Buffer diff --git a/test/express.text.js b/test/express.text.js index 7c92f90e5a..ebc12cd109 100644 --- a/test/express.text.js +++ b/test/express.text.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var Buffer = require('safe-buffer').Buffer diff --git a/test/express.urlencoded.js b/test/express.urlencoded.js index 6011de05f7..340eb74316 100644 --- a/test/express.urlencoded.js +++ b/test/express.urlencoded.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var Buffer = require('safe-buffer').Buffer diff --git a/test/middleware.basic.js b/test/middleware.basic.js index 4616842ed6..19f00d9a29 100644 --- a/test/middleware.basic.js +++ b/test/middleware.basic.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var express = require('../'); diff --git a/test/regression.js b/test/regression.js index 5d4509ed6f..4e99b30694 100644 --- a/test/regression.js +++ b/test/regression.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.accepts.js b/test/req.accepts.js index 0df4780e22..2066fb5185 100644 --- a/test/req.accepts.js +++ b/test/req.accepts.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.acceptsCharset.js b/test/req.acceptsCharset.js index f7d0cc0e30..6dbab439b7 100644 --- a/test/req.acceptsCharset.js +++ b/test/req.acceptsCharset.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.acceptsCharsets.js b/test/req.acceptsCharsets.js index d1c459174a..360a9878a7 100644 --- a/test/req.acceptsCharsets.js +++ b/test/req.acceptsCharsets.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.acceptsEncoding.js b/test/req.acceptsEncoding.js index f2af68da22..bcec2280e6 100644 --- a/test/req.acceptsEncoding.js +++ b/test/req.acceptsEncoding.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.acceptsEncodings.js b/test/req.acceptsEncodings.js index dc21c4edda..c36934290a 100644 --- a/test/req.acceptsEncodings.js +++ b/test/req.acceptsEncodings.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.acceptsLanguage.js b/test/req.acceptsLanguage.js index 616e723946..816be244eb 100644 --- a/test/req.acceptsLanguage.js +++ b/test/req.acceptsLanguage.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.acceptsLanguages.js b/test/req.acceptsLanguages.js index 87bf7b25df..e5629fbc32 100644 --- a/test/req.acceptsLanguages.js +++ b/test/req.acceptsLanguages.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.baseUrl.js b/test/req.baseUrl.js index 9ac9d88029..b70803ea8b 100644 --- a/test/req.baseUrl.js +++ b/test/req.baseUrl.js @@ -1,3 +1,4 @@ +'use strict' var express = require('..') var request = require('supertest') diff --git a/test/req.fresh.js b/test/req.fresh.js index 1aa8fa5b21..9160e2caaf 100644 --- a/test/req.fresh.js +++ b/test/req.fresh.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.get.js b/test/req.get.js index 109a2d90ce..16589b3f05 100644 --- a/test/req.get.js +++ b/test/req.get.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest') diff --git a/test/req.host.js b/test/req.host.js index 7bb0b27acf..2c051fb979 100644 --- a/test/req.host.js +++ b/test/req.host.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest') diff --git a/test/req.hostname.js b/test/req.hostname.js index 09bfb89989..b3716b566a 100644 --- a/test/req.hostname.js +++ b/test/req.hostname.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest') diff --git a/test/req.ip.js b/test/req.ip.js index 23623cfce6..6bb3c5ac52 100644 --- a/test/req.ip.js +++ b/test/req.ip.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.ips.js b/test/req.ips.js index a7d464b846..2f9a0736ea 100644 --- a/test/req.ips.js +++ b/test/req.ips.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.is.js b/test/req.is.js index a2fce17867..c5904dd600 100644 --- a/test/req.is.js +++ b/test/req.is.js @@ -1,3 +1,4 @@ +'use strict' var express = require('..') var request = require('supertest') diff --git a/test/req.param.js b/test/req.param.js index 89f0295cd9..b3748c02bc 100644 --- a/test/req.param.js +++ b/test/req.param.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest') diff --git a/test/req.path.js b/test/req.path.js index 6ad4009c7d..3ff6177c74 100644 --- a/test/req.path.js +++ b/test/req.path.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.protocol.js b/test/req.protocol.js index 453ad11ca4..61f76356b4 100644 --- a/test/req.protocol.js +++ b/test/req.protocol.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.query.js b/test/req.query.js index f3e8df8a18..6fae592dcc 100644 --- a/test/req.query.js +++ b/test/req.query.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var express = require('../') diff --git a/test/req.range.js b/test/req.range.js index 5443c0658d..111441736e 100644 --- a/test/req.range.js +++ b/test/req.range.js @@ -1,3 +1,4 @@ +'use strict' var express = require('..'); var request = require('supertest') diff --git a/test/req.route.js b/test/req.route.js index b32d470bd6..6c17fbb1c8 100644 --- a/test/req.route.js +++ b/test/req.route.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.secure.js b/test/req.secure.js index 2025c8786b..0097ed6136 100644 --- a/test/req.secure.js +++ b/test/req.secure.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.signedCookies.js b/test/req.signedCookies.js index a55f81b22c..db56195166 100644 --- a/test/req.signedCookies.js +++ b/test/req.signedCookies.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest') diff --git a/test/req.stale.js b/test/req.stale.js index 30c9d05d51..cda77fa403 100644 --- a/test/req.stale.js +++ b/test/req.stale.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.subdomains.js b/test/req.subdomains.js index 18e4d80ad3..e5600f2eb5 100644 --- a/test/req.subdomains.js +++ b/test/req.subdomains.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.xhr.js b/test/req.xhr.js index 3ad1c6fb72..99cf7f1917 100644 --- a/test/req.xhr.js +++ b/test/req.xhr.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/res.append.js b/test/res.append.js index f7f1d55b3c..5b12e35b69 100644 --- a/test/res.append.js +++ b/test/res.append.js @@ -1,3 +1,4 @@ +'use strict' var express = require('..') var request = require('supertest') diff --git a/test/res.attachment.js b/test/res.attachment.js index 4c3d4aa2f1..6283ded0d6 100644 --- a/test/res.attachment.js +++ b/test/res.attachment.js @@ -1,3 +1,4 @@ +'use strict' var Buffer = require('safe-buffer').Buffer var express = require('../') diff --git a/test/res.clearCookie.js b/test/res.clearCookie.js index 4822057e92..fc0cfb99a3 100644 --- a/test/res.clearCookie.js +++ b/test/res.clearCookie.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/res.cookie.js b/test/res.cookie.js index 8f8662c217..d10e48646b 100644 --- a/test/res.cookie.js +++ b/test/res.cookie.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest') diff --git a/test/res.download.js b/test/res.download.js index 579f8c67a9..ce0ee088ba 100644 --- a/test/res.download.js +++ b/test/res.download.js @@ -1,3 +1,4 @@ +'use strict' var after = require('after'); var assert = require('assert'); diff --git a/test/res.format.js b/test/res.format.js index 076b78d738..24e18d9552 100644 --- a/test/res.format.js +++ b/test/res.format.js @@ -1,3 +1,4 @@ +'use strict' var after = require('after') var express = require('../') diff --git a/test/res.get.js b/test/res.get.js index a53bdc3380..a5f12e2e53 100644 --- a/test/res.get.js +++ b/test/res.get.js @@ -1,3 +1,4 @@ +'use strict' var express = require('..'); var request = require('supertest'); diff --git a/test/res.json.js b/test/res.json.js index 59227a830b..dcaceae5ca 100644 --- a/test/res.json.js +++ b/test/res.json.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest') diff --git a/test/res.jsonp.js b/test/res.jsonp.js index 3444d5138b..0735d43bd5 100644 --- a/test/res.jsonp.js +++ b/test/res.jsonp.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest') diff --git a/test/res.links.js b/test/res.links.js index 36630c9ccc..240b7fcfda 100644 --- a/test/res.links.js +++ b/test/res.links.js @@ -1,3 +1,4 @@ +'use strict' var express = require('..'); var request = require('supertest'); diff --git a/test/res.locals.js b/test/res.locals.js index a1c819667a..c4365b36f3 100644 --- a/test/res.locals.js +++ b/test/res.locals.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/res.location.js b/test/res.location.js index c0bfbe8c8e..158afac01e 100644 --- a/test/res.location.js +++ b/test/res.location.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/res.redirect.js b/test/res.redirect.js index c07df5dd2c..be7c773bee 100644 --- a/test/res.redirect.js +++ b/test/res.redirect.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var express = require('..'); diff --git a/test/res.render.js b/test/res.render.js index 643a57002a..50f0b0a742 100644 --- a/test/res.render.js +++ b/test/res.render.js @@ -1,3 +1,4 @@ +'use strict' var express = require('..'); var path = require('path') diff --git a/test/res.send.js b/test/res.send.js index e62caf95dc..8f849f8069 100644 --- a/test/res.send.js +++ b/test/res.send.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var Buffer = require('safe-buffer').Buffer diff --git a/test/res.sendFile.js b/test/res.sendFile.js index 183faceb1d..c7fc93a76d 100644 --- a/test/res.sendFile.js +++ b/test/res.sendFile.js @@ -1,3 +1,4 @@ +'use strict' var after = require('after'); var Buffer = require('safe-buffer').Buffer diff --git a/test/res.sendStatus.js b/test/res.sendStatus.js index c355bc408f..9b1de8385c 100644 --- a/test/res.sendStatus.js +++ b/test/res.sendStatus.js @@ -1,3 +1,4 @@ +'use strict' var express = require('..') var request = require('supertest') diff --git a/test/res.set.js b/test/res.set.js index e46d123947..04511c1c95 100644 --- a/test/res.set.js +++ b/test/res.set.js @@ -1,3 +1,4 @@ +'use strict' var express = require('..'); var request = require('supertest'); diff --git a/test/res.status.js b/test/res.status.js index 8c173a645c..e0abc73c4c 100644 --- a/test/res.status.js +++ b/test/res.status.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/res.type.js b/test/res.type.js index cc1dd08d41..980717a6e3 100644 --- a/test/res.type.js +++ b/test/res.type.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/res.vary.js b/test/res.vary.js index 9d39a341c0..1efc20b445 100644 --- a/test/res.vary.js +++ b/test/res.vary.js @@ -1,3 +1,4 @@ +'use strict' var express = require('..'); var request = require('supertest'); diff --git a/test/utils.js b/test/utils.js index a0fac7a722..f0cb3c3761 100644 --- a/test/utils.js +++ b/test/utils.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert'); var Buffer = require('safe-buffer').Buffer From e98f5848a0a496c0977a2d1734067b77f69de360 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 14 Feb 2022 18:42:47 -0500 Subject: [PATCH 026/158] Revert "build: use minimatch@3.0.4 for Node.js < 4" --- .github/workflows/ci.yml | 10 +++++----- appveyor.yml | 5 ----- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 30da0e25c3..d6e1b168ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,23 +31,23 @@ jobs: include: - name: Node.js 0.10 node-version: "0.10" - npm-i: minimatch@3.0.4 mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 + npm-i: mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 - name: Node.js 0.12 node-version: "0.12" - npm-i: minimatch@3.0.4 mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 + npm-i: mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 - name: io.js 1.x node-version: "1.8" - npm-i: minimatch@3.0.4 mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 + npm-i: mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 - name: io.js 2.x node-version: "2.5" - npm-i: minimatch@3.0.4 mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 + npm-i: mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 - name: io.js 3.x node-version: "3.3" - npm-i: minimatch@3.0.4 mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 + npm-i: mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 - name: Node.js 4.x node-version: "4.9" diff --git a/appveyor.yml b/appveyor.yml index 1052be0097..db54a3fdb0 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -36,11 +36,6 @@ install: sls "^eslint(-|$)" | ` %{ npm rm --silent --save-dev $_ } # Setup Node.js version-specific dependencies - - ps: | - # minimatch for Node.js < 4 - if ([int]$env:nodejs_version.split(".")[0] -lt 4) { - npm install --silent --save-dev minimatch@3.0.4 - } - ps: | # mocha for testing # - use 3.x for Node.js < 4 From a00786309641731661edb4d826a6919330887ca7 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 15 Feb 2022 23:43:41 -0500 Subject: [PATCH 027/158] deps: body-parser@1.19.2 --- History.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/History.md b/History.md index 140756cd03..2550cba59b 100644 --- a/History.md +++ b/History.md @@ -4,6 +4,10 @@ unreleased * deps: accepts@~1.3.8 - deps: mime-types@~2.1.34 - deps: negotiator@0.6.3 + * deps: body-parser@1.19.2 + - deps: bytes@3.1.2 + - deps: qs@6.9.7 + - deps: raw-body@2.4.3 * deps: cookie@0.4.2 * pref: remove unnecessary regexp for trust proxy diff --git a/package.json b/package.json index fe5d07553f..a028b3896c 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "dependencies": { "accepts": "~1.3.8", "array-flatten": "1.1.1", - "body-parser": "1.19.1", + "body-parser": "1.19.2", "content-disposition": "0.5.4", "content-type": "~1.0.4", "cookie": "0.4.2", From 6381bc6317ec8ffbf830e2d16677e4b5af37cc08 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 16 Feb 2022 00:03:16 -0500 Subject: [PATCH 028/158] deps: qs@6.9.7 --- History.md | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/History.md b/History.md index 2550cba59b..e57f098a9f 100644 --- a/History.md +++ b/History.md @@ -9,6 +9,8 @@ unreleased - deps: qs@6.9.7 - deps: raw-body@2.4.3 * deps: cookie@0.4.2 + * deps: qs@6.9.7 + * Fix handling of `__proto__` keys * pref: remove unnecessary regexp for trust proxy 4.17.2 / 2021-12-16 diff --git a/package.json b/package.json index a028b3896c..4816ae1b4a 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "parseurl": "~1.3.3", "path-to-regexp": "0.1.7", "proxy-addr": "~2.0.7", - "qs": "6.9.6", + "qs": "6.9.7", "range-parser": "~1.2.1", "safe-buffer": "5.2.1", "send": "0.17.2", From f9063712e01979588818b0756851053b5ee43d09 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 16 Feb 2022 00:11:24 -0500 Subject: [PATCH 029/158] build: update example dependencies --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4816ae1b4a..2ff077f833 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "method-override": "3.0.0", "mocha": "9.2.0", "morgan": "1.10.0", - "multiparty": "4.2.2", + "multiparty": "4.2.3", "nyc": "15.1.0", "pbkdf2-password": "1.2.1", "resolve-path": "1.4.0", From 3d7fce56a35f4f73fa437866cd1401587a212334 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 16 Feb 2022 21:03:42 -0500 Subject: [PATCH 030/158] 4.17.3 --- History.md | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/History.md b/History.md index e57f098a9f..9f3f876512 100644 --- a/History.md +++ b/History.md @@ -1,5 +1,5 @@ -unreleased -========== +4.17.3 / 2022-02-16 +=================== * deps: accepts@~1.3.8 - deps: mime-types@~2.1.34 diff --git a/package.json b/package.json index 2ff077f833..2fb6ebaab0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "express", "description": "Fast, unopinionated, minimalist web framework", - "version": "4.17.2", + "version": "4.17.3", "author": "TJ Holowaychuk ", "contributors": [ "Aaron Heckmann ", From 8ee3420f0fa064fe8bd6476492cc928f1833f90e Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sun, 20 Feb 2022 23:43:02 -0500 Subject: [PATCH 031/158] tests: fix req.acceptsEncodings tests --- test/req.acceptsEncodings.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/req.acceptsEncodings.js b/test/req.acceptsEncodings.js index c36934290a..9f8973cdfb 100644 --- a/test/req.acceptsEncodings.js +++ b/test/req.acceptsEncodings.js @@ -10,8 +10,8 @@ describe('req', function(){ app.get('/', function (req, res) { res.send({ - gzip: req.acceptsEncoding('gzip'), - deflate: req.acceptsEncoding('deflate') + gzip: req.acceptsEncodings('gzip'), + deflate: req.acceptsEncodings('deflate') }) }) @@ -26,7 +26,7 @@ describe('req', function(){ app.get('/', function (req, res) { res.send({ - bogus: req.acceptsEncoding('bogus') + bogus: req.acceptsEncodings('bogus') }) }) From d8ed591117295f528c59d0f0367064ffde96d427 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sun, 20 Feb 2022 23:49:42 -0500 Subject: [PATCH 032/158] tests: fix req.acceptsLanguage tests --- test/req.acceptsLanguage.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/req.acceptsLanguage.js b/test/req.acceptsLanguage.js index 816be244eb..39bd73c483 100644 --- a/test/req.acceptsLanguage.js +++ b/test/req.acceptsLanguage.js @@ -10,8 +10,8 @@ describe('req', function(){ app.get('/', function (req, res) { res.send({ - 'en-us': req.acceptsLanguages('en-us'), - en: req.acceptsLanguages('en') + 'en-us': req.acceptsLanguage('en-us'), + en: req.acceptsLanguage('en') }) }) @@ -26,7 +26,7 @@ describe('req', function(){ app.get('/', function (req, res) { res.send({ - es: req.acceptsLanguages('es') + es: req.acceptsLanguage('es') }) }) @@ -42,9 +42,9 @@ describe('req', function(){ app.get('/', function (req, res) { res.send({ - en: req.acceptsLanguages('en'), - es: req.acceptsLanguages('es'), - jp: req.acceptsLanguages('jp') + en: req.acceptsLanguage('en'), + es: req.acceptsLanguage('es'), + jp: req.acceptsLanguage('jp') }) }) From 7df0c840e07d17a2268a2ab18e6db7656b203b78 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 21 Feb 2022 19:07:26 -0500 Subject: [PATCH 033/158] tests: fix up app.locals tests --- test/app.locals.js | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/test/app.locals.js b/test/app.locals.js index 88f83c9483..657b4b75c7 100644 --- a/test/app.locals.js +++ b/test/app.locals.js @@ -2,28 +2,24 @@ var assert = require('assert') var express = require('../') -var should = require('should') describe('app', function(){ - describe('.locals(obj)', function(){ - it('should merge locals', function(){ - var app = express(); - should(Object.keys(app.locals)).eql(['settings']) - app.locals.user = 'tobi'; - app.locals.age = 2; - should(Object.keys(app.locals)).eql(['settings', 'user', 'age']) - assert.strictEqual(app.locals.user, 'tobi') - assert.strictEqual(app.locals.age, 2) + describe('.locals', function () { + it('should default object', function () { + var app = express() + assert.ok(app.locals) + assert.strictEqual(typeof app.locals, 'object') }) - }) - describe('.locals.settings', function(){ - it('should expose app settings', function(){ - var app = express(); - app.set('title', 'House of Manny'); - var obj = app.locals.settings; - should(obj).have.property('env', 'test') - should(obj).have.property('title', 'House of Manny') + describe('.settings', function () { + it('should contain app settings ', function () { + var app = express() + app.set('title', 'Express') + assert.ok(app.locals.settings) + assert.strictEqual(typeof app.locals.settings, 'object') + assert.strictEqual(app.locals.settings, app.settings) + assert.strictEqual(app.locals.settings.title, 'Express') + }) }) }) }) From 9967ffbdc2b90fd651e2a687fabc0d53a1065f82 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 21 Feb 2022 19:23:25 -0500 Subject: [PATCH 034/158] tests: update res.append to verify separate header lines --- test/res.append.js | 71 ++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/test/res.append.js b/test/res.append.js index 5b12e35b69..8f72598bf5 100644 --- a/test/res.append.js +++ b/test/res.append.js @@ -1,31 +1,29 @@ 'use strict' +var assert = require('assert') var express = require('..') var request = require('supertest') -var should = require('should') describe('res', function () { - // note about these tests: "Link" and "X-*" are chosen because - // the common node.js versions white list which _incoming_ - // headers can appear multiple times; there is no such white list - // for outgoing, though describe('.append(field, val)', function () { it('should append multiple headers', function (done) { var app = express() app.use(function (req, res, next) { - res.append('Link', '') + res.append('Set-Cookie', 'foo=bar') next() }) app.use(function (req, res) { - res.append('Link', '') + res.append('Set-Cookie', 'fizz=buzz') res.end() }) request(app) - .get('/') - .expect('Link', ', ', done) + .get('/') + .expect(200) + .expect(shouldHaveHeaderValues('Set-Cookie', ['foo=bar', 'fizz=buzz'])) + .end(done) }) it('should accept array of values', function (done) { @@ -37,51 +35,54 @@ describe('res', function () { }) request(app) - .get('/') - .expect(function (res) { - should(res.headers['set-cookie']).eql(['foo=bar', 'fizz=buzz']) - }) - .expect(200, done) + .get('/') + .expect(200) + .expect(shouldHaveHeaderValues('Set-Cookie', ['foo=bar', 'fizz=buzz'])) + .end(done) }) it('should get reset by res.set(field, val)', function (done) { var app = express() app.use(function (req, res, next) { - res.append('Link', '') - res.append('Link', '') + res.append('Set-Cookie', 'foo=bar') + res.append('Set-Cookie', 'fizz=buzz') next() }) app.use(function (req, res) { - res.set('Link', '') + res.set('Set-Cookie', 'pet=tobi') res.end() }); request(app) - .get('/') - .expect('Link', '', done) + .get('/') + .expect(200) + .expect(shouldHaveHeaderValues('Set-Cookie', ['pet=tobi'])) + .end(done) }) it('should work with res.set(field, val) first', function (done) { var app = express() app.use(function (req, res, next) { - res.set('Link', '') + res.set('Set-Cookie', 'foo=bar') next() }) app.use(function(req, res){ - res.append('Link', '') + res.append('Set-Cookie', 'fizz=buzz') res.end() }) request(app) - .get('/') - .expect('Link', ', ', done) + .get('/') + .expect(200) + .expect(shouldHaveHeaderValues('Set-Cookie', ['foo=bar', 'fizz=buzz'])) + .end(done) }) - it('should work with cookies', function (done) { + it('should work together with res.cookie', function (done) { var app = express() app.use(function (req, res, next) { @@ -90,16 +91,26 @@ describe('res', function () { }) app.use(function (req, res) { - res.append('Set-Cookie', 'bar=baz') + res.append('Set-Cookie', 'fizz=buzz') res.end() }) request(app) - .get('/') - .expect(function (res) { - should(res.headers['set-cookie']).eql(['foo=bar; Path=/', 'bar=baz']) - }) - .expect(200, done) + .get('/') + .expect(200) + .expect(shouldHaveHeaderValues('Set-Cookie', ['foo=bar; Path=/', 'fizz=buzz'])) + .end(done) }) }) }) + +function shouldHaveHeaderValues (key, values) { + return function (res) { + var headers = res.headers[key.toLowerCase()] + assert.ok(headers, 'should have header "' + key + '"') + assert.strictEqual(headers.length, values.length, 'should have ' + values.length + ' occurances of "' + key + '"') + for (var i = 0; i < values.length; i++) { + assert.strictEqual(headers[i], values[i]) + } + } +} From bc5ca055094bb48dedbb4a4c828dbe5b2d450616 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 21 Feb 2022 19:54:52 -0500 Subject: [PATCH 035/158] tests: remove usage of should --- package.json | 1 - test/Route.js | 34 +++++++++++++++++----------------- test/exports.js | 21 ++++++++++----------- test/mocha.opts | 2 -- test/res.sendFile.js | 23 ++++++++++------------- test/utils.js | 12 +++++++++--- 6 files changed, 46 insertions(+), 47 deletions(-) delete mode 100644 test/mocha.opts diff --git a/package.json b/package.json index 2fb6ebaab0..61e91899e6 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,6 @@ "nyc": "15.1.0", "pbkdf2-password": "1.2.1", "resolve-path": "1.4.0", - "should": "13.2.3", "supertest": "6.2.2", "vhost": "~3.0.2" }, diff --git a/test/Route.js b/test/Route.js index 005b4634e9..8e7ddbdbcc 100644 --- a/test/Route.js +++ b/test/Route.js @@ -1,7 +1,7 @@ 'use strict' var after = require('after'); -var should = require('should'); +var assert = require('assert') var express = require('../') , Route = express.Route , methods = require('methods') @@ -25,7 +25,7 @@ describe('Route', function(){ route.dispatch(req, {}, function (err) { if (err) return done(err); - should(req.called).be.ok() + assert.ok(req.called) done(); }); }) @@ -35,7 +35,7 @@ describe('Route', function(){ var route = new Route('/foo'); var cb = after(methods.length, function (err) { if (err) return done(err); - count.should.equal(methods.length); + assert.strictEqual(count, methods.length) done(); }); @@ -66,7 +66,7 @@ describe('Route', function(){ route.dispatch(req, {}, function (err) { if (err) return done(err); - req.count.should.equal(2); + assert.strictEqual(req.count, 2) done(); }); }) @@ -84,7 +84,7 @@ describe('Route', function(){ route.dispatch(req, {}, function (err) { if (err) return done(err); - should(req.called).be.ok() + assert.ok(req.called) done(); }); }) @@ -104,7 +104,7 @@ describe('Route', function(){ route.dispatch(req, {}, function (err) { if (err) return done(err); - should(req.called).be.true() + assert.ok(req.called) done(); }); }) @@ -130,7 +130,7 @@ describe('Route', function(){ route.dispatch(req, {}, function (err) { if (err) return done(err); - req.order.should.equal('abc'); + assert.strictEqual(req.order, 'abc') done(); }); }) @@ -156,9 +156,9 @@ describe('Route', function(){ }); route.dispatch(req, {}, function (err) { - should(err).be.ok() - should(err.message).equal('foobar'); - req.order.should.equal('a'); + assert.ok(err) + assert.strictEqual(err.message, 'foobar') + assert.strictEqual(req.order, 'a') done(); }); }) @@ -182,9 +182,9 @@ describe('Route', function(){ }); route.dispatch(req, {}, function (err) { - should(err).be.ok() - should(err.message).equal('foobar'); - req.order.should.equal('a'); + assert.ok(err) + assert.strictEqual(err.message, 'foobar') + assert.strictEqual(req.order, 'a') done(); }); }); @@ -208,7 +208,7 @@ describe('Route', function(){ route.dispatch(req, {}, function (err) { if (err) return done(err); - should(req.message).equal('oops'); + assert.strictEqual(req.message, 'oops') done(); }); }); @@ -222,8 +222,8 @@ describe('Route', function(){ }); route.dispatch(req, {}, function(err){ - should(err).be.ok() - err.message.should.equal('boom!'); + assert.ok(err) + assert.strictEqual(err.message, 'boom!') done(); }); }); @@ -234,7 +234,7 @@ describe('Route', function(){ route.all(function(err, req, res, next){ // this should not execute - true.should.be.false() + throw new Error('should not be called') }); route.dispatch(req, {}, done); diff --git a/test/exports.js b/test/exports.js index 98d7936594..5ab0f885ce 100644 --- a/test/exports.js +++ b/test/exports.js @@ -3,11 +3,10 @@ var assert = require('assert') var express = require('../'); var request = require('supertest'); -var should = require('should'); describe('exports', function(){ it('should expose Router', function(){ - express.Router.should.be.a.Function() + assert.strictEqual(typeof express.Router, 'function') }) it('should expose json middleware', function () { @@ -36,20 +35,23 @@ describe('exports', function(){ }) it('should expose the application prototype', function(){ - express.application.set.should.be.a.Function() + assert.strictEqual(typeof express.application, 'object') + assert.strictEqual(typeof express.application.set, 'function') }) it('should expose the request prototype', function(){ - express.request.accepts.should.be.a.Function() + assert.strictEqual(typeof express.request, 'object') + assert.strictEqual(typeof express.request.accepts, 'function') }) it('should expose the response prototype', function(){ - express.response.send.should.be.a.Function() + assert.strictEqual(typeof express.response, 'object') + assert.strictEqual(typeof express.response.send, 'function') }) it('should permit modifying the .application prototype', function(){ express.application.foo = function(){ return 'bar'; }; - express().foo().should.equal('bar'); + assert.strictEqual(express().foo(), 'bar') }) it('should permit modifying the .request prototype', function(done){ @@ -79,10 +81,7 @@ describe('exports', function(){ }) it('should throw on old middlewares', function(){ - var error; - try { express.bodyParser; } catch (e) { error = e; } - should(error).have.property('message'); - error.message.should.containEql('middleware'); - error.message.should.containEql('bodyParser'); + assert.throws(function () { express.bodyParser() }, /Error:.*middleware.*bodyParser/) + assert.throws(function () { express.limit() }, /Error:.*middleware.*limit/) }) }) diff --git a/test/mocha.opts b/test/mocha.opts deleted file mode 100644 index 1e065ec52d..0000000000 --- a/test/mocha.opts +++ /dev/null @@ -1,2 +0,0 @@ ---require should ---slow 20 diff --git a/test/res.sendFile.js b/test/res.sendFile.js index c7fc93a76d..c676fc41ee 100644 --- a/test/res.sendFile.js +++ b/test/res.sendFile.js @@ -7,7 +7,6 @@ var express = require('../') , assert = require('assert'); var onFinished = require('on-finished'); var path = require('path'); -var should = require('should'); var fixtures = path.join(__dirname, 'fixtures'); var utils = require('./support/utils'); @@ -359,15 +358,13 @@ describe('res', function(){ app.use(function (req, res) { res.sendFile(path.resolve(fixtures, 'does-not-exist'), function (err) { - should(err).be.ok() - err.status.should.equal(404); - res.send('got it'); + res.send(err ? 'got ' + err.status + ' error' : 'no error') }); }); request(app) - .get('/') - .expect(200, 'got it', done); + .get('/') + .expect(200, 'got 404 error', done) }) }) @@ -539,7 +536,7 @@ describe('res', function(){ app.use(function(req, res){ res.sendfile('test/fixtures/user.html', function(err){ assert(!res.headersSent); - req.socket.listeners('error').should.have.length(1); // node's original handler + assert.strictEqual(req.socket.listeners('error').length, 1) // node's original handler done(); }); @@ -783,12 +780,12 @@ describe('res', function(){ }); request(app) - .get('/') - .end(function(err, res){ - res.statusCode.should.equal(404); - calls.should.equal(1); - done(); - }); + .get('/') + .expect(404, function (err) { + if (err) return done(err) + assert.strictEqual(calls, 1) + done() + }) }) describe('with non-GET', function(){ diff --git a/test/utils.js b/test/utils.js index f0cb3c3761..9a38ede656 100644 --- a/test/utils.js +++ b/test/utils.js @@ -2,7 +2,6 @@ var assert = require('assert'); var Buffer = require('safe-buffer').Buffer -var should = require('should') var utils = require('../lib/utils'); describe('utils.etag(body, encoding)', function(){ @@ -91,7 +90,14 @@ describe('utils.isAbsolute()', function(){ describe('utils.flatten(arr)', function(){ it('should flatten an array', function(){ var arr = ['one', ['two', ['three', 'four'], 'five']]; - should(utils.flatten(arr)) - .eql(['one', 'two', 'three', 'four', 'five']) + var flat = utils.flatten(arr) + + assert.strictEqual(flat.length, 5) + assert.strictEqual(flat[0], 'one') + assert.strictEqual(flat[1], 'two') + assert.strictEqual(flat[2], 'three') + assert.strictEqual(flat[3], 'four') + assert.strictEqual(flat[4], 'five') + assert.ok(flat.every(function (v) { return typeof v === 'string' })) }) }) From 18f782bba97157ab2e0ab754b404388e524915fd Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 23 Feb 2022 00:18:36 -0500 Subject: [PATCH 036/158] tests: remove duplicate utils --- test/res.download.js | 36 ++++++++++-------------------------- test/res.redirect.js | 33 +++++++++++++-------------------- test/res.send.js | 34 +++++++++------------------------- test/res.sendFile.js | 26 ++++++++------------------ 4 files changed, 40 insertions(+), 89 deletions(-) diff --git a/test/res.download.js b/test/res.download.js index ce0ee088ba..29a687a4fd 100644 --- a/test/res.download.js +++ b/test/res.download.js @@ -1,10 +1,10 @@ 'use strict' var after = require('after'); -var assert = require('assert'); var Buffer = require('safe-buffer').Buffer var express = require('..'); var request = require('supertest'); +var utils = require('./support/utils') describe('res', function(){ describe('.download(path)', function(){ @@ -129,12 +129,12 @@ describe('res', function(){ }) request(app) - .get('/') - .expect(200) - .expect('Content-Disposition', 'attachment; filename="document"') - .expect('Cache-Control', 'public, max-age=14400') - .expect(shouldHaveBody(Buffer.from('tobi'))) - .end(done) + .get('/') + .expect(200) + .expect('Content-Disposition', 'attachment; filename="document"') + .expect('Cache-Control', 'public, max-age=14400') + .expect(utils.shouldHaveBody(Buffer.from('tobi'))) + .end(done) }) describe('when options.headers contains Content-Disposition', function () { @@ -207,25 +207,9 @@ describe('res', function(){ }); request(app) - .get('/') - .expect(shouldNotHaveHeader('Content-Disposition')) - .expect(200, 'failed', done); + .get('/') + .expect(utils.shouldNotHaveHeader('Content-Disposition')) + .expect(200, 'failed', done) }) }) }) - -function shouldHaveBody (buf) { - return function (res) { - var body = !Buffer.isBuffer(res.body) - ? Buffer.from(res.text) - : res.body - assert.ok(body, 'response has body') - assert.strictEqual(body.toString('hex'), buf.toString('hex')) - } -} - -function shouldNotHaveHeader(header) { - return function (res) { - assert.ok(!(header.toLowerCase() in res.headers), 'should not have header ' + header); - }; -} diff --git a/test/res.redirect.js b/test/res.redirect.js index be7c773bee..5ffc7e48f1 100644 --- a/test/res.redirect.js +++ b/test/res.redirect.js @@ -1,6 +1,5 @@ 'use strict' -var assert = require('assert') var express = require('..'); var request = require('supertest'); var utils = require('./support/utils'); @@ -86,11 +85,11 @@ describe('res', function(){ }); request(app) - .head('/') - .expect(302) - .expect('Location', 'http://google.com') - .expect(shouldNotHaveBody()) - .end(done) + .head('/') + .expect(302) + .expect('Location', 'http://google.com') + .expect(utils.shouldNotHaveBody()) + .end(done) }) }) @@ -199,20 +198,14 @@ describe('res', function(){ }); request(app) - .get('/') - .set('Accept', 'application/octet-stream') - .expect(302) - .expect('location', 'http://google.com') - .expect('content-length', '0') - .expect(utils.shouldNotHaveHeader('Content-Type')) - .expect(shouldNotHaveBody()) - .end(done) + .get('/') + .set('Accept', 'application/octet-stream') + .expect(302) + .expect('location', 'http://google.com') + .expect('content-length', '0') + .expect(utils.shouldNotHaveHeader('Content-Type')) + .expect(utils.shouldNotHaveBody()) + .end(done) }) }) }) - -function shouldNotHaveBody () { - return function (res) { - assert.ok(res.text === '' || res.text === undefined) - } -} diff --git a/test/res.send.js b/test/res.send.js index 8f849f8069..6ba5542288 100644 --- a/test/res.send.js +++ b/test/res.send.js @@ -188,11 +188,11 @@ describe('res', function(){ }); request(app) - .get('/') - .expect(200) - .expect('Content-Type', 'application/octet-stream') - .expect(shouldHaveBody(Buffer.from('hello'))) - .end(done) + .get('/') + .expect(200) + .expect('Content-Type', 'application/octet-stream') + .expect(utils.shouldHaveBody(Buffer.from('hello'))) + .end(done) }) it('should set ETag', function (done) { @@ -259,10 +259,10 @@ describe('res', function(){ }); request(app) - .head('/') - .expect(200) - .expect(shouldNotHaveBody()) - .end(done) + .head('/') + .expect(200) + .expect(utils.shouldNotHaveBody()) + .end(done) }) }) @@ -578,19 +578,3 @@ describe('res', function(){ }) }) }) - -function shouldHaveBody (buf) { - return function (res) { - var body = !Buffer.isBuffer(res.body) - ? Buffer.from(res.text) - : res.body - assert.ok(body, 'response has body') - assert.strictEqual(body.toString('hex'), buf.toString('hex')) - } -} - -function shouldNotHaveBody () { - return function (res) { - assert.ok(res.text === '' || res.text === undefined) - } -} diff --git a/test/res.sendFile.js b/test/res.sendFile.js index c676fc41ee..538d6b9d34 100644 --- a/test/res.sendFile.js +++ b/test/res.sendFile.js @@ -165,10 +165,10 @@ describe('res', function(){ var app = createApp(path.resolve(__dirname, 'fixtures/.name'), { dotfiles: 'allow' }); request(app) - .get('/') - .expect(200) - .expect(shouldHaveBody(Buffer.from('tobi'))) - .end(done) + .get('/') + .expect(200) + .expect(utils.shouldHaveBody(Buffer.from('tobi'))) + .end(done) }); }); @@ -570,10 +570,10 @@ describe('res', function(){ }); request(app) - .get('/') - .expect(200) - .expect(shouldHaveBody(Buffer.from('tobi'))) - .end(done) + .get('/') + .expect(200) + .expect(utils.shouldHaveBody(Buffer.from('tobi'))) + .end(done) }) it('should accept headers option', function(done){ @@ -828,13 +828,3 @@ function createApp(path, options, fn) { return app; } - -function shouldHaveBody (buf) { - return function (res) { - var body = !Buffer.isBuffer(res.body) - ? Buffer.from(res.text) - : res.body - assert.ok(body, 'response has body') - assert.strictEqual(body.toString('hex'), buf.toString('hex')) - } -} From 8da8f79c44cefd96f0a194904288658abce13d9d Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 23 Feb 2022 00:20:34 -0500 Subject: [PATCH 037/158] tests: fix callback in res.download test --- test/res.download.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/res.download.js b/test/res.download.js index 29a687a4fd..1322b0a31f 100644 --- a/test/res.download.js +++ b/test/res.download.js @@ -107,7 +107,7 @@ describe('res', function(){ var options = {} app.use(function (req, res) { - res.download('test/fixtures/user.html', 'document', options, done) + res.download('test/fixtures/user.html', 'document', options, cb) }) request(app) From cf9f662655ec8e2b90c5e5d561e0daa083908aa0 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 24 Feb 2022 00:17:01 -0500 Subject: [PATCH 038/158] tests: fix position of res.sendfile(path, options) test --- test/res.sendFile.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/res.sendFile.js b/test/res.sendFile.js index 538d6b9d34..67981fa127 100644 --- a/test/res.sendFile.js +++ b/test/res.sendFile.js @@ -803,19 +803,19 @@ describe('res', function(){ }) }) }) -}) -describe('.sendfile(path, options)', function () { - it('should pass options to send module', function (done) { - var app = express() + describe('.sendfile(path, options)', function () { + it('should pass options to send module', function (done) { + var app = express() - app.use(function (req, res) { - res.sendfile(path.resolve(fixtures, 'name.txt'), { start: 0, end: 1 }) - }) + app.use(function (req, res) { + res.sendfile(path.resolve(fixtures, 'name.txt'), { start: 0, end: 1 }) + }) - request(app) - .get('/') - .expect(200, 'to', done) + request(app) + .get('/') + .expect(200, 'to', done) + }) }) }) From d0e166c3c6eaf80871b7f38839ea90e048452844 Mon Sep 17 00:00:00 2001 From: apeltop Date: Mon, 28 Feb 2022 16:38:06 +0900 Subject: [PATCH 039/158] docs: fix typo in private api jsdoc closes #4843 --- lib/response.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/response.js b/lib/response.js index ba02008522..ccf8d91b2c 100644 --- a/lib/response.js +++ b/lib/response.js @@ -1113,7 +1113,7 @@ function sendfile(res, file, options, callback) { * ability to escape characters that can trigger HTML sniffing. * * @param {*} value - * @param {function} replaces + * @param {function} replacer * @param {number} spaces * @param {boolean} escape * @returns {string} From ea66a9b81bdd95b83d0035d8cbb41e6eacc6ea5b Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 28 Feb 2022 21:15:08 -0500 Subject: [PATCH 040/158] docs: update link to github actions ci --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index b60d588c41..61c4d5219d 100644 --- a/Readme.md +++ b/Readme.md @@ -147,7 +147,7 @@ The current lead maintainer is [Douglas Christopher Wilson](https://github.com/d [MIT](LICENSE) [ci-image]: https://img.shields.io/github/workflow/status/expressjs/express/ci/master.svg?label=linux -[ci-url]: https://github.com/expressjs/express/actions?query=workflow%3Aci +[ci-url]: https://github.com/expressjs/express/actions/workflows/ci.yml [npm-image]: https://img.shields.io/npm/v/express.svg [npm-url]: https://npmjs.org/package/express [downloads-image]: https://img.shields.io/npm/dm/express.svg From 4ed35b42026e09bcdcd9da821f172c238fb36cb5 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 28 Feb 2022 21:23:49 -0500 Subject: [PATCH 041/158] docs: switch badges to badgen --- Readme.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Readme.md b/Readme.md index 61c4d5219d..51c0fb108e 100644 --- a/Readme.md +++ b/Readme.md @@ -2,9 +2,9 @@ Fast, unopinionated, minimalist web framework for [node](http://nodejs.org). - [![NPM Version][npm-image]][npm-url] - [![NPM Downloads][downloads-image]][downloads-url] - [![Linux Build][ci-image]][ci-url] + [![NPM Version][npm-version-image]][npm-url] + [![NPM Downloads][npm-downloads-image]][npm-downloads-url] + [![Linux Build][github-actions-ci-image]][github-actions-ci-url] [![Windows Build][appveyor-image]][appveyor-url] [![Test Coverage][coveralls-image]][coveralls-url] @@ -146,13 +146,13 @@ The current lead maintainer is [Douglas Christopher Wilson](https://github.com/d [MIT](LICENSE) -[ci-image]: https://img.shields.io/github/workflow/status/expressjs/express/ci/master.svg?label=linux -[ci-url]: https://github.com/expressjs/express/actions/workflows/ci.yml -[npm-image]: https://img.shields.io/npm/v/express.svg -[npm-url]: https://npmjs.org/package/express -[downloads-image]: https://img.shields.io/npm/dm/express.svg -[downloads-url]: https://npmcharts.com/compare/express?minimal=true -[appveyor-image]: https://img.shields.io/appveyor/ci/dougwilson/express/master.svg?label=windows +[appveyor-image]: https://badgen.net/appveyor/ci/dougwilson/express/master?label=windows [appveyor-url]: https://ci.appveyor.com/project/dougwilson/express -[coveralls-image]: https://img.shields.io/coveralls/expressjs/express/master.svg +[coveralls-image]: https://badgen.net/coveralls/c/github/expressjs/express/master [coveralls-url]: https://coveralls.io/r/expressjs/express?branch=master +[github-actions-ci-image]: https://badgen.net/github/checks/expressjs/express/master?label=linux +[github-actions-ci-url]: https://github.com/expressjs/express/actions/workflows/ci.yml +[npm-downloads-image]: https://badgen.net/npm/dm/express +[npm-downloads-url]: https://npmcharts.com/compare/express?minimal=true +[npm-url]: https://npmjs.org/package/express +[npm-version-image]: https://badgen.net/npm/v/express From 07aa91f7cbfc3bc2443b292488ab8e3aafb92605 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 28 Feb 2022 21:52:57 -0500 Subject: [PATCH 042/158] docs: consolidate contributing in readme --- Readme.md | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/Readme.md b/Readme.md index 51c0fb108e..b0a7950e8a 100644 --- a/Readme.md +++ b/Readme.md @@ -4,9 +4,6 @@ [![NPM Version][npm-version-image]][npm-url] [![NPM Downloads][npm-downloads-image]][npm-downloads-url] - [![Linux Build][github-actions-ci-image]][github-actions-ci-url] - [![Windows Build][appveyor-image]][appveyor-url] - [![Test Coverage][coveralls-image]][coveralls-url] ```js const express = require('express') @@ -33,7 +30,7 @@ the [`npm init` command](https://docs.npmjs.com/creating-a-package-json-file). Installation is done using the [`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally): -```bash +```console $ npm install express ``` @@ -61,35 +58,31 @@ for more information. **PROTIP** Be sure to read [Migrating from 3.x to 4.x](https://github.com/expressjs/express/wiki/Migrating-from-3.x-to-4.x) as well as [New features in 4.x](https://github.com/expressjs/express/wiki/New-features-in-4.x). -### Security Issues - -If you discover a security vulnerability in Express, please see [Security Policies and Procedures](Security.md). - ## Quick Start The quickest way to get started with express is to utilize the executable [`express(1)`](https://github.com/expressjs/generator) to generate an application as shown below: Install the executable. The executable's major version will match Express's: -```bash +```console $ npm install -g express-generator@4 ``` Create the app: -```bash +```console $ express /tmp/foo && cd /tmp/foo ``` Install dependencies: -```bash +```console $ npm install ``` Start the server: -```bash +```console $ npm start ``` @@ -109,7 +102,7 @@ $ npm start To view the examples, clone the Express repo and install the dependencies: -```bash +```console $ git clone git://github.com/expressjs/express.git --depth 1 $ cd express $ npm install @@ -117,23 +110,35 @@ $ npm install Then run whichever example you want: -```bash +```console $ node examples/content-negotiation ``` -## Tests +## Contributing + + [![Linux Build][github-actions-ci-image]][github-actions-ci-url] + [![Windows Build][appveyor-image]][appveyor-url] + [![Test Coverage][coveralls-image]][coveralls-url] + +The Express.js project welcomes all constructive contributions. Contributions take many forms, +from code for bug fixes and enhancements, to additions and fixes to documentation, additional +tests, triaging incoming pull requests and issues, and more! + +See the [Contributing Guide](Contributing.md) for more technical details on contributing. - To run the test suite, first install the dependencies, then run `npm test`: +### Security Issues + +If you discover a security vulnerability in Express, please see [Security Policies and Procedures](Security.md). -```bash +### Running Tests + +To run the test suite, first install the dependencies, then run `npm test`: + +```console $ npm install $ npm test ``` -## Contributing - -[Contributing Guide](Contributing.md) - ## People The original author of Express is [TJ Holowaychuk](https://github.com/tj) From e8594c35715a764afda8e56fd1b60cb2fe147f64 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 9 Aug 2018 15:00:29 -0400 Subject: [PATCH 043/158] docs: add install size badge closes #3710 --- Readme.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Readme.md b/Readme.md index b0a7950e8a..720bf38922 100644 --- a/Readme.md +++ b/Readme.md @@ -3,6 +3,7 @@ Fast, unopinionated, minimalist web framework for [node](http://nodejs.org). [![NPM Version][npm-version-image]][npm-url] + [![NPM Install Size][npm-install-size-image]][npm-install-size-url] [![NPM Downloads][npm-downloads-image]][npm-downloads-url] ```js @@ -159,5 +160,7 @@ The current lead maintainer is [Douglas Christopher Wilson](https://github.com/d [github-actions-ci-url]: https://github.com/expressjs/express/actions/workflows/ci.yml [npm-downloads-image]: https://badgen.net/npm/dm/express [npm-downloads-url]: https://npmcharts.com/compare/express?minimal=true +[npm-install-size-image]: https://badgen.net/packagephobia/install/express +[npm-install-size-url]: https://packagephobia.com/result?p=express [npm-url]: https://npmjs.org/package/express [npm-version-image]: https://badgen.net/npm/v/express From 291993d73c0c92c1ccce2dad264c86bdd1b4fe4b Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 1 Mar 2022 00:22:09 -0500 Subject: [PATCH 044/158] tests: expand res.sendFile options tests --- test/res.sendFile.js | 712 ++++++++++++++++++++++++++++++++++-------- test/support/utils.js | 14 + 2 files changed, 596 insertions(+), 130 deletions(-) diff --git a/test/res.sendFile.js b/test/res.sendFile.js index 67981fa127..e828c17e25 100644 --- a/test/res.sendFile.js +++ b/test/res.sendFile.js @@ -28,6 +28,14 @@ describe('res', function(){ .expect(500, /TypeError: path must be a string to res.sendFile/, done) }) + it('should error for non-absolute path', function (done) { + var app = createApp('name.txt') + + request(app) + .get('/') + .expect(500, /TypeError: path must be absolute/, done) + }) + it('should transfer a file', function (done) { var app = createApp(path.resolve(fixtures, 'name.txt')); @@ -90,6 +98,23 @@ describe('res', function(){ .expect(404, done); }); + it('should send cache-control by default', function (done) { + var app = createApp(path.resolve(__dirname, 'fixtures/name.txt')) + + request(app) + .get('/') + .expect('Cache-Control', 'public, max-age=0') + .expect(200, done) + }) + + it('should not serve dotfiles by default', function (done) { + var app = createApp(path.resolve(__dirname, 'fixtures/.name')) + + request(app) + .get('/') + .expect(404, done) + }) + it('should not override manual content-types', function (done) { var app = express(); @@ -131,136 +156,6 @@ describe('res', function(){ server.close(cb) }) }) - - describe('with "cacheControl" option', function () { - it('should enable cacheControl by default', function (done) { - var app = createApp(path.resolve(__dirname, 'fixtures/name.txt')) - - request(app) - .get('/') - .expect('Cache-Control', 'public, max-age=0') - .expect(200, done) - }) - - it('should accept cacheControl option', function (done) { - var app = createApp(path.resolve(__dirname, 'fixtures/name.txt'), { cacheControl: false }) - - request(app) - .get('/') - .expect(utils.shouldNotHaveHeader('Cache-Control')) - .expect(200, done) - }) - }) - - describe('with "dotfiles" option', function () { - it('should not serve dotfiles by default', function (done) { - var app = createApp(path.resolve(__dirname, 'fixtures/.name')); - - request(app) - .get('/') - .expect(404, done); - }); - - it('should accept dotfiles option', function(done){ - var app = createApp(path.resolve(__dirname, 'fixtures/.name'), { dotfiles: 'allow' }); - - request(app) - .get('/') - .expect(200) - .expect(utils.shouldHaveBody(Buffer.from('tobi'))) - .end(done) - }); - }); - - describe('with "headers" option', function () { - it('should accept headers option', function (done) { - var headers = { - 'x-success': 'sent', - 'x-other': 'done' - }; - var app = createApp(path.resolve(__dirname, 'fixtures/name.txt'), { headers: headers }); - - request(app) - .get('/') - .expect('x-success', 'sent') - .expect('x-other', 'done') - .expect(200, done); - }); - - it('should ignore headers option on 404', function (done) { - var headers = { 'x-success': 'sent' }; - var app = createApp(path.resolve(__dirname, 'fixtures/does-not-exist'), { headers: headers }); - - request(app) - .get('/') - .expect(utils.shouldNotHaveHeader('X-Success')) - .expect(404, done); - }); - }); - - describe('with "immutable" option', function () { - it('should add immutable cache-control directive', function (done) { - var app = createApp(path.resolve(__dirname, 'fixtures/name.txt'), { - immutable: true, - maxAge: '4h' - }) - - request(app) - .get('/') - .expect('Cache-Control', 'public, max-age=14400, immutable') - .expect(200, done) - }) - }) - - describe('with "maxAge" option', function () { - it('should set cache-control max-age from number', function (done) { - var app = createApp(path.resolve(__dirname, 'fixtures/name.txt'), { - maxAge: 14400000 - }) - - request(app) - .get('/') - .expect('Cache-Control', 'public, max-age=14400') - .expect(200, done) - }) - - it('should set cache-control max-age from string', function (done) { - var app = createApp(path.resolve(__dirname, 'fixtures/name.txt'), { - maxAge: '4h' - }) - - request(app) - .get('/') - .expect('Cache-Control', 'public, max-age=14400') - .expect(200, done) - }) - }) - - describe('with "root" option', function () { - it('should not transfer relative with without', function (done) { - var app = createApp('test/fixtures/name.txt'); - - request(app) - .get('/') - .expect(500, /must be absolute/, done); - }) - - it('should serve relative to "root"', function (done) { - var app = createApp('name.txt', {root: fixtures}); - - request(app) - .get('/') - .expect(200, 'tobi', done); - }) - - it('should disallow requesting out of "root"', function (done) { - var app = createApp('foo/../../user.html', {root: fixtures}); - - request(app) - .get('/') - .expect(403, done); - }) - }) }) describe('.sendFile(path, fn)', function () { @@ -374,6 +269,563 @@ describe('res', function(){ .get('/') .expect(200, 'to', done) }) + + describe('with "acceptRanges" option', function () { + describe('when true', function () { + it('should advertise byte range accepted', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile(path.resolve(fixtures, 'nums.txt'), { + acceptRanges: true + }) + }) + + request(app) + .get('/') + .expect(200) + .expect('Accept-Ranges', 'bytes') + .expect('123456789') + .end(done) + }) + + it('should respond to range request', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile(path.resolve(fixtures, 'nums.txt'), { + acceptRanges: true + }) + }) + + request(app) + .get('/') + .set('Range', 'bytes=0-4') + .expect(206, '12345', done) + }) + }) + + describe('when false', function () { + it('should not advertise accept-ranges', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile(path.resolve(fixtures, 'nums.txt'), { + acceptRanges: false + }) + }) + + request(app) + .get('/') + .expect(200) + .expect(utils.shouldNotHaveHeader('Accept-Ranges')) + .end(done) + }) + + it('should not honor range requests', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile(path.resolve(fixtures, 'nums.txt'), { + acceptRanges: false + }) + }) + + request(app) + .get('/') + .set('Range', 'bytes=0-4') + .expect(200, '123456789', done) + }) + }) + }) + + describe('with "cacheControl" option', function () { + describe('when true', function () { + it('should send cache-control header', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile(path.resolve(fixtures, 'user.html'), { + cacheControl: true + }) + }) + + request(app) + .get('/') + .expect(200) + .expect('Cache-Control', 'public, max-age=0') + .end(done) + }) + }) + + describe('when false', function () { + it('should not send cache-control header', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile(path.resolve(fixtures, 'user.html'), { + cacheControl: false + }) + }) + + request(app) + .get('/') + .expect(200) + .expect(utils.shouldNotHaveHeader('Cache-Control')) + .end(done) + }) + }) + }) + + describe('with "dotfiles" option', function () { + describe('when "allow"', function () { + it('should allow dotfiles', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile(path.resolve(fixtures, '.name'), { + dotfiles: 'allow' + }) + }) + + request(app) + .get('/') + .expect(200) + .expect(utils.shouldHaveBody(Buffer.from('tobi'))) + .end(done) + }) + }) + + describe('when "deny"', function () { + it('should deny dotfiles', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile(path.resolve(fixtures, '.name'), { + dotfiles: 'deny' + }) + }) + + request(app) + .get('/') + .expect(403) + .expect(/Forbidden/) + .end(done) + }) + }) + + describe('when "ignore"', function () { + it('should ignore dotfiles', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile(path.resolve(fixtures, '.name'), { + dotfiles: 'ignore' + }) + }) + + request(app) + .get('/') + .expect(404) + .expect(/Not Found/) + .end(done) + }) + }) + }) + + describe('with "headers" option', function () { + it('should set headers on response', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile(path.resolve(fixtures, 'user.html'), { + headers: { + 'X-Foo': 'Bar', + 'X-Bar': 'Foo' + } + }) + }) + + request(app) + .get('/') + .expect(200) + .expect('X-Foo', 'Bar') + .expect('X-Bar', 'Foo') + .end(done) + }) + + it('should use last header when duplicated', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile(path.resolve(fixtures, 'user.html'), { + headers: { + 'X-Foo': 'Bar', + 'x-foo': 'bar' + } + }) + }) + + request(app) + .get('/') + .expect(200) + .expect('X-Foo', 'bar') + .end(done) + }) + + it('should override Content-Type', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile(path.resolve(fixtures, 'user.html'), { + headers: { + 'Content-Type': 'text/x-custom' + } + }) + }) + + request(app) + .get('/') + .expect(200) + .expect('Content-Type', 'text/x-custom') + .end(done) + }) + + it('should not set headers on 404', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile(path.resolve(fixtures, 'does-not-exist'), { + headers: { + 'X-Foo': 'Bar' + } + }) + }) + + request(app) + .get('/') + .expect(404) + .expect(utils.shouldNotHaveHeader('X-Foo')) + .end(done) + }) + }) + + describe('with "immutable" option', function () { + describe('when true', function () { + it('should send cache-control header with immutable', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile(path.resolve(fixtures, 'user.html'), { + immutable: true + }) + }) + + request(app) + .get('/') + .expect(200) + .expect('Cache-Control', 'public, max-age=0, immutable') + .end(done) + }) + }) + + describe('when false', function () { + it('should not send cache-control header with immutable', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile(path.resolve(fixtures, 'user.html'), { + immutable: false + }) + }) + + request(app) + .get('/') + .expect(200) + .expect('Cache-Control', 'public, max-age=0') + .end(done) + }) + }) + }) + + describe('with "lastModified" option', function () { + describe('when true', function () { + it('should send last-modified header', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile(path.resolve(fixtures, 'user.html'), { + lastModified: true + }) + }) + + request(app) + .get('/') + .expect(200) + .expect(utils.shouldHaveHeader('Last-Modified')) + .end(done) + }) + + it('should conditionally respond with if-modified-since', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile(path.resolve(fixtures, 'user.html'), { + lastModified: true + }) + }) + + request(app) + .get('/') + .set('If-Modified-Since', (new Date(Date.now() + 99999).toUTCString())) + .expect(304, done) + }) + }) + + describe('when false', function () { + it('should not have last-modified header', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile(path.resolve(fixtures, 'user.html'), { + lastModified: false + }) + }) + + request(app) + .get('/') + .expect(200) + .expect(utils.shouldNotHaveHeader('Last-Modified')) + .end(done) + }) + + it('should not honor if-modified-since', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile(path.resolve(fixtures, 'user.html'), { + lastModified: false + }) + }) + + request(app) + .get('/') + .set('If-Modified-Since', (new Date(Date.now() + 99999).toUTCString())) + .expect(200) + .expect(utils.shouldNotHaveHeader('Last-Modified')) + .end(done) + }) + }) + }) + + describe('with "maxAge" option', function () { + it('should set cache-control max-age to milliseconds', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile(path.resolve(fixtures, 'user.html'), { + maxAge: 20000 + }) + }) + + request(app) + .get('/') + .expect(200) + .expect('Cache-Control', 'public, max-age=20') + .end(done) + }) + + it('should cap cache-control max-age to 1 year', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile(path.resolve(fixtures, 'user.html'), { + maxAge: 99999999999 + }) + }) + + request(app) + .get('/') + .expect(200) + .expect('Cache-Control', 'public, max-age=31536000') + .end(done) + }) + + it('should min cache-control max-age to 0', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile(path.resolve(fixtures, 'user.html'), { + maxAge: -20000 + }) + }) + + request(app) + .get('/') + .expect(200) + .expect('Cache-Control', 'public, max-age=0') + .end(done) + }) + + it('should floor cache-control max-age', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile(path.resolve(fixtures, 'user.html'), { + maxAge: 21911.23 + }) + }) + + request(app) + .get('/') + .expect(200) + .expect('Cache-Control', 'public, max-age=21') + .end(done) + }) + + describe('when cacheControl: false', function () { + it('shold not send cache-control', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile(path.resolve(fixtures, 'user.html'), { + cacheControl: false, + maxAge: 20000 + }) + }) + + request(app) + .get('/') + .expect(200) + .expect(utils.shouldNotHaveHeader('Cache-Control')) + .end(done) + }) + }) + + describe('when string', function () { + it('should accept plain number as milliseconds', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile(path.resolve(fixtures, 'user.html'), { + maxAge: '20000' + }) + }) + + request(app) + .get('/') + .expect(200) + .expect('Cache-Control', 'public, max-age=20') + .end(done) + }) + + it('should accept suffix "s" for seconds', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile(path.resolve(fixtures, 'user.html'), { + maxAge: '20s' + }) + }) + + request(app) + .get('/') + .expect(200) + .expect('Cache-Control', 'public, max-age=20') + .end(done) + }) + + it('should accept suffix "m" for minutes', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile(path.resolve(fixtures, 'user.html'), { + maxAge: '20m' + }) + }) + + request(app) + .get('/') + .expect(200) + .expect('Cache-Control', 'public, max-age=1200') + .end(done) + }) + + it('should accept suffix "d" for days', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile(path.resolve(fixtures, 'user.html'), { + maxAge: '20d' + }) + }) + + request(app) + .get('/') + .expect(200) + .expect('Cache-Control', 'public, max-age=1728000') + .end(done) + }) + }) + }) + + describe('with "root" option', function () { + it('should allow relative path', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile('name.txt', { + root: fixtures + }) + }) + + request(app) + .get('/') + .expect(200, 'tobi', done) + }) + + it('should allow up within root', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile('fake/../name.txt', { + root: fixtures + }) + }) + + request(app) + .get('/') + .expect(200, 'tobi', done) + }) + + it('should reject up outside root', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile('..' + path.sep + path.relative(path.dirname(fixtures), path.join(fixtures, 'name.txt')), { + root: fixtures + }) + }) + + request(app) + .get('/') + .expect(403, done) + }) + + it('should reject reading outside root', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendFile('../name.txt', { + root: fixtures + }) + }) + + request(app) + .get('/') + .expect(403, done) + }) + }) }) describe('.sendfile(path, fn)', function(){ diff --git a/test/support/utils.js b/test/support/utils.js index 579f042a0c..5b4062e0b2 100644 --- a/test/support/utils.js +++ b/test/support/utils.js @@ -13,6 +13,7 @@ var Buffer = require('safe-buffer').Buffer */ exports.shouldHaveBody = shouldHaveBody +exports.shouldHaveHeader = shouldHaveHeader exports.shouldNotHaveBody = shouldNotHaveBody exports.shouldNotHaveHeader = shouldNotHaveHeader; @@ -33,6 +34,19 @@ function shouldHaveBody (buf) { } } +/** + * Assert that a supertest response does have a header. + * + * @param {string} header Header name to check + * @returns {function} + */ + +function shouldHaveHeader (header) { + return function (res) { + assert.ok((header.toLowerCase() in res.headers), 'should have header ' + header) + } +} + /** * Assert that a supertest response does not have a body. * From 446046f886eb457c3d43f57c3f2fc97b698b317a Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 1 Mar 2022 00:27:48 -0500 Subject: [PATCH 045/158] build: mocha@9.2.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 61e91899e6..7992166629 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "hbs": "4.2.0", "marked": "0.7.0", "method-override": "3.0.0", - "mocha": "9.2.0", + "mocha": "9.2.1", "morgan": "1.10.0", "multiparty": "4.2.3", "nyc": "15.1.0", From 490f1a1738449699c217e00ba56db378923fd6b5 Mon Sep 17 00:00:00 2001 From: Tobias Speicher Date: Thu, 17 Mar 2022 13:00:48 +0100 Subject: [PATCH 046/158] lint: remove deprecated String.prototype.substr closes #4860 --- lib/router/index.js | 16 ++++++++-------- lib/view.js | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/router/index.js b/lib/router/index.js index fbe94acdb4..467d30458c 100644 --- a/lib/router/index.js +++ b/lib/router/index.js @@ -108,8 +108,8 @@ proto.param = function param(name, fn) { var ret; if (name[0] === ':') { - deprecate('router.param(' + JSON.stringify(name) + ', fn): Use router.param(' + JSON.stringify(name.substr(1)) + ', fn) instead'); - name = name.substr(1); + deprecate('router.param(' + JSON.stringify(name) + ', fn): Use router.param(' + JSON.stringify(name.slice(1)) + ', fn) instead') + name = name.slice(1) } for (var i = 0; i < len; ++i) { @@ -180,14 +180,14 @@ proto.handle = function handle(req, res, out) { // remove added slash if (slashAdded) { - req.url = req.url.substr(1); + req.url = req.url.slice(1) slashAdded = false; } // restore altered req.url if (removed.length !== 0) { req.baseUrl = parentUrl; - req.url = protohost + removed + req.url.substr(protohost.length); + req.url = protohost + removed + req.url.slice(protohost.length) removed = ''; } @@ -288,7 +288,7 @@ proto.handle = function handle(req, res, out) { function trim_prefix(layer, layerError, layerPath, path) { if (layerPath.length !== 0) { // Validate path is a prefix match - if (layerPath !== path.substr(0, layerPath.length)) { + if (layerPath !== path.slice(0, layerPath.length)) { next(layerError) return } @@ -301,7 +301,7 @@ proto.handle = function handle(req, res, out) { // middleware (.use stuff) needs to have the path stripped debug('trim prefix (%s) from url %s', layerPath, req.url); removed = layerPath; - req.url = protohost + req.url.substr(protohost.length + removed.length); + req.url = protohost + req.url.slice(protohost.length + removed.length) // Ensure leading slash if (!protohost && req.url[0] !== '/') { @@ -547,10 +547,10 @@ function getProtohost(url) { var pathLength = searchIndex !== -1 ? searchIndex : url.length - var fqdnIndex = url.substr(0, pathLength).indexOf('://') + var fqdnIndex = url.slice(0, pathLength).indexOf('://') return fqdnIndex !== -1 - ? url.substr(0, url.indexOf('/', 3 + fqdnIndex)) + ? url.substring(0, url.indexOf('/', 3 + fqdnIndex)) : undefined } diff --git a/lib/view.js b/lib/view.js index cf101caeab..c08ab4d8d5 100644 --- a/lib/view.js +++ b/lib/view.js @@ -74,7 +74,7 @@ function View(name, options) { if (!opts.engines[this.ext]) { // load engine - var mod = this.ext.substr(1) + var mod = this.ext.slice(1) debug('require "%s"', mod) // default engine export From 2a7417dd84025b62c4207bf018ae8826dc0be629 Mon Sep 17 00:00:00 2001 From: Hashen <37979557+Hashen110@users.noreply.github.com> Date: Sun, 20 Mar 2022 19:58:13 +0530 Subject: [PATCH 047/158] examples: fixup html closes #4866 --- examples/route-separation/views/users/edit.ejs | 2 +- examples/search/public/index.html | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/route-separation/views/users/edit.ejs b/examples/route-separation/views/users/edit.ejs index 0ca2df7652..6df78a953a 100644 --- a/examples/route-separation/views/users/edit.ejs +++ b/examples/route-separation/views/users/edit.ejs @@ -3,7 +3,7 @@

    Editing <%= user.name %>

    - +

    Name: diff --git a/examples/search/public/index.html b/examples/search/public/index.html index f67063c502..7353644ba6 100644 --- a/examples/search/public/index.html +++ b/examples/search/public/index.html @@ -4,7 +4,7 @@ Search example -