Compare commits

...

6 Commits
4.3.1 ... 4.3.2

Author SHA1 Message Date
Douglas Christopher Wilson
311e83e591 4.3.2 2014-05-29 00:17:21 -04:00
Douglas Christopher Wilson
fb2d918056 fix handling of errors from param callbacks
fixes #2149
2014-05-28 22:26:05 -04:00
Douglas Christopher Wilson
dfefea5e9d update example dependencies 2014-05-27 23:51:47 -04:00
Douglas Christopher Wilson
3fbab91231 Merge tag '3.8.1' 2014-05-27 23:49:47 -04:00
Douglas Christopher Wilson
f7e73e2da0 3.8.1 2014-05-27 23:43:13 -04:00
Douglas Christopher Wilson
867728b5ab update connect to 2.17.3 2014-05-27 23:02:27 -04:00
4 changed files with 56 additions and 6 deletions

View File

@@ -1,3 +1,8 @@
4.3.2 / 2014-05-28
==================
* fix handling of errors from `router.param()` callbacks
4.3.1 / 2014-05-23
==================
@@ -119,6 +124,14 @@
- `app.route()` - Proxy to the app's `Router#route()` method to create a new route
- Router & Route - public API
3.8.1 / 2014-05-27
==================
* update connect to 2.17.3
- deps: body-parser@1.2.2
- deps: express-session@1.2.1
- deps: method-override@1.0.2
3.8.0 / 2014-05-21
==================

View File

@@ -290,6 +290,7 @@ proto.process_params = function(layer, called, req, res, done) {
var key;
var paramVal;
var paramCallbacks;
var paramCalled;
// process params in order
// param callbacks can be async
@@ -312,12 +313,18 @@ proto.process_params = function(layer, called, req, res, done) {
name = key.name;
paramVal = req.params[name];
paramCallbacks = params[name];
paramCalled = called[name];
if (paramVal === undefined || !paramCallbacks || called[name] === paramVal) {
if (paramVal === undefined || !paramCallbacks) {
return param();
}
called[name] = paramVal;
// param previously called with same value or error occurred
if (paramCalled && (paramCalled.err || paramCalled.val === paramVal)) {
return param(paramCalled.err);
}
called[name] = paramCalled = { val: paramVal };
try {
return paramCallback();
@@ -328,6 +335,11 @@ proto.process_params = function(layer, called, req, res, done) {
// single param callbacks
function paramCallback(err) {
if (err && paramCalled) {
// store error
paramCalled.err = err;
}
var fn = paramCallbacks[paramIndex++];
if (err || !fn) return param(err);
fn(req, res, paramCallback, paramVal, key.name);

View File

@@ -1,7 +1,7 @@
{
"name": "express",
"description": "Sinatra inspired web development framework",
"version": "4.3.1",
"version": "4.3.2",
"author": "TJ Holowaychuk <tj@vision-media.ca>",
"contributors": [
{
@@ -78,10 +78,10 @@
"marked": "0.3.2",
"multiparty": "~3.2.4",
"hjs": "~0.0.6",
"body-parser": "1.2.0",
"body-parser": "1.2.2",
"cookie-parser": "1.1.0",
"express-session": "1.2.0",
"method-override": "1.0.1",
"express-session": "1.2.1",
"method-override": "1.0.2",
"morgan": "1.1.1",
"vhost": "1.0.0"
},

View File

@@ -194,5 +194,30 @@ describe('app', function(){
.get('/user/123')
.expect('name', done);
})
it('should defer all the param routes', function(done){
var app = express();
app.param('id', function(req, res, next, val){
if (val === 'new') return next('route');
return next();
});
app.all('/user/:id', function(req, res){
res.send('all.id');
});
app.get('/user/:id', function(req, res){
res.send('get.id');
});
app.get('/user/new', function(req, res){
res.send('get.new');
});
request(app)
.get('/user/new')
.expect('get.new', done);
})
})
})