From fc0cf1ff51bea9dea884ef38ee3bbea89c242041 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Sun, 9 Sep 2018 23:47:31 +0100 Subject: [PATCH] Handle context.get with multiple levels of unknown key Fixes #1883 --- red/runtime/nodes/context/localfilesystem.js | 21 +++++++++-- red/runtime/nodes/context/memory.js | 9 ++++- red/runtime/util.js | 36 +++++++++++-------- .../nodes/context/localfilesystem_spec.js | 2 +- test/red/runtime/nodes/context/memory_spec.js | 2 +- 5 files changed, 50 insertions(+), 20 deletions(-) diff --git a/red/runtime/nodes/context/localfilesystem.js b/red/runtime/nodes/context/localfilesystem.js index dc25b6290..548c98c60 100644 --- a/red/runtime/nodes/context/localfilesystem.js +++ b/red/runtime/nodes/context/localfilesystem.js @@ -230,14 +230,31 @@ LocalFileSystem.prototype.get = function(scope, key, callback) { } var storagePath = getStoragePath(this.storageBaseDir ,scope); loadFile(storagePath + ".json").then(function(data){ + var value; if(data){ data = JSON.parse(data); if (!Array.isArray(key)) { - callback(null, util.getObjectProperty(data,key)); + try { + value = util.getObjectProperty(data,key); + } catch(err) { + if (err.code === "INVALID_EXPR") { + throw err; + } + value = undefined; + } + callback(null, value); } else { var results = [undefined]; for (var i=0;i