Skip to content

Commit

Permalink
Merge branch '5.0' into 5-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleytodd authored Sep 10, 2024
2 parents e5feb9f + 0264908 commit f9256ef
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 55 deletions.
15 changes: 15 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
unreleased
=========================
* remove:
- `path-is-absolute` dependency - use `path.isAbsolute` instead
* breaking:
* `res.status()` accepts only integers, and input must be greater than 99 and less than 1000
* will throw a `RangeError: Invalid status code: ${code}. Status code must be greater than 99 and less than 1000.` for inputs outside this range
* will throw a `TypeError: Invalid status code: ${code}. Status code must be an integer.` for non integer inputs
* deps: [email protected]
* change:
- `res.clearCookie` will ignore user provided `maxAge` and `expires` options
* deps: cookie-signature@^1.2.1
* deps: [email protected]
* deps: merge-descriptors@^2.0.0
* deps: serve-static@^2.0.0
* deps: [email protected]
* deps: accepts@^2.0.0
* deps: mime-types@^3.0.0
- `application/javascript` => `text/javascript`
* deps: type-is@^2.0.0
* deps: content-disposition@^1.0.0
* deps: finalhandler@^2.0.0
* deps: fresh@^2.0.0

5.0.0-beta.3 / 2024-03-25
=========================
Expand Down
4 changes: 2 additions & 2 deletions examples/downloads/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ 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) {
res.download(req.params.file, { root: FILES_DIR }, function (err) {
app.get('/files/*file', function (req, res, next) {
res.download(req.params.file.join('/'), { root: FILES_DIR }, function (err) {
if (!err) return; // file sent
if (err.status !== 404) return next(err); // non-404 error
// file for download not found
Expand Down
2 changes: 1 addition & 1 deletion examples/resource/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var app = module.exports = express();

app.resource = function(path, obj) {
this.get(path, obj.index);
this.get(path + '/:a..:b.:format?', function(req, res){
this.get(path + '/:a..:b{.:format}', function(req, res){
var a = parseInt(req.params.a, 10);
var b = parseInt(req.params.b, 10);
var format = req.params.format;
Expand Down
2 changes: 1 addition & 1 deletion examples/route-separation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ app.get('/', site.index);
// User

app.get('/users', user.list);
app.all('/user/:id/:op?', user.load);
app.all('/user/:id{/:op}', user.load);
app.get('/user/:id', user.view);
app.get('/user/:id/view', user.view);
app.get('/user/:id/edit', user.edit);
Expand Down
2 changes: 1 addition & 1 deletion lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ defineGetter(req, 'hostname', function hostname(){

/**
* Check if the request is fresh, aka
* Last-Modified and/or the ETag
* Last-Modified or the ETag
* still match.
*
* @return {Boolean}
Expand Down
2 changes: 1 addition & 1 deletion lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var http = require('http');
var onFinished = require('on-finished');
var mime = require('mime-types')
var path = require('path');
var pathIsAbsolute = require('path-is-absolute');
var pathIsAbsolute = require('path').isAbsolute;
var statuses = require('statuses')
var merge = require('utils-merge');
var sign = require('cookie-signature').sign;
Expand Down
31 changes: 13 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{
"name": "express",
"description": "Fast, unopinionated, minimalist web framework",
<<<<<<< HEAD
"version": "5.0.0-beta.3",
=======
"version": "4.20.0",
>>>>>>> master
"author": "TJ Holowaychuk <[email protected]>",
"contributors": [
"Aaron Heckmann <[email protected]>",
Expand All @@ -32,37 +28,36 @@
"api"
],
"dependencies": {
"accepts": "~1.3.8",
"accepts": "^2.0.0",
"body-parser": "2.0.0-beta.2",
"content-disposition": "0.5.4",
"content-disposition": "^1.0.0",
"content-type": "~1.0.4",
"cookie": "0.6.0",
"cookie-signature": "1.0.6",
"debug": "3.1.0",
"cookie-signature": "^1.2.1",
"debug": "4.3.6",
"depd": "2.0.0",
"encodeurl": "~2.0.0",
"escape-html": "~1.0.3",
"etag": "~1.8.1",
"finalhandler": "1.2.0",
"fresh": "0.5.2",
"finalhandler": "^2.0.0",
"fresh": "2.0.0",
"http-errors": "2.0.0",
"merge-descriptors": "1.0.3",
"merge-descriptors": "^2.0.0",
"methods": "~1.1.2",
"mime-types": "~2.1.34",
"mime-types": "^3.0.0",
"on-finished": "2.4.1",
"once": "1.4.0",
"parseurl": "~1.3.3",
"path-is-absolute": "1.0.1",
"proxy-addr": "~2.0.7",
"qs": "6.11.0",
"qs": "6.13.0",
"range-parser": "~1.2.1",
"router": "2.0.0-beta.2",
"router": "^2.0.0",
"safe-buffer": "5.2.1",
"send": "1.0.0-beta.2",
"serve-static": "2.0.0-beta.2",
"send": "^1.0.0",
"serve-static": "^2.0.0",
"setprototypeof": "1.2.0",
"statuses": "2.0.1",
"type-is": "~1.6.18",
"type-is": "^2.0.0",
"utils-merge": "1.0.1",
"vary": "~1.1.2"
},
Expand Down
2 changes: 1 addition & 1 deletion test/app.all.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('app.all()', function(){
var app = express()
, n = 0;

app.all('/*', function(req, res, next){
app.all('/*splat', function(req, res, next){
if (n++) return done(new Error('DELETE called several times'));
next();
});
Expand Down
54 changes: 27 additions & 27 deletions test/app.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,12 @@ describe('app.router', function(){
var app = express();
var router = new express.Router({ mergeParams: true });

router.get('/(.*).(.*)', function (req, res) {
router.get(/^\/(.*)\.(.*)/, function (req, res) {
var keys = Object.keys(req.params).sort();
res.send(keys.map(function(k){ return [k, req.params[k]] }));
});

app.use('/user/id:(\\d+)', router);
app.use(/^\/user\/id:(\d+)/, router);

request(app)
.get('/user/id:10/profile.json')
Expand All @@ -353,12 +353,12 @@ describe('app.router', function(){
var app = express();
var router = new express.Router({ mergeParams: true });

router.get('/(.*)', function (req, res) {
router.get(/\/(.*)/, function (req, res) {
var keys = Object.keys(req.params).sort();
res.send(keys.map(function(k){ return [k, req.params[k]] }));
});

app.use('/user/id:(\\d+)/name:(\\w+)', router);
app.use(/^\/user\/id:(\d+)\/name:(\w+)/, router);

request(app)
.get('/user/id:10/name:tj/profile')
Expand All @@ -369,12 +369,12 @@ describe('app.router', function(){
var app = express();
var router = new express.Router({ mergeParams: true });

router.get('/name:(\\w+)', function(req, res){
router.get(/\/name:(\w+)/, function(req, res){
var keys = Object.keys(req.params).sort();
res.send(keys.map(function(k){ return [k, req.params[k]] }));
});

app.use('/user/id:(\\d+)', router);
app.use(/\/user\/id:(\d+)/, router);

request(app)
.get('/user/id:10/name:tj')
Expand Down Expand Up @@ -404,11 +404,11 @@ describe('app.router', function(){
var app = express();
var router = new express.Router({ mergeParams: true });

router.get('/user:(\\w+)/*', function (req, res, next) {
router.get(/\/user:(\w+)\//, function (req, res, next) {
next();
});

app.use('/user/id:(\\d+)', function (req, res, next) {
app.use(/\/user\/id:(\d+)/, function (req, res, next) {
router(req, res, function (err) {
var keys = Object.keys(req.params).sort();
res.send(keys.map(function(k){ return [k, req.params[k]] }));
Expand Down Expand Up @@ -631,8 +631,8 @@ describe('app.router', function(){
var app = express();
var cb = after(2, done);

app.get('/user(s?)/:user/:op', function(req, res){
res.end(req.params.op + 'ing ' + req.params.user + (req.params[0] ? ' (old)' : ''));
app.get('/user{s}/:user/:op', function(req, res){
res.end(req.params.op + 'ing ' + req.params.user + (req.url.startsWith('/users') ? ' (old)' : ''));
});

request(app)
Expand Down Expand Up @@ -678,7 +678,7 @@ describe('app.router', function(){
it('should denote an optional capture group', function(done){
var app = express();

app.get('/user/:user/:op?', function(req, res){
app.get('/user/:user{/:op}', function(req, res){
var op = req.params.op || 'view';
res.end(op + 'ing ' + req.params.user);
});
Expand All @@ -691,7 +691,7 @@ describe('app.router', function(){
it('should populate the capture group', function(done){
var app = express();

app.get('/user/:user/:op?', function(req, res){
app.get('/user/:user{/:op}', function(req, res){
var op = req.params.op || 'view';
res.end(op + 'ing ' + req.params.user);
});
Expand All @@ -706,8 +706,8 @@ describe('app.router', function(){
it('should match one segment', function (done) {
var app = express()

app.get('/user/:user*', function (req, res) {
res.end(req.params.user)
app.get('/user/*user', function (req, res) {
res.end(req.params.user[0])
})

request(app)
Expand All @@ -718,8 +718,8 @@ describe('app.router', function(){
it('should match many segments', function (done) {
var app = express()

app.get('/user/:user*', function (req, res) {
res.end(req.params.user)
app.get('/user/*user', function (req, res) {
res.end(req.params.user.join('/'))
})

request(app)
Expand All @@ -730,7 +730,7 @@ describe('app.router', function(){
it('should match zero segments', function (done) {
var app = express()

app.get('/user/:user*', function (req, res) {
app.get('/user{/*user}', function (req, res) {
res.end(req.params.user)
})

Expand All @@ -744,8 +744,8 @@ describe('app.router', function(){
it('should match one segment', function (done) {
var app = express()

app.get('/user/:user+', function (req, res) {
res.end(req.params.user)
app.get('/user/*user', function (req, res) {
res.end(req.params.user[0])
})

request(app)
Expand All @@ -756,8 +756,8 @@ describe('app.router', function(){
it('should match many segments', function (done) {
var app = express()

app.get('/user/:user+', function (req, res) {
res.end(req.params.user)
app.get('/user/*user', function (req, res) {
res.end(req.params.user.join('/'))
})

request(app)
Expand All @@ -768,7 +768,7 @@ describe('app.router', function(){
it('should not match zero segments', function (done) {
var app = express()

app.get('/user/:user+', function (req, res) {
app.get('/user/*user', function (req, res) {
res.end(req.params.user)
})

Expand Down Expand Up @@ -802,7 +802,7 @@ describe('app.router', function(){
var app = express();
var cb = after(2, done)

app.get('/:name.:format?', function(req, res){
app.get('/:name{.:format}', function(req, res){
res.end(req.params.name + ' as ' + (req.params.format || 'html'));
});

Expand All @@ -821,7 +821,7 @@ describe('app.router', function(){
var app = express()
, calls = [];

app.get('/foo/:bar?', function(req, res, next){
app.get('/foo{/:bar}', function(req, res, next){
calls.push('/foo/:bar?');
next();
});
Expand Down Expand Up @@ -906,7 +906,7 @@ describe('app.router', function(){
var app = express()
, calls = [];

app.get('/foo/:bar?', function(req, res, next){
app.get('/foo{/:bar}', function(req, res, next){
calls.push('/foo/:bar?');
next();
});
Expand Down Expand Up @@ -1117,7 +1117,7 @@ describe('app.router', function(){
var app = express();
var path = [];

app.get('/:path+', function (req, res, next) {
app.get('/*path', function (req, res, next) {
path.push(0);
next();
});
Expand All @@ -1137,7 +1137,7 @@ describe('app.router', function(){
next();
});

app.get('/(.*)', function (req, res, next) {
app.get('/*splat', function (req, res, next) {
path.push(4);
next();
});
Expand Down
20 changes: 20 additions & 0 deletions test/req.fresh.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,25 @@ describe('req', function(){
.get('/')
.expect(200, 'false', done);
})

it('should ignore "If-Modified-Since" when "If-None-Match" is present', function(done) {
var app = express();
const etag = '"FooBar"'
const now = Date.now()

app.disable('x-powered-by')
app.use(function(req, res) {
res.set('Etag', etag)
res.set('Last-Modified', new Date(now).toUTCString())
res.send(req.fresh);
});

request(app)
.get('/')
.set('If-Modified-Since', new Date(now - 1000).toUTCString)
.set('If-None-Match', etag)
.expect(304, done);
})

})
})
4 changes: 2 additions & 2 deletions test/req.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('req', function(){
it('should be the executed Route', function(done){
var app = express();

app.get('/user/:id/:op?', function(req, res, next){
app.get('/user/:id{/:op}', function(req, res, next){
res.header('path-1', req.route.path)
next();
});
Expand All @@ -20,7 +20,7 @@ describe('req', function(){

request(app)
.get('/user/12/edit')
.expect('path-1', '/user/:id/:op?')
.expect('path-1', '/user/:id{/:op}')
.expect('path-2', '/user/:id/edit')
.expect(200, done)
})
Expand Down
2 changes: 1 addition & 1 deletion test/res.type.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('res', function(){

request(app)
.get('/')
.expect('Content-Type', 'application/javascript; charset=utf-8')
.expect('Content-Type', 'text/javascript; charset=utf-8')
.end(done)
})

Expand Down

0 comments on commit f9256ef

Please sign in to comment.