Allow quoted property expressions

Fixes #1101
This commit is contained in:
Nick O'Leary
2017-01-06 11:23:19 +00:00
parent 08b11addec
commit 0c7705beff
6 changed files with 105 additions and 78 deletions

View File

@@ -129,6 +129,9 @@ function compareObjects(obj1,obj2) {
}
function normalisePropertyExpression(str) {
// This must be kept in sync with validatePropertyExpression
// in editor/js/ui/utils.js
var length = str.length;
var parts = [];
var start = 0;
@@ -140,7 +143,7 @@ function normalisePropertyExpression(str) {
var c = str[i];
if (!inString) {
if (c === "'" || c === '"') {
if (!inBox) {
if (i != start) {
throw new Error("Invalid property expression: unexpected "+c+" at position "+i);
}
inString = true;
@@ -201,10 +204,15 @@ function normalisePropertyExpression(str) {
}
} else {
if (c === quoteChar) {
if (i-start === 0) {
throw new Error("Invalid property expression: zero-length string at position "+start);
}
parts.push(str.substring(start,i));
// Next char must be a ]
if (!/\]/.test(str[i+1])) {
// If inBox, next char must be a ]. Otherwise it may be [ or .
if (inBox && !/\]/.test(str[i+1])) {
throw new Error("Invalid property expression: unexpected array expression at position "+start);
} else if (!inBox && i+1!==length && !/[\[\.]/.test(str[i+1])) {
throw new Error("Invalid property expression: unexpected "+str[i+1]+" expression at position "+(i+1));
}
start = i+1;
inString = false;