fix object dot notation bug (fix #4185) (#4188)

* fix object dot notation bug

* add test case
This commit is contained in:
chengchao 2016-11-14 02:15:08 +08:00 committed by Evan You
parent 9931b715cd
commit 46b3bcd707
2 changed files with 13 additions and 1 deletions

View File

@ -116,7 +116,7 @@ export function parseModel (val: string): Object {
len = str.length
index = expressionPos = expressionEndPos = 0
if (val.indexOf('[') < 0) {
if (val.indexOf('[') < 0 || val.lastIndexOf(']') < len - 1) {
return {
exp: val,
idx: null

View File

@ -1,12 +1,24 @@
import { parseModel } from 'compiler/helpers'
describe('model expression parser', () => {
it('parse object dot notation', () => {
const res = parseModel('a.b.c')
expect(res.exp).toBe('a.b.c')
expect(res.idx).toBe(null)
})
it('parse string in brackets', () => {
const res = parseModel('a["b"][c]')
expect(res.exp).toBe('a["b"]')
expect(res.idx).toBe('c')
})
it('parse brackets with object dot notation', () => {
const res = parseModel('a["b"][c].xxx')
expect(res.exp).toBe('a["b"][c].xxx')
expect(res.idx).toBe(null)
})
it('parse nested brackets', () => {
const res = parseModel('a[i[c]]')
expect(res.exp).toBe('a')