Skip to content

Commit 647563f

Browse files
committed
1 parent 6da57c7 commit 647563f

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

Diff for: History.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
unreleased
2+
==========
3+
4+
5+
- Adds support for named matching groups in the routes using a regex
6+
17
4.19.2 / 2024-03-25
28
==========
39

Diff for: 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",

Diff for: test/app.router.js

+26
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,23 @@ describe('app.router', function(){
188188
.expect('editing user 10', done);
189189
})
190190

191+
if (supportsRegexp('(?<foo>.*)')) {
192+
it('should populate req.params with named captures', function(done){
193+
var app = express();
194+
var re = new RegExp('^/user/(?<userId>[0-9]+)/(view|edit)?$');
195+
196+
app.get(re, function(req, res){
197+
var id = req.params.userId
198+
, op = req.params[0];
199+
res.end(op + 'ing user ' + id);
200+
});
201+
202+
request(app)
203+
.get('/user/10/edit')
204+
.expect('editing user 10', done);
205+
})
206+
}
207+
191208
it('should ensure regexp matches path prefix', function (done) {
192209
var app = express()
193210
var p = []
@@ -1109,3 +1126,12 @@ describe('app.router', function(){
11091126
assert.strictEqual(app.get('/', function () {}), app)
11101127
})
11111128
})
1129+
1130+
function supportsRegexp(source) {
1131+
try {
1132+
new RegExp(source)
1133+
return true
1134+
} catch (e) {
1135+
return false
1136+
}
1137+
}

0 commit comments

Comments
 (0)