Skip to content

Commit c5addb9

Browse files
authored
1 parent e35380a commit c5addb9

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

History.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
unreleased
22
==========
33

4+
5+
- Adds support for named matching groups in the routes using a regex
46
* deps: encodeurl@~2.0.0
57
- Removes encoding of `\`, `|`, and `^` to align better with URL spec
68
* Deprecate passing `options.maxAge` and `options.expires` to `res.clearCookie`

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"methods": "~1.1.2",
4848
"on-finished": "2.4.1",
4949
"parseurl": "~1.3.3",
50-
"path-to-regexp": "0.1.7",
50+
"path-to-regexp": "0.1.8",
5151
"proxy-addr": "~2.0.7",
5252
"qs": "6.11.0",
5353
"range-parser": "~1.2.1",

test/app.router.js

+26
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,23 @@ describe('app.router', function(){
193193
.expect('editing user 10', done);
194194
})
195195

196+
if (supportsRegexp('(?<foo>.*)')) {
197+
it('should populate req.params with named captures', function(done){
198+
var app = express();
199+
var re = new RegExp('^/user/(?<userId>[0-9]+)/(view|edit)?$');
200+
201+
app.get(re, function(req, res){
202+
var id = req.params.userId
203+
, op = req.params[0];
204+
res.end(op + 'ing user ' + id);
205+
});
206+
207+
request(app)
208+
.get('/user/10/edit')
209+
.expect('editing user 10', done);
210+
})
211+
}
212+
196213
it('should ensure regexp matches path prefix', function (done) {
197214
var app = express()
198215
var p = []
@@ -1114,3 +1131,12 @@ describe('app.router', function(){
11141131
assert.strictEqual(app.get('/', function () {}), app)
11151132
})
11161133
})
1134+
1135+
function supportsRegexp(source) {
1136+
try {
1137+
new RegExp(source)
1138+
return true
1139+
} catch (e) {
1140+
return false
1141+
}
1142+
}

0 commit comments

Comments
 (0)