Skip to content
Myr

Fixed route wild-card scenario "/report.:format?"

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

Should match "/report.csv", and "/report" etc

authored by visionmedia · committed by visionmedia · parent 8ebfd96 · Browse files · 2 files+10 added−5 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+10 added−5 removed

  • tests:+7 added−0 removed
  • other:+3 added−5 removed

2 files+10 added−5 removed

modified:lib/express/core.js+3 added-5 removed
77 unmodified lines
78 var self = this79 this.keys = []80 if (path instanceof RegExp) return path81 return new RegExp('^' + escapeRegexp(normalizePath(path), '.')82 .replace(/[*]/g, function(){83 return '(.+)'84 })85 .replace(/\/:(\w+)\?/g, function(_, key){82 .replace(/\*/g, '(.+)')83 .replace(/(\/|\\\.):(\w+)\?/g, function(_, c, key){84 self.keys.push(key)87 return '(?:\/([^\/]+))?'85 return '(?:' + c + '([^\/]+))?'86 })87 .replace(/:(\w+)/g, function(_, key){88 self.keys.push(key)89 return '([^\/]+)'
174 unmodified lines
modified:spec/spec.routing.js+7 added
147 unmodified lines
148 it 'should not match with an additional path segment'149 get('/user/:id?', function(){ return 'yay' })150 get('/user/12/edit').body.should.eql 'Not Found'151 end152 153 it 'should match without leading character'154 get('/report.:format?', function(format){ return format || 'none' })155 get('/report.csv').body.should.eql 'csv'156 get('/report').body.should.eql 'none'157 end158 159 end160 161 describe 'with partial wild-card'162 it 'should still match'
139 unmodified lines