From cd334070f3b82d3f5892c4999cc290ccd4f56fd8 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 21 Feb 2018 13:11:11 -0500 Subject: [PATCH] fix: address potential regex backtrack --- src/compiler/codegen/events.js | 4 ++-- src/compiler/helpers.js | 4 +++- test/unit/modules/compiler/codegen.spec.js | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/compiler/codegen/events.js b/src/compiler/codegen/events.js index 2b53c2333fd..722e32a4d60 100644 --- a/src/compiler/codegen/events.js +++ b/src/compiler/codegen/events.js @@ -1,7 +1,7 @@ /* @flow */ -const fnExpRE = /^\s*([\w$_]+|\([^)]*?\))\s*=>|^function\s*\(/ -const simplePathRE = /^\s*[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['.*?']|\[".*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*\s*$/ +const fnExpRE = /^([\w$_]+|\([^)]*?\))\s*=>|^function\s*\(/ +const simplePathRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*$/ // keyCode aliases const keyCodes: { [key: string]: number | Array } = { diff --git a/src/compiler/helpers.js b/src/compiler/helpers.js index 1d1feddbf01..6a7375a3080 100644 --- a/src/compiler/helpers.js +++ b/src/compiler/helpers.js @@ -100,7 +100,9 @@ export function addHandler ( events = el.events || (el.events = {}) } - const newHandler: any = { value } + const newHandler: any = { + value: value.trim() + } if (modifiers !== emptyObject) { newHandler.modifiers = modifiers } diff --git a/test/unit/modules/compiler/codegen.spec.js b/test/unit/modules/compiler/codegen.spec.js index b1085a571df..745ef33c228 100644 --- a/test/unit/modules/compiler/codegen.spec.js +++ b/test/unit/modules/compiler/codegen.spec.js @@ -428,7 +428,7 @@ describe('codegen', () => { it('should not treat handler with unexpected whitespace as inline statement', () => { assertCodegen( '', - `with(this){return _c('input',{on:{"input": onInput }})}` + `with(this){return _c('input',{on:{"input":onInput}})}` ) })