From 08ade44dc8a7309187f0be8b06a9e4a2849a773c Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Mon, 13 Jun 2016 21:59:20 +0100 Subject: [PATCH] Handle more edge cases with RED.util.normalisePropertyExpression --- editor/js/ui/typedInput.js | 4 +++- red/runtime/util.js | 5 +++++ test/red/runtime/util_spec.js | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/editor/js/ui/typedInput.js b/editor/js/ui/typedInput.js index 1fd63abc0..710c8cdae 100644 --- a/editor/js/ui/typedInput.js +++ b/editor/js/ui/typedInput.js @@ -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) { diff --git a/red/runtime/util.js b/red/runtime/util.js index 807375e6f..f132564c8 100644 --- a/red/runtime/util.js +++ b/red/runtime/util.js @@ -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) { diff --git a/test/red/runtime/util_spec.js b/test/red/runtime/util_spec.js index 3aad44418..aa8e25728 100644 --- a/test/red/runtime/util_spec.js +++ b/test/red/runtime/util_spec.js @@ -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]"); }) }); });