From 929f19f1974b7d64e50b42078e1bc8b8aa2ba6d4 Mon Sep 17 00:00:00 2001 From: andrew-coleman Date: Thu, 9 May 2024 08:59:20 +0100 Subject: [PATCH] Prevent lookup of function object properties A lambda function is represented internally as a javascript object. A check needs to be added to the `lookup` function to only expose properties if they are a non-function object. Similar to the check that already exists in the `keys` function. Signed-off-by: andrew-coleman --- src/functions.js | 4 ++-- test/test-suite/groups/lambdas/case013.json | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 test/test-suite/groups/lambdas/case013.json diff --git a/src/functions.js b/src/functions.js index 219a3904..d493c946 100644 --- a/src/functions.js +++ b/src/functions.js @@ -1658,7 +1658,7 @@ const functions = (() => { }); }); result = keys(merge); - } else if (arg !== null && typeof arg === 'object' && !(isLambda(arg))) { + } else if (arg !== null && typeof arg === 'object' && !isFunction(arg)) { Object.keys(arg).forEach(key => result.push(key)); } return result; @@ -1685,7 +1685,7 @@ const functions = (() => { } } } - } else if (input !== null && typeof input === 'object') { + } else if (input !== null && typeof input === 'object' && !isFunction(input)) { result = input[key]; } return result; diff --git a/test/test-suite/groups/lambdas/case013.json b/test/test-suite/groups/lambdas/case013.json new file mode 100644 index 00000000..01ef8677 --- /dev/null +++ b/test/test-suite/groups/lambdas/case013.json @@ -0,0 +1,6 @@ +{ + "expr": "( $f := function(){1}; $f.environment )", + "dataset": null, + "bindings": {}, + "undefinedResult": true +} \ No newline at end of file