]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
fix(matcher): clear customRe after consuming buffer (#680)
authordneuschaefer-rube <daniel.neuschaefer@gmail.com>
Sun, 27 Dec 2020 14:12:32 +0000 (15:12 +0100)
committerGitHub <noreply@github.com>
Sun, 27 Dec 2020 14:12:32 +0000 (15:12 +0100)
Fix #679

__tests__/matcher/pathParser.spec.ts
src/matcher/pathTokenizer.ts

index b897243bbd4e340e7dc43957d8fc886eea0b6c44..f9b9be8b2f634f14a9c7a0a8e929d2afaf8ca45a 100644 (file)
@@ -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([
         [
index 6c173de2120a8bfa71d85f561431d1b6fa145294..65795d18d14be06f76ce24ad2bf279429654f1f5 100644 (file)
@@ -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 {
@@ -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: