From: dneuschaefer-rube Date: Sun, 27 Dec 2020 14:12:32 +0000 (+0100) Subject: fix(matcher): clear customRe after consuming buffer (#680) X-Git-Tag: v4.0.2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4c0b82507e1f949d55daffd06756615cd704e090;p=thirdparty%2Fvuejs%2Frouter.git fix(matcher): clear customRe after consuming buffer (#680) Fix #679 --- 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: