Handle more edge cases with RED.util.normalisePropertyExpression

This commit is contained in:
Nick O'Leary 2016-06-13 21:59:20 +01:00
parent 8fb1c76247
commit 08ade44dc8
3 changed files with 11 additions and 1 deletions

View File

@ -32,7 +32,7 @@
quoteChar = c;
start = i+1;
} else if (c === '.') {
if (i===length-1) {
if (i===0 || i===length-1) {
return false;
}
// Next char is a-z
@ -65,6 +65,8 @@
}
start = i+1;
inBox = false;
} else if (c === ' ') {
return false;
}
} else {
if (c === quoteChar) {

View File

@ -146,6 +146,9 @@ function normalisePropertyExpression(str) {
quoteChar = c;
start = i+1;
} else if (c === '.') {
if (i===0) {
throw new Error("Invalid property expression: unexpected . at position 0");
}
if (start != i) {
v = str.substring(start,i);
if (/^\d+$/.test(v)) {
@ -192,6 +195,8 @@ function normalisePropertyExpression(str) {
}
start = i+1;
inBox = false;
} else if (c === ' ') {
throw new Error("Invalid property expression: unexpected ' ' at position "+i);
}
} else {
if (c === quoteChar) {

View File

@ -346,6 +346,9 @@ describe("red/util", function() {
it("fail [0]",function() { testInvalid("[0]"); })
it("fail a[0",function() { testInvalid("a[0"); })
it("fail a.",function() { testInvalid("a."); })
it("fail .a",function() { testInvalid(".a"); })
it("fail a. b",function() { testInvalid("a. b"); })
it("fail a.b",function() { testInvalid(" a.b"); })
it("fail a[0].[1]",function() { testInvalid("a[0].[1]"); })
});
});