Browse Source

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.
dev
Phan An 8 years ago
committed by Evan You
parent
commit
adae5caaee
  1. 2
      src/compiler/parser/index.js

2
src/compiler/parser/index.js

@ -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:/

Loading…
Cancel
Save