Skip to content

Commit 1574925

Browse files
committed
deps: router@2.0.0-beta.1
closes #4321
1 parent c7d528c commit 1574925

File tree

5 files changed

+97
-208
lines changed

5 files changed

+97
-208
lines changed

History.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33

44
This incorporates all changes after 4.17.1 up to 4.17.2.
55

6+
* deps: router@2.0.0-beta.1
7+
- Add new `?`, `*`, and `+` parameter modifiers
8+
- Internalize private `router.process_params` method
9+
- Matching group expressions are only RegExp syntax
10+
- Named matching groups no longer available by position in `req.params`
11+
- Regular expressions can only be used in a matching group
12+
- Remove `debug` dependency
13+
- Special `*` path segment behavior removed
14+
- deps: array-flatten@3.0.0
15+
- deps: parseurl@~1.3.3
16+
- deps: path-to-regexp@3.2.0
17+
- deps: setprototypeof@1.2.0
18+
619
5.0.0-alpha.8 / 2020-03-25
720
==========================
821

examples/downloads/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ app.get('/', function(req, res){
1717

1818
// /files/* is accessed via req.params[0]
1919
// but here we name it :file
20-
app.get('/files/:file(*)', function(req, res, next){
20+
app.get('/files/:file+', function (req, res, next) {
2121
var filePath = path.join(__dirname, 'files', req.params.file);
2222

2323
res.download(filePath, function (err) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"proxy-addr": "~2.0.7",
5151
"qs": "6.9.6",
5252
"range-parser": "~1.2.1",
53-
"router": "2.0.0-alpha.1",
53+
"router": "2.0.0-beta.1",
5454
"safe-buffer": "5.2.1",
5555
"send": "0.17.2",
5656
"serve-static": "1.14.2",

test/Router.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -344,24 +344,6 @@ describe('Router', function(){
344344
assert.equal(count, methods.length);
345345
done();
346346
})
347-
348-
it('should be called for any URL when "*"', function (done) {
349-
var cb = after(4, done)
350-
var router = new Router()
351-
352-
function no () {
353-
throw new Error('should not be called')
354-
}
355-
356-
router.all('*', function (req, res) {
357-
res.end()
358-
})
359-
360-
router.handle({ url: '/', method: 'GET' }, { end: cb }, no)
361-
router.handle({ url: '/foo', method: 'GET' }, { end: cb }, no)
362-
router.handle({ url: 'foo', method: 'GET' }, { end: cb }, no)
363-
router.handle({ url: '*', method: 'GET' }, { end: cb }, no)
364-
})
365347
})
366348

367349
describe('.use', function() {

test/app.router.js

Lines changed: 82 additions & 188 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ describe('app.router', function(){
189189
.expect('editing user 10', done);
190190
})
191191

192-
it.skip('should ensure regexp matches path prefix', function (done) {
192+
it('should ensure regexp matches path prefix', function (done) {
193193
var app = express()
194194
var p = []
195195

@@ -315,7 +315,7 @@ describe('app.router', function(){
315315
var app = express();
316316
var router = new express.Router({ mergeParams: true });
317317

318-
router.get('/*.*', function(req, res){
318+
router.get('/(.*).(.*)', function (req, res) {
319319
var keys = Object.keys(req.params).sort();
320320
res.send(keys.map(function(k){ return [k, req.params[k]] }));
321321
});
@@ -331,7 +331,7 @@ describe('app.router', function(){
331331
var app = express();
332332
var router = new express.Router({ mergeParams: true });
333333

334-
router.get('/*', function(req, res){
334+
router.get('/(.*)', function (req, res) {
335335
var keys = Object.keys(req.params).sort();
336336
res.send(keys.map(function(k){ return [k, req.params[k]] }));
337337
});
@@ -553,23 +553,6 @@ describe('app.router', function(){
553553
})
554554
})
555555

556-
it('should allow escaped regexp', function(done){
557-
var app = express();
558-
559-
app.get('/user/\\d+', function(req, res){
560-
res.end('woot');
561-
});
562-
563-
request(app)
564-
.get('/user/10')
565-
.expect(200, function (err) {
566-
if (err) return done(err)
567-
request(app)
568-
.get('/user/tj')
569-
.expect(404, done);
570-
});
571-
})
572-
573556
it('should allow literal "."', function(done){
574557
var app = express();
575558

@@ -585,171 +568,6 @@ describe('app.router', function(){
585568
.expect('users from 1 to 50', done);
586569
})
587570

588-
describe('*', function(){
589-
it('should capture everything', function (done) {
590-
var app = express()
591-
592-
app.get('*', function (req, res) {
593-
res.end(req.params[0])
594-
})
595-
596-
request(app)
597-
.get('/user/tobi.json')
598-
.expect('/user/tobi.json', done)
599-
})
600-
601-
it('should decode the capture', function (done) {
602-
var app = express()
603-
604-
app.get('*', function (req, res) {
605-
res.end(req.params[0])
606-
})
607-
608-
request(app)
609-
.get('/user/tobi%20and%20loki.json')
610-
.expect('/user/tobi and loki.json', done)
611-
})
612-
613-
it('should denote a greedy capture group', function(done){
614-
var app = express();
615-
616-
app.get('/user/*.json', function(req, res){
617-
res.end(req.params[0]);
618-
});
619-
620-
request(app)
621-
.get('/user/tj.json')
622-
.expect('tj', done);
623-
})
624-
625-
it('should work with several', function(done){
626-
var app = express();
627-
628-
app.get('/api/*.*', function(req, res){
629-
var resource = req.params[0]
630-
, format = req.params[1];
631-
res.end(resource + ' as ' + format);
632-
});
633-
634-
request(app)
635-
.get('/api/users/foo.bar.json')
636-
.expect('users/foo.bar as json', done);
637-
})
638-
639-
it('should work cross-segment', function(done){
640-
var app = express();
641-
642-
app.get('/api*', function(req, res){
643-
res.send(req.params[0]);
644-
});
645-
646-
request(app)
647-
.get('/api')
648-
.expect('', function(){
649-
request(app)
650-
.get('/api/hey')
651-
.expect('/hey', done);
652-
});
653-
})
654-
655-
it('should allow naming', function(done){
656-
var app = express();
657-
658-
app.get('/api/:resource(*)', function(req, res){
659-
var resource = req.params.resource;
660-
res.end(resource);
661-
});
662-
663-
request(app)
664-
.get('/api/users/0.json')
665-
.expect('users/0.json', done);
666-
})
667-
668-
it('should not be greedy immediately after param', function(done){
669-
var app = express();
670-
671-
app.get('/user/:user*', function(req, res){
672-
res.end(req.params.user);
673-
});
674-
675-
request(app)
676-
.get('/user/122')
677-
.expect('122', done);
678-
})
679-
680-
it('should eat everything after /', function(done){
681-
var app = express();
682-
683-
app.get('/user/:user*', function(req, res){
684-
res.end(req.params.user);
685-
});
686-
687-
request(app)
688-
.get('/user/122/aaa')
689-
.expect('122', done);
690-
})
691-
692-
it('should span multiple segments', function(done){
693-
var app = express();
694-
695-
app.get('/file/*', function(req, res){
696-
res.end(req.params[0]);
697-
});
698-
699-
request(app)
700-
.get('/file/javascripts/jquery.js')
701-
.expect('javascripts/jquery.js', done);
702-
})
703-
704-
it('should be optional', function(done){
705-
var app = express();
706-
707-
app.get('/file/*', function(req, res){
708-
res.end(req.params[0]);
709-
});
710-
711-
request(app)
712-
.get('/file/')
713-
.expect('', done);
714-
})
715-
716-
it('should require a preceding /', function(done){
717-
var app = express();
718-
719-
app.get('/file/*', function(req, res){
720-
res.end(req.params[0]);
721-
});
722-
723-
request(app)
724-
.get('/file')
725-
.expect(404, done);
726-
})
727-
728-
it('should keep correct parameter indexes', function(done){
729-
var app = express();
730-
731-
app.get('/*/user/:id', function (req, res) {
732-
res.send(req.params);
733-
});
734-
735-
request(app)
736-
.get('/1/user/2')
737-
.expect(200, '{"0":"1","id":"2"}', done);
738-
})
739-
740-
it('should work within arrays', function(done){
741-
var app = express();
742-
743-
app.get(['/user/:id', '/foo/*', '/:bar'], function (req, res) {
744-
res.send(req.params.bar);
745-
});
746-
747-
request(app)
748-
.get('/test')
749-
.expect(200, 'test', done);
750-
})
751-
})
752-
753571
describe(':name', function(){
754572
it('should denote a capture group', function(done){
755573
var app = express();
@@ -791,7 +609,7 @@ describe('app.router', function(){
791609
var app = express();
792610
var cb = after(2, done);
793611

794-
app.get('/user(s)?/:user/:op', function(req, res){
612+
app.get('/user(s?)/:user/:op', function(req, res){
795613
res.end(req.params.op + 'ing ' + req.params.user + (req.params[0] ? ' (old)' : ''));
796614
});
797615

@@ -862,6 +680,82 @@ describe('app.router', function(){
862680
})
863681
})
864682

683+
describe(':name*', function () {
684+
it('should match one segment', function (done) {
685+
var app = express()
686+
687+
app.get('/user/:user*', function (req, res) {
688+
res.end(req.params.user)
689+
})
690+
691+
request(app)
692+
.get('/user/122')
693+
.expect('122', done)
694+
})
695+
696+
it('should match many segments', function (done) {
697+
var app = express()
698+
699+
app.get('/user/:user*', function (req, res) {
700+
res.end(req.params.user)
701+
})
702+
703+
request(app)
704+
.get('/user/1/2/3/4')
705+
.expect('1/2/3/4', done)
706+
})
707+
708+
it('should match zero segments', function (done) {
709+
var app = express()
710+
711+
app.get('/user/:user*', function (req, res) {
712+
res.end(req.params.user)
713+
})
714+
715+
request(app)
716+
.get('/user')
717+
.expect('', done)
718+
})
719+
})
720+
721+
describe(':name+', function () {
722+
it('should match one segment', function (done) {
723+
var app = express()
724+
725+
app.get('/user/:user+', function (req, res) {
726+
res.end(req.params.user)
727+
})
728+
729+
request(app)
730+
.get('/user/122')
731+
.expect(200, '122', done)
732+
})
733+
734+
it('should match many segments', function (done) {
735+
var app = express()
736+
737+
app.get('/user/:user+', function (req, res) {
738+
res.end(req.params.user)
739+
})
740+
741+
request(app)
742+
.get('/user/1/2/3/4')
743+
.expect(200, '1/2/3/4', done)
744+
})
745+
746+
it('should not match zero segments', function (done) {
747+
var app = express()
748+
749+
app.get('/user/:user+', function (req, res) {
750+
res.end(req.params.user)
751+
})
752+
753+
request(app)
754+
.get('/user')
755+
.expect(404, done)
756+
})
757+
})
758+
865759
describe('.:name', function(){
866760
it('should denote a format', function(done){
867761
var app = express();
@@ -1199,7 +1093,7 @@ describe('app.router', function(){
11991093
var app = express();
12001094
var path = [];
12011095

1202-
app.get('*', function(req, res, next){
1096+
app.get('/:path+', function (req, res, next) {
12031097
path.push(0);
12041098
next();
12051099
});
@@ -1219,7 +1113,7 @@ describe('app.router', function(){
12191113
next();
12201114
});
12211115

1222-
app.get('*', function(req, res, next){
1116+
app.get('/(.*)', function (req, res, next) {
12231117
path.push(4);
12241118
next();
12251119
});

0 commit comments

Comments
 (0)