Skip to content

Commit

Permalink
fix(matcher): clear customRe after consuming buffer (#680)
Browse files Browse the repository at this point in the history
Fix #679
  • Loading branch information
dneuschaefer-rube committed Dec 27, 2020
1 parent 8f93a5c commit 4c0b825
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions __tests__/matcher/pathParser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,29 @@ describe('Path parser', () => {
])
})

it('param custom re followed by param without regex', () => {
expect(tokenizePath('/:one(\\d+)/:two')).toEqual([
[
{
type: TokenType.Param,
value: 'one',
regexp: '\\d+',
repeatable: false,
optional: false,
},
],
[
{
type: TokenType.Param,
value: 'two',
regexp: '',
repeatable: false,
optional: false,
},
],
])
})

it('param custom re?', () => {
expect(tokenizePath('/:id(\\d+)?')).toEqual([
[
Expand Down
2 changes: 1 addition & 1 deletion src/matcher/pathTokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ export function tokenizePath(path: string): Array<Token[]> {
case TokenizerState.Param:
if (char === '(') {
state = TokenizerState.ParamRegExp
customRe = ''
} else if (VALID_PARAM_RE.test(char)) {
addCharToBuffer()
} else {
Expand Down Expand Up @@ -180,6 +179,7 @@ export function tokenizePath(path: string): Array<Token[]> {
state = TokenizerState.Static
// go back one character if we were not modifying
if (char !== '*' && char !== '?' && char !== '+') i--
customRe = ''
break

default:
Expand Down

0 comments on commit 4c0b825

Please sign in to comment.