From f5e77499917f16b1fd8bdfd998adebb88aa40d00 Mon Sep 17 00:00:00 2001 From: Michael van Engelshoven Date: Thu, 5 Feb 2015 16:57:28 +0100 Subject: [PATCH 1/3] deps: update to path-to-regexp@1.0.3 Because of api changes, some tests had be updated. Backwards incampatible changes are: - Regular expressions have to be wrapped by parentheses -> /users/(\\d+) - standalone asterisk must be written as expression -> /(.*) Benefits: - Match one or more parameters -> /templates/:template+ - Match zero or more parameters -> /files/:path* - Optional parameters -> :foo/:bar? --- examples/downloads/index.js | 2 +- package.json | 2 +- test/app.router.js | 22 +++++++++++----------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/examples/downloads/index.js b/examples/downloads/index.js index d7bdc0c043..e536c536b5 100644 --- a/examples/downloads/index.js +++ b/examples/downloads/index.js @@ -16,7 +16,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){ +app.get('/files/:file*', function(req, res, next){ var file = req.params.file; var path = __dirname + '/files/' + file; diff --git a/package.json b/package.json index 835a9fadfe..71d7549f5a 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "methods": "1.1.0", "on-finished": "~2.1.1", "parseurl": "~1.3.0", - "path-to-regexp": "0.1.3", + "path-to-regexp": "~1.0.3", "proxy-addr": "~1.0.3", "qs": "2.3.2", "range-parser": "~1.0.2", diff --git a/test/app.router.js b/test/app.router.js index 6162489632..beb673bd23 100644 --- a/test/app.router.js +++ b/test/app.router.js @@ -292,7 +292,7 @@ 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]] })); }); @@ -308,7 +308,7 @@ 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]] })); }); @@ -497,7 +497,7 @@ describe('app.router', function(){ it('should allow escaped regexp', function(done){ var app = express(); - app.get('/user/\\d+', function(req, res){ + app.get('/user/(\\d+)', function(req, res){ res.end('woot'); }); @@ -530,7 +530,7 @@ describe('app.router', function(){ it('should denote a greedy capture group', function(done){ var app = express(); - app.get('/user/*.json', function(req, res){ + app.get('/user/(.*).json', function(req, res){ res.end(req.params[0]); }); @@ -542,7 +542,7 @@ describe('app.router', function(){ it('should work with several', function(done){ var app = express(); - app.get('/api/*.*', function(req, res){ + app.get('/api/(.*).(.*)', function(req, res){ var resource = req.params[0] , format = req.params[1]; res.end(resource + ' as ' + format); @@ -556,7 +556,7 @@ describe('app.router', function(){ it('should work cross-segment', function(done){ var app = express(); - app.get('/api*', function(req, res){ + app.get('/api(.*)', function(req, res){ res.send(req.params[0]); }); @@ -572,7 +572,7 @@ describe('app.router', function(){ it('should allow naming', function(done){ var app = express(); - app.get('/api/:resource(*)', function(req, res){ + app.get('/api/:resource*', function(req, res){ var resource = req.params.resource; res.end(resource); }); @@ -609,7 +609,7 @@ describe('app.router', function(){ it('should span multiple segments', function(done){ var app = express(); - app.get('/file/*', function(req, res){ + app.get('/file/(.*)', function(req, res){ res.end(req.params[0]); }); @@ -621,7 +621,7 @@ describe('app.router', function(){ it('should be optional', function(done){ var app = express(); - app.get('/file/*', function(req, res){ + app.get('/file/(.*)', function(req, res){ res.end(req.params[0]); }); @@ -903,7 +903,7 @@ describe('app.router', function(){ var app = express(); var path = []; - app.get('*', function(req, res, next){ + app.get('/(.*)', function(req, res, next){ path.push(0); next(); }); @@ -923,7 +923,7 @@ describe('app.router', function(){ next(); }); - app.get('*', function(req, res, next){ + app.get('/(.*)', function(req, res, next){ path.push(4); next(); }); From 253591f4d97b51b9e7771e59e9817bc1d5125d24 Mon Sep 17 00:00:00 2001 From: Michael van Engelshoven Date: Thu, 5 Feb 2015 20:46:00 +0100 Subject: [PATCH 2/3] tests: fix text expectation The test description did not match the contained expectation. --- test/app.router.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/app.router.js b/test/app.router.js index beb673bd23..6e8bc995c6 100644 --- a/test/app.router.js +++ b/test/app.router.js @@ -603,7 +603,7 @@ describe('app.router', function(){ request(app) .get('/user/122/aaa') - .expect('122', done); + .expect('122/aaa', done); }) it('should span multiple segments', function(done){ From 24cc3bab26002bbe016d4b92b0e2327add5e2695 Mon Sep 17 00:00:00 2001 From: Michael van Engelshoven Date: Fri, 26 Jun 2015 07:59:18 +0200 Subject: [PATCH 3/3] Update path-to-regex dependency --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 71d7549f5a..dd276d4a4b 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "methods": "1.1.0", "on-finished": "~2.1.1", "parseurl": "~1.3.0", - "path-to-regexp": "~1.0.3", + "path-to-regexp": "~1.2.0", "proxy-addr": "~1.0.3", "qs": "2.3.2", "range-parser": "~1.0.2",