From 4c0b82507e1f949d55daffd06756615cd704e090 Mon Sep 17 00:00:00 2001 From: dneuschaefer-rube Date: Sun, 27 Dec 2020 15:12:32 +0100 Subject: [PATCH] fix(matcher): clear customRe after consuming buffer (#680) Fix #679 --- __tests__/matcher/pathParser.spec.ts | 23 +++++++++++++++++++++++ src/matcher/pathTokenizer.ts | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/__tests__/matcher/pathParser.spec.ts b/__tests__/matcher/pathParser.spec.ts index b897243b..f9b9be8b 100644 --- a/__tests__/matcher/pathParser.spec.ts +++ b/__tests__/matcher/pathParser.spec.ts @@ -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([ [ diff --git a/src/matcher/pathTokenizer.ts b/src/matcher/pathTokenizer.ts index 6c173de2..65795d18 100644 --- a/src/matcher/pathTokenizer.ts +++ b/src/matcher/pathTokenizer.ts @@ -147,7 +147,6 @@ export function tokenizePath(path: string): Array { case TokenizerState.Param: if (char === '(') { state = TokenizerState.ParamRegExp - customRe = '' } else if (VALID_PARAM_RE.test(char)) { addCharToBuffer() } else { @@ -180,6 +179,7 @@ export function tokenizePath(path: string): Array { state = TokenizerState.Static // go back one character if we were not modifying if (char !== '*' && char !== '?' && char !== '+') i-- + customRe = '' break default: -- 2.47.3