diff --git a/lib/layer.js b/lib/layer.js index 6a4408f..3dbf3a8 100644 --- a/lib/layer.js +++ b/lib/layer.js @@ -45,6 +45,8 @@ function Layer (path, options, fn) { this.params = undefined this.path = undefined this.slash = path === '/' && opts.end === false + // Track if path is multiple slashes (like //) which needs special handling + this.multiSlash = /^\/+$/.test(path) && opts.end === false function matcher (_path) { if (_path instanceof RegExp) { @@ -186,6 +188,14 @@ Layer.prototype.match = function match (path) { return true } + // For paths with multiple slashes (like //), match any path that's longer + // This is similar to '/' but excludes exact match + if (this.multiSlash && path.length > 1) { + this.params = {} + this.path = '' + return true + } + let i = 0 while (!match && i < this.matchers.length) { // match the path @@ -241,6 +251,12 @@ function loosen (path) { return path } + // Don't loosen paths that are only slashes (//, ///, etc.) + // These would become empty strings which matches everything + if (/^\/+$/.test(path)) { + return path + } + return Array.isArray(path) ? path.map(function (p) { return loosen(p) }) : String(path).replace(TRAILING_SLASH_REGEXP, '')