Skip to content
Myr

Added + support to the router

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by TJ Holowaychuk · committed by TJ Holowaychuk · parent ebf60d2 · Browse files · 2 files+25 added−18 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+25 added−18 removed

  • tests:+23 added−18 removed
  • other:+2 added−0 removed

2 files+25 added−18 removed

modified:lib/utils.js+2 added
262 unmodified lines
263 if (Array.isArray(path)) path = '(' + path.join('|') + ')';264 path = path265 .concat(strict ? '' : '/?')266 .replace(/\/\(/g, '(?:/')267 .replace(/\+/g, '__plus__')268 .replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?/g, function(_, slash, format, key, capture, optional){269 keys.push({ name: key, optional: !! optional });270 slash = slash || '';271 return ''
3 unmodified lines
275 + (format || '') + (capture || (format && '([^/.]+?)' || '([^/]+?)')) + ')'276 + (optional || '');277 })278 .replace(/([\/.])/g, '\\$1')279 .replace(/__plus__/g, '(.+)')280 .replace(/\*/g, '(.*)');281 return new RegExp('^' + path + '$', sensitive ? '' : 'i');282}
modified:test/app.router.js+23 added-18 removed
254 unmodified lines
255 })256 })257 })258259 it('should allow escaped regexp', function(done){260 var app = express();261262 app.get('/user/\\d+', function(req, res){263 res.end('woot');264 });265266 request(app)267 .get('/user/10')268 .end(function(res){269 res.statusCode.should.equal(200);270 request(app)271 .get('/user/tj')272 .expect(404, done);273 });274 })275 259 it('should allow literal "."', function(done){260 var app = express();261262 app.get('/api/users/:from..:to', function(req, res){
7 unmodified lines
270 .get('/api/users/1..50')271 .expect('users from 1 to 50', done);272 })273291 describe('*', function(){274 describe('+', function(){275 it('should denote a greedy capture group', function(done){276 var app = express();277278 app.get('/blog+', function(req, res){279 res.end(req.params[0] || 'nothing');280 });281282 request(app)283 .get('/blog')284 .expect(404, function(){285 request(app)286 .get('/blog/post')287 .expect(200, function(){288 request(app)289 .get('/blog-admin')290 .expect(200, done)291 })292 });293 })294 })295296 describe('*', function(){297 it('should denote an optional greedy capture group', function(done){298 var app = express();299300 app.get('/user/*.json', function(req, res){301 res.end(req.params[0]);302 });303
274 unmodified lines