From 73a41707e54982b1b7a57e0eeb918274517b94b0 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Fri, 6 Jan 2017 21:58:17 +0000 Subject: [PATCH] Property expressions must not be blank --- editor/js/ui/utils.js | 3 +++ red/runtime/util.js | 3 +++ test/red/runtime/util_spec.js | 1 + 3 files changed, 7 insertions(+) diff --git a/editor/js/ui/utils.js b/editor/js/ui/utils.js index 60303fd3c..d86f1d599 100644 --- a/editor/js/ui/utils.js +++ b/editor/js/ui/utils.js @@ -284,6 +284,9 @@ RED.utils = (function() { // in red/runtime/util.js var length = str.length; + if (length === 0) { + return false; + } var start = 0; var inString = false; var inBox = false; diff --git a/red/runtime/util.js b/red/runtime/util.js index 38177e3b4..563949c1b 100644 --- a/red/runtime/util.js +++ b/red/runtime/util.js @@ -133,6 +133,9 @@ function normalisePropertyExpression(str) { // in editor/js/ui/utils.js var length = str.length; + if (length === 0) { + throw new Error("Invalid property expression: zero-length"); + } var parts = []; var start = 0; var inString = false; diff --git a/test/red/runtime/util_spec.js b/test/red/runtime/util_spec.js index c5772d38f..d681f1917 100644 --- a/test/red/runtime/util_spec.js +++ b/test/red/runtime/util_spec.js @@ -361,6 +361,7 @@ describe("red/util", function() { it("fail a[0].[1]",function() { testInvalid("a[0].[1]"); }) it("fail a['']",function() { testInvalid("a['']"); }) it("fail 'a.b'c",function() { testInvalid("'a.b'c"); }) + it("fail ",function() { testInvalid("");}) }); });