Skip to content

Commit

Permalink
Make forAlias regex lazy (fixes vuejs#3846) (vuejs#3859)
Browse files Browse the repository at this point in the history
The current forAliasRE has the first rule greedy (`.*?`), which will
attempt to match whatever it can. This exposes a bug (vuejs#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.
  • Loading branch information
phanan authored and yyx990803 committed Oct 7, 2016
1 parent 463c9c9 commit adae5ca
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/compiler/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '../helpers'

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

0 comments on commit adae5ca

Please sign in to comment.