From 5c0c8cb268857c301ca47e79822f1915944b2ee8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 29 Jul 2026 08:54:29 +0000 Subject: [PATCH] Fix render_template.cjs merging lines around removed falsy conditional blocks When a {{#if false}}...{{/if}} block on its own lines was removed, both the leading and trailing newline were dropped, silently joining the line before the block to the line after it (e.g. "Line1\n{{#if false}}...{{/if}}\nLine2" became "Line1Line2" instead of "Line1\nLine2"). The kept-branch already preserved the leading newline; the removed-branch now does the same. --- actions/setup/js/render_template.cjs | 6 +++++- actions/setup/js/render_template.test.cjs | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/actions/setup/js/render_template.cjs b/actions/setup/js/render_template.cjs index 162a07c97bd..c90f039c8a6 100644 --- a/actions/setup/js/render_template.cjs +++ b/actions/setup/js/render_template.cjs @@ -73,7 +73,11 @@ function renderMarkdownTemplate(markdown) { } else { removedBlocks++; core.info(`[renderMarkdownTemplate] Action: Removing entire block`); - return ""; + // Keep the leading newline so the line before the block stays separated + // from the line after it (the closing tag's trailing newline is already + // consumed by the match). Dropping it merges unrelated lines together, + // e.g. "Before\n{{#if false}}...{{/if}}\nAfter" -> "BeforeAfter". + return leadNL; } }); diff --git a/actions/setup/js/render_template.test.cjs b/actions/setup/js/render_template.test.cjs index 171686cd50e..819e7f68f4e 100644 --- a/actions/setup/js/render_template.test.cjs +++ b/actions/setup/js/render_template.test.cjs @@ -52,6 +52,10 @@ describe("renderMarkdownTemplate", () => { const output = renderMarkdownTemplate("Start\n\n{{#if false}}\nBlock 1\n{{/if}}\n\n{{#if false}}\nBlock 2\n{{/if}}\n\n{{#if false}}\nBlock 3\n{{/if}}\n\nEnd"); (expect(output).not.toMatch(/\n{3,}/), expect(output).toContain("Start"), expect(output).toContain("End")); }), + it("should not merge the surrounding lines when a single-newline-separated falsy block is removed", () => { + const output = renderMarkdownTemplate("Line1\n{{#if false}}\nRemoved\n{{/if}}\nLine2\n"); + expect(output).toBe("Line1\nLine2\n"); + }), it("should preserve leading spaces with truthy block", () => { const output = renderMarkdownTemplate(" {{#if true}}\n Content with leading spaces\n {{/if}}"); expect(output).toBe(" Content with leading spaces\n");