From 0ad1b946f478413110d34ed4a95181b1ef1115ba Mon Sep 17 00:00:00 2001 From: Paul Engel Date: Thu, 23 Jun 2022 10:10:37 +0200 Subject: [PATCH] fix: escape functions before "isolated logging" (#318) --- src/functions/testRunner.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/functions/testRunner.ts b/src/functions/testRunner.ts index de9ccaf8..43e4f7fc 100644 --- a/src/functions/testRunner.ts +++ b/src/functions/testRunner.ts @@ -126,11 +126,32 @@ const run = (workingDir: string): Promise => { let failures = 0; const console = (() => { + const escape = (value) => { + switch (typeof(value)) { + case "function": + return value.toString(); + case "object": + if (value == null) { + return value; + } + if (value instanceof Array) { + return value.map(escape); + } else { + return Object.keys(value).reduce((o, k) => { + o[k] = escape(value[k]); + return o; + }, {}); + } + default: + return value; + } + }; + const log = (level) => (...args) => $console.apply(null, [ level, - new ivm.ExternalCopy(args).copyInto() + new ivm.ExternalCopy(escape(args)).copyInto() ]); return {