Skip to content

Commit

Permalink
🐛 bug(path): fix array path syntax error
Browse files Browse the repository at this point in the history
Closes #42 #43
  • Loading branch information
kazupon committed Aug 15, 2016
1 parent b001dd5 commit bc9dbee
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,33 @@ pathStateMachine[IN_DOUBLE_QUOTE] = {
'else': [IN_DOUBLE_QUOTE, APPEND]
}

/**
* Check if an expression is a literal value.
*
* @param {String} exp
* @return {Boolean}
*/

const literalValueRE = /^\s?(true|false|-?[\d\.]+|'[^']*'|"[^"]*")\s?$/
function isLiteral (exp) {
return literalValueRE.test(exp)
}

/**
* Strip quotes from a string
*
* @param {String} str
* @return {String | false}
*/

function stripQuotes (str) {
const a = str.charCodeAt(0)
const b = str.charCodeAt(str.length - 1)
return a === b && (a === 0x22 || a === 0x27)
? str.slice(1, -1)
: str
}

/**
* Determine the type of a character in a keypath.
*
Expand Down Expand Up @@ -133,8 +160,6 @@ function getPathCharType (ch) {
*/

function formatSubPath (path) {
const { isLiteral, stripQuotes } = exports.Vue.util

const trimmed = path.trim()
// invalid leading 0
if (path.charAt(0) === '0' && isNaN(path)) { return false }
Expand Down
9 changes: 9 additions & 0 deletions test/specs/issues.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,13 @@ describe('issues', () => {
)
})
})

describe('#42, #43', () => {
it('should not be occured error', () => {
assert.equal(
vm.$t('message[\'hello\']'),
locales[Vue.config.lang]['message']['hello']
)
})
})
})

0 comments on commit bc9dbee

Please sign in to comment.