Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No match path param with ignoreTrailingSlash #146

Merged
merged 5 commits into from Mar 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion index.js
Expand Up @@ -421,7 +421,8 @@ Router.prototype.find = function find (method, path, version) {
return this._getWildcardNode(wildcardNode, method, originalPath, pathLenWildcard)
}

if (originalPath.indexOf('/' + previousPath) === -1) {
var goBack = this.ignoreTrailingSlash ? previousPath : '/' + previousPath
if (originalPath.indexOf(goBack) === -1) {
// we need to know the outstanding path so far from the originalPath since the last encountered "/" and assign it to previousPath.
// e.g originalPath: /aa/bbb/cc, path: bb/cc
// outstanding path: /bbb/cc
Expand Down
24 changes: 24 additions & 0 deletions test/issue-145.test.js
@@ -0,0 +1,24 @@
'use strict'

const t = require('tap')
const FindMyWay = require('../')

t.test('issue-145', (t) => {
t.plan(8)

const findMyWay = FindMyWay({ ignoreTrailingSlash: true })

const fixedPath = function staticPath () {}
const varPath = function parameterPath () {}
findMyWay.on('GET', '/a/b', fixedPath)
findMyWay.on('GET', '/a/:pam/c', varPath)

t.equals(findMyWay.find('GET', '/a/b').handler, fixedPath)
t.equals(findMyWay.find('GET', '/a/b/').handler, fixedPath)
t.equals(findMyWay.find('GET', '/a/b/c').handler, varPath)
t.equals(findMyWay.find('GET', '/a/b/c/').handler, varPath)
t.equals(findMyWay.find('GET', '/a/foo/c').handler, varPath)
t.equals(findMyWay.find('GET', '/a/foo/c/').handler, varPath)
t.notOk(findMyWay.find('GET', '/a/c'))
t.notOk(findMyWay.find('GET', '/a/c/'))
})