diff --git a/libs/match-route.ts b/libs/match-route.ts index 4760d63..0e7587d 100644 --- a/libs/match-route.ts +++ b/libs/match-route.ts @@ -19,7 +19,7 @@ function matchRoute(pattern: string, path: string): RouteArgs { } if (flag === '+') { - parsedArgs[name] = path.slice(parsedPathSegment.index) + parsedArgs[name] = path.slice(parsedPathSegment.index + 1) return parsedArgs } diff --git a/test/match-route.unit.ts b/test/match-route.unit.ts index b10702f..192e8e9 100644 --- a/test/match-route.unit.ts +++ b/test/match-route.unit.ts @@ -34,15 +34,17 @@ tap.test(testRouteMultiRegex, t => { runTest(t, testRouteMultiRegex, suite) }) -const testRoutePlusSegment = '/david/:topic/:user/:repo/:path+' +const testRoutePlusSegment = '/david/:topic/:path+' tap.test(testRoutePlusSegment, t => { const suite = { - '/david/dep/babel/babel': null, - '/david/dep/babel/babel/packages/babel-cli': { + '/david/dep': null, + '/david/dep/packages/babel-cli': { topic: 'dep', - user: 'babel', - repo: 'babel', - path: '/packages/babel-cli' + path: 'packages/babel-cli' + }, + '/david/dep/https://eiyo.com': { + topic: 'dep', + path: 'https://eiyo.com' } } runTest(t, testRoutePlusSegment, suite)