Skip to content

Commit

Permalink
deps: path-to-regexp@0.1.6
Browse files Browse the repository at this point in the history
fixes #2491
fixes #2617
closes #2637
closes #2683
  • Loading branch information
blakeembrey authored and dougwilson committed Jun 19, 2015
1 parent e66bb4f commit 60e2008
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 13 deletions.
4 changes: 3 additions & 1 deletion History.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ unreleased

* Fix `res.format` error when only `default` provided
* Fix issue where `next('route')` in `app.param` would incorrectly skip values
* Fix using `*` before params in routes
* Fix using capture groups before params in routes
* Use `array-flatten` module for flattening arrays
* deps: accepts@~1.2.9
- deps: mime-types@~2.1.1
Expand Down Expand Up @@ -36,7 +38,7 @@ unreleased
- Add defined behavior for HTTP `CONNECT` requests
- Add defined behavior for HTTP `Upgrade` requests
- deps: ee-first@1.1.1
* deps: path-to-regexp@0.1.4
* deps: path-to-regexp@0.1.6
* deps: send@0.13.0
- Allow Node.js HTTP server to set `Date` response header
- Fix incorrectly removing `Content-Location` on 304 response
Expand Down
16 changes: 5 additions & 11 deletions lib/router/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,11 @@ Layer.prototype.match = function match(path) {

var keys = this.keys;
var params = this.params;
var prop;
var n = 0;
var key;
var val;

for (var i = 1, len = m.length; i < len; ++i) {
key = keys[i - 1];
prop = key
? key.name
: n++;
val = decode_param(m[i]);

for (var i = 1; i < m.length; i++) {
var key = keys[i - 1];
var prop = key.name;
var val = decode_param(m[i]);

if (val !== undefined || !(hasOwnProperty.call(params, prop))) {
params[prop] = val;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"methods": "~1.1.1",
"on-finished": "~2.3.0",
"parseurl": "~1.3.0",
"path-to-regexp": "0.1.4",
"path-to-regexp": "0.1.6",
"proxy-addr": "~1.0.8",
"qs": "2.4.2",
"range-parser": "~1.0.2",
Expand Down
41 changes: 41 additions & 0 deletions test/app.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,30 @@ describe('app.router', function(){
.get('/file')
.expect(404, done);
})

it('should keep correct parameter indexes', function(done){
var app = express();

app.get('/*/user/:id', function (req, res) {
res.send(req.params);
});

request(app)
.get('/1/user/2')
.expect(200, '{"0":"1","id":"2"}', done);
})

it('should work within arrays', function(done){
var app = express();

app.get(['/user/:id', '/foo/*', '/:bar'], function (req, res) {
res.send(req.params.bar);
});

request(app)
.get('/test')
.expect(200, 'test', done);
})
})

describe(':name', function(){
Expand Down Expand Up @@ -680,6 +704,23 @@ describe('app.router', function(){
.expect('editing tj', done);
})

it('should work following a partial capture group', function(done){
var app = express();
var cb = after(2, done);

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

request(app)
.get('/user/tj/edit')
.expect('editing tj', cb);

request(app)
.get('/users/tj/edit')
.expect('editing tj (old)', cb);
})

it('should work in array of paths', function(done){
var app = express();
var cb = after(2, done);
Expand Down

0 comments on commit 60e2008

Please sign in to comment.