@koa/router 9.3.1 → 10.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/layer.js CHANGED
@@ -24,9 +24,9 @@ function Layer(path, methods, middleware, opts) {
24
24
  this.paramNames = [];
25
25
  this.stack = Array.isArray(middleware) ? middleware : [middleware];
26
26
 
27
- for(let i = 0; i < methods.length; i++) {
27
+ for (let i = 0; i < methods.length; i++) {
28
28
  const l = this.methods.push(methods[i].toUpperCase());
29
- if (this.methods[l-1] === 'GET') this.methods.unshift('HEAD');
29
+ if (this.methods[l - 1] === 'GET') this.methods.unshift('HEAD');
30
30
  }
31
31
 
32
32
  // ensure middleware is a function
@@ -68,10 +68,10 @@ Layer.prototype.match = function (path) {
68
68
  Layer.prototype.params = function (path, captures, existingParams) {
69
69
  const params = existingParams || {};
70
70
 
71
- for (let len = captures.length, i=0; i<len; i++) {
71
+ for (let len = captures.length, i = 0; i < len; i++) {
72
72
  if (this.paramNames[i]) {
73
73
  const c = captures[i];
74
- params[this.paramNames[i].name] = c ? safeDecodeURIComponent(c) : c;
74
+ if (c && c.length !== 0) params[this.paramNames[i].name] = c ? safeDecodeURIComponent(c) : c;
75
75
  }
76
76
  }
77
77
 
@@ -125,7 +125,7 @@ Layer.prototype.url = function (params, options) {
125
125
  let replace = {};
126
126
 
127
127
  if (args instanceof Array) {
128
- for (let len = tokens.length, i=0, j=0; i<len; i++) {
128
+ for (let len = tokens.length, i = 0, j = 0; i < len; i++) {
129
129
  if (tokens[i].name) replace[tokens[i].name] = args[j++];
130
130
  }
131
131
  } else if (tokens.some(token => token.name)) {
package/lib/router.js CHANGED
@@ -362,7 +362,7 @@ Router.prototype.routes = Router.prototype.middleware = function () {
362
362
  layerChain = matchedLayers.reduce(function(memo, layer) {
363
363
  memo.push(function(ctx, next) {
364
364
  ctx.captures = layer.captures(path, ctx.captures);
365
- ctx.params = layer.params(path, ctx.captures, ctx.params);
365
+ ctx.params = ctx.request.params = layer.params(path, ctx.captures, ctx.params);
366
366
  ctx.routerPath = layer.path;
367
367
  ctx.routerName = layer.name;
368
368
  ctx._matchedRoute = layer.path;
@@ -532,7 +532,7 @@ Router.prototype.redirect = function (source, destination, code) {
532
532
  if (source[0] !== '/') source = this.url(source);
533
533
 
534
534
  // lookup destination route by name
535
- if (destination[0] !== '/') destination = this.url(destination);
535
+ if (destination[0] !== '/' && !destination.includes('://')) destination = this.url(destination);
536
536
 
537
537
  return this.all(source, ctx => {
538
538
  ctx.redirect(destination);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@koa/router",
3
3
  "description": "Router middleware for koa. Provides RESTful resource routing.",
4
- "version": "9.3.1",
4
+ "version": "10.1.1",
5
5
  "author": "Alex Mingoia <talk@alexmingoia.com>",
6
6
  "bugs": {
7
7
  "url": "https://github.com/koajs/router/issues",