Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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, '')
Expand Down