Skip to content

Commit 338df8c

Browse files
jjuutilatroch
authored andcommitted
fix: fix TypeError when there is no match for path
1 parent 965062d commit 338df8c

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

modules/matchChildren.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,12 @@ const matchChildren = (
6060

6161
// Can't create a regexp from the path because it might contain a
6262
// regexp character.
63-
if (segment.toLowerCase().indexOf(consumedPath.toLowerCase()) === 0) {
63+
if (
64+
segment.toLowerCase().indexOf(consumedPath.toLowerCase()) === 0
65+
) {
6466
remainingPath = segment.slice(consumedPath.length)
67+
} else {
68+
remainingPath = segment
6569
}
6670

6771
if (!strictTrailingSlash && !child.children.length) {

test/main.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,14 +775,28 @@ describe('RouteNode', function() {
775775
allowNotFound: true,
776776
trailingSlashMode: 'never',
777777
queryParamsMode: 'loose',
778-
queryParams: {nullFormat: 'hidden'}
778+
queryParams: { nullFormat: 'hidden' }
779779
}
780780
const node = new RouteNode('', '', routes)
781781
node.matchPath('/foo+bar/AB1234.html', options).params.should.eql({
782782
id: 'AB1234',
783783
name: 'foo+bar'
784784
})
785785
})
786+
787+
it('should return null if there is no match', () => {
788+
const routes = [
789+
{
790+
name: 'page',
791+
path: '/:name<.+>'
792+
}
793+
]
794+
const options = {
795+
allowNotFound: true
796+
}
797+
const node = new RouteNode('', '', routes)
798+
should(node.matchPath('/foobar%24', options)).be.null()
799+
})
786800
})
787801

788802
function getRoutes(trailingSlash) {

0 commit comments

Comments
 (0)