Просмотр исходного кода

fix: address potential regex backtrack

Evan You 8 лет назад
Родитель
Сommit
cd334070f3

+ 2 - 2
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<number> } = {

+ 3 - 1
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
   }

+ 1 - 1
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(
       '<input @input=" onInput ">',
-      `with(this){return _c('input',{on:{"input": onInput }})}`
+      `with(this){return _c('input',{on:{"input":onInput}})}`
     )
   })