From 29d2d0ec620e8ab9d5a7bfb10e0200c7b2de1344 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Mon, 16 Sep 2024 06:37:48 -0700 Subject: [PATCH] Prevent infinite recursion in response tag Closes yaakapp/app#90 --- plugins/template-function-response/src/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/template-function-response/src/index.ts b/plugins/template-function-response/src/index.ts index c0c4f6e4..023707f1 100644 --- a/plugins/template-function-response/src/index.ts +++ b/plugins/template-function-response/src/index.ts @@ -39,7 +39,6 @@ export const plugin: Plugin = { if (httpRequest == null) { return null; } - const renderedHttpRequest = await ctx.httpRequest.render({ httpRequest, purpose: args.purpose }); const responses = await ctx.httpResponse.find({ requestId: httpRequest.id, limit: 1 }); @@ -57,6 +56,8 @@ export const plugin: Plugin = { // Send if no responses and "smart," or "always" if ((behavior === 'smart' && response == null) || behavior === 'always') { + // NOTE: Render inside this conditional, or we'll get infinite recursion (render->render->...) + const renderedHttpRequest = await ctx.httpRequest.render({ httpRequest, purpose: args.purpose }); response = await ctx.httpRequest.send({ httpRequest: renderedHttpRequest }); }