Handle context.get with multiple levels of unknown key

Fixes #1883
This commit is contained in:
Nick O'Leary
2018-09-09 23:47:31 +01:00
parent 0f4d46671f
commit fc0cf1ff51
5 changed files with 50 additions and 20 deletions

View File

@@ -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<key.length;i++) {
results.push(util.getObjectProperty(data,key[i]))
try {
value = util.getObjectProperty(data,key[i]);
} catch(err) {
if (err.code === "INVALID_EXPR") {
throw err;
}
value = undefined;
}
results.push(value)
}
callback.apply(null,results);
}

View File

@@ -32,7 +32,14 @@ Memory.prototype._getOne = function(scope, key) {
var value;
var error;
if(this.data[scope]){
value = util.getObjectProperty(this.data[scope], key);
try {
value = util.getObjectProperty(this.data[scope], key);
} catch(err) {
if (err.code === "INVALID_EXPR") {
throw err;
}
value = undefined;
}
}
return value;
}