Skip to content

Commit

Permalink
fix: fix matching with strictTrailingSlash option
Browse files Browse the repository at this point in the history
  • Loading branch information
troch committed Mar 26, 2018
1 parent 470b2a5 commit 353ecc0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
6 changes: 5 additions & 1 deletion modules/Path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ const identity = (_: any): any => _
const exists = val => val !== undefined && val !== null

const optTrailingSlash = (source, strictTrailingSlash) => {
if (!strictTrailingSlash) {
if (strictTrailingSlash) {
return source
}

if (source === '\\/') {
return source
}

Expand Down
15 changes: 6 additions & 9 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,20 +222,17 @@ describe('Path', function() {

it('should match paths with optional trailing slashes', function() {
let path = new Path('/my-path')
should.not.exist(path.test('/my-path/'))
path.test('/my-path/', { strictTrailingSlash: true }).should.eql({})
path.test('/my-path/', { strictTrailingSlash: 1 }).should.eql({})
should.not.exist(path.test('/my-path/', { strictTrailingSlash: true }))
path.test('/my-path/', { strictTrailingSlash: false }).should.eql({})

path = new Path('/my-path/')
should.not.exist(path.test('/my-path'))
path.test('/my-path', { strictTrailingSlash: true }).should.eql({})
path.test('/my-path', { strictTrailingSlash: 1 }).should.eql({})
should.not.exist(path.test('/my-path', { strictTrailingSlash: true }))
path.test('/my-path', { strictTrailingSlash: false }).should.eql({})

path = new Path('/')
should.not.exist(path.test(''))
should.not.exist(path.partialTest(''))
should.not.exist(path.test('', { strictTrailingSlash: true }))
should.not.exist(path.test('', { strictTrailingSlash: false }))
path.test('/', { strictTrailingSlash: true }).should.eql({})
path.test('', { strictTrailingSlash: 1 }).should.eql({})
})

it('should match paths with encoded values', function() {
Expand Down

0 comments on commit 353ecc0

Please sign in to comment.