Skip to content

Commit 4c0b825

Browse files
fix(matcher): clear customRe after consuming buffer (vuejs#680)
Fix vuejs#679
1 parent 8f93a5c commit 4c0b825

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

__tests__/matcher/pathParser.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,29 @@ describe('Path parser', () => {
147147
])
148148
})
149149

150+
it('param custom re followed by param without regex', () => {
151+
expect(tokenizePath('/:one(\\d+)/:two')).toEqual([
152+
[
153+
{
154+
type: TokenType.Param,
155+
value: 'one',
156+
regexp: '\\d+',
157+
repeatable: false,
158+
optional: false,
159+
},
160+
],
161+
[
162+
{
163+
type: TokenType.Param,
164+
value: 'two',
165+
regexp: '',
166+
repeatable: false,
167+
optional: false,
168+
},
169+
],
170+
])
171+
})
172+
150173
it('param custom re?', () => {
151174
expect(tokenizePath('/:id(\\d+)?')).toEqual([
152175
[

src/matcher/pathTokenizer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ export function tokenizePath(path: string): Array<Token[]> {
147147
case TokenizerState.Param:
148148
if (char === '(') {
149149
state = TokenizerState.ParamRegExp
150-
customRe = ''
151150
} else if (VALID_PARAM_RE.test(char)) {
152151
addCharToBuffer()
153152
} else {
@@ -180,6 +179,7 @@ export function tokenizePath(path: string): Array<Token[]> {
180179
state = TokenizerState.Static
181180
// go back one character if we were not modifying
182181
if (char !== '*' && char !== '?' && char !== '+') i--
182+
customRe = ''
183183
break
184184

185185
default:

0 commit comments

Comments
 (0)