From 335d38f6278e96c908b24183f1c9c90afc8ae00c Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 29 Feb 2024 00:54:29 +0000 Subject: [PATCH] Check for constructor property --- src/jsonata.js | 2 +- test/implementation-tests.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/jsonata.js b/src/jsonata.js index 199b7dfc..b7dfad53 100644 --- a/src/jsonata.js +++ b/src/jsonata.js @@ -1293,7 +1293,7 @@ var jsonata = (function() { } for(var ii = 0; ii < matches.length; ii++) { var match = matches[ii]; - if (match && match.isPrototypeOf(result)) { + if (match && (match.isPrototypeOf(result) || match instanceof Object.constructor)) { throw { code: "D1010", stack: (new Error()).stack, diff --git a/test/implementation-tests.js b/test/implementation-tests.js index ace6efe5..6df7e679 100644 --- a/test/implementation-tests.js +++ b/test/implementation-tests.js @@ -974,6 +974,15 @@ describe("Tests that are specific to a Javascript runtime", () => { code: "D1010", }); }); + it("should throw an error with constructor", async function() { + const expr = jsonata('{} ~> | constructor | {"is_admin": true} |'); + expect( + expr.evaluate() + ).to.eventually.be.rejected.to.deep.contain({ + position: 7, + code: "D1010", + }); + }); }); });