mirror of
https://gitee.com/vuejs/vue.git
synced 2024-12-04 21:17:55 +08:00
* fix object dot notation bug * add test case
This commit is contained in:
parent
9931b715cd
commit
46b3bcd707
@ -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
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user