Skip to content

Commit

Permalink
Fix additional entry inejcted to params (#124)
Browse files Browse the repository at this point in the history
* fix additional entry inejcted to params ..

* add unit test for this case ..
  • Loading branch information
3imed-jaberi authored Jul 20, 2021
1 parent 344ba0b commit e9fa04b
Show file tree
Hide file tree
Showing 2 changed files with 458 additions and 430 deletions.
10 changes: 5 additions & 5 deletions lib/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ function Layer(path, methods, middleware, opts) {
this.paramNames = [];
this.stack = Array.isArray(middleware) ? middleware : [middleware];

for(let i = 0; i < methods.length; i++) {
for (let i = 0; i < methods.length; i++) {
const l = this.methods.push(methods[i].toUpperCase());
if (this.methods[l-1] === 'GET') this.methods.unshift('HEAD');
if (this.methods[l - 1] === 'GET') this.methods.unshift('HEAD');
}

// ensure middleware is a function
Expand Down Expand Up @@ -68,10 +68,10 @@ Layer.prototype.match = function (path) {
Layer.prototype.params = function (path, captures, existingParams) {
const params = existingParams || {};

for (let len = captures.length, i=0; i<len; i++) {
for (let len = captures.length, i = 0; i < len; i++) {
if (this.paramNames[i]) {
const c = captures[i];
params[this.paramNames[i].name] = c ? safeDecodeURIComponent(c) : c;
if (c && c.length !== 0) params[this.paramNames[i].name] = c ? safeDecodeURIComponent(c) : c;
}
}

Expand Down Expand Up @@ -125,7 +125,7 @@ Layer.prototype.url = function (params, options) {
let replace = {};

if (args instanceof Array) {
for (let len = tokens.length, i=0, j=0; i<len; i++) {
for (let len = tokens.length, i = 0, j = 0; i < len; i++) {
if (tokens[i].name) replace[tokens[i].name] = args[j++];
}
} else if (tokens.some(token => token.name)) {
Expand Down
Loading

0 comments on commit e9fa04b

Please sign in to comment.