Skip to content

Commit e6dbfb9

Browse files
author
An Phan
committed
Make forAlias regex lazy (fixes #3846)
The current forAliasRE has the first rule greedy (`.*?`), which will attempt to match whatever it can. This exposes a bug (#3846), where the regex fails if the template happens to have " in " or " of " in its last group. For instance, with the template `for key in [{body: 'Hey in body'}]`, current regex will capture the last group as `body'}]` instead of `[{body: 'Hey in body'}]`. This commit aims to fix this issue by making the first rule lazy instead.
1 parent c2e6bf8 commit e6dbfb9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/compiler/parser/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from '../helpers'
1717

1818
export const dirRE = /^v-|^@|^:/
19-
export const forAliasRE = /(.*)\s+(?:in|of)\s+(.*)/
19+
export const forAliasRE = /(.*?)\s+(?:in|of)\s+(.*)/
2020
export const forIteratorRE = /\(([^,]*),([^,]*)(?:,([^,]*))?\)/
2121
const bindRE = /^:|^v-bind:/
2222
const onRE = /^@|^v-on:/

0 commit comments

Comments
 (0)