diff --git a/src/compiler/parser/filter-parser.js b/src/compiler/parser/filter-parser.js index b63fa408..dd2989c1 100644 --- a/src/compiler/parser/filter-parser.js +++ b/src/compiler/parser/filter-parser.js @@ -55,7 +55,7 @@ export function parseFilters (exp: string): string { p = exp.charAt(j) if (p !== ' ') break } - if (!p || !/[\w$]/.test(p)) { + if (!p || !/[\w).\]\+\-\_$]/.test(p)) { inRegex = true } } diff --git a/test/unit/features/filter/filter.spec.js b/test/unit/features/filter/filter.spec.js index 2a506dce..1fd6ee3a 100644 --- a/test/unit/features/filter/filter.spec.js +++ b/test/unit/features/filter/filter.spec.js @@ -78,6 +78,68 @@ describe('Filters', () => { expect(vm.$el.textContent).toBe(String(1 / 4)) }) + it('handle division with parenthesis', () => { + const vm = new Vue({ + data: { a: 20 }, + template: `
{{ (a*2) / 5 | double }}
`, + filters: { double: v => v * 2 } + }).$mount() + expect(vm.$el.textContent).toBe(String(16)) + }) + + it('handle division with dot', () => { + const vm = new Vue({ + template: `
{{ 20. / 5 | double }}
`, + filters: { double: v => v * 2 } + }).$mount() + expect(vm.$el.textContent).toBe(String(8)) + }) + + it('handle division with array values', () => { + const vm = new Vue({ + data: { a: [20] }, + template: `
{{ a[0] / 5 | double }}
`, + filters: { double: v => v * 2 } + }).$mount() + expect(vm.$el.textContent).toBe(String(8)) + }) + + it('handle division with hash values', () => { + const vm = new Vue({ + data: { a: { n: 20 }}, + template: `
{{ a['n'] / 5 | double }}
`, + filters: { double: v => v * 2 } + }).$mount() + expect(vm.$el.textContent).toBe(String(8)) + }) + + it('handle division with variable++', () => { + const vm = new Vue({ + data: { a: 7 }, + template: `
{{ a++ / 2 | double }}
`, + filters: { double: v => v * 2 } + }).$mount() + expect(vm.$el.textContent).toBe(String(7)) + }) + + it('handle division with variable--', () => { + const vm = new Vue({ + data: { a: 7 }, + template: `
{{ a++ / 2 | double }}
`, + filters: { double: v => v * 2 } + }).$mount() + expect(vm.$el.textContent).toBe(String(7)) + }) + + it('handle division with variable_', () => { + const vm = new Vue({ + data: { a_: 8 }, + template: `
{{ a_ / 2 | double }}
`, + filters: { double: v => v * 2 } + }).$mount() + expect(vm.$el.textContent).toBe(String(8)) + }) + it('arguments', () => { const vm = new Vue({ template: `
{{ msg | add(a, 3) }}
`,