From e6dbfb9a213be68808a07cafd6f0fe4dbec0f877 Mon Sep 17 00:00:00 2001 From: An Phan Date: Thu, 6 Oct 2016 12:30:18 +0800 Subject: [PATCH] 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. --- src/compiler/parser/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/parser/index.js b/src/compiler/parser/index.js index 7f3746d0add..9b246236c1c 100644 --- a/src/compiler/parser/index.js +++ b/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:/