Skip to content

Commit adae5ca

Browse files
phananyyx990803
authored andcommitted
Make forAlias regex lazy (fixes #3846) (#3859)
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 463c9c9 commit adae5ca

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)