| @@ -193,6 +193,23 @@ describe('app.router', function(){ |
|
|
| 193 |
193 |
.expect('editing user 10', done); |
| 194 |
194 |
}) |
| 195 |
195 |
|
|
196 |
+if (supportsRegexp('(?.*)')) { |
|
197 |
+it('should populate req.params with named captures', function(done){ |
|
198 |
+var app = express(); |
|
199 |
+var re = new RegExp('^/user/(?[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 |
+ |
| 196 |
213 |
it('should ensure regexp matches path prefix', function (done) { |
| 197 |
214 |
var app = express() |
| 198 |
215 |
var p = [] |
| @@ -1114,3 +1131,12 @@ describe('app.router', function(){ |
|
|
| 1114 |
1131 |
assert.strictEqual(app.get('/', function () {}), app) |
| 1115 |
1132 |
}) |
| 1116 |
1133 |
}) |
|
1134 |
+ |
|
1135 |
+function supportsRegexp(source) { |
|
1136 |
+try { |
|
1137 |
+new RegExp(source) |
|
1138 |
+return true |
|
1139 |
+} catch (e) { |
|
1140 |
+return false |
|
1141 |
+} |
|
1142 |
+} |