From 30104fb7495e913349a586c88af1d333101957ea Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Thu, 4 Dec 2025 09:38:24 +0000 Subject: [PATCH] fix: escape backticks and special chars in commit message for GitHub Action (#1928) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `issue-closed-comment` workflow fails when commit messages contain backticks because they're interpolated directly into JS template strings, breaking syntax. ### Changes - Escape backslashes, backticks, and `${` sequences before setting the commit message output - Order matters: backslashes first to avoid interfering with subsequent escaping ```javascript // Before: raw message breaks template string if it contains backticks core.setOutput('commit_message', commit.message); // After: properly escaped for safe interpolation const escapedMessage = commit.message.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\$\{/g, '\\${'); core.setOutput('commit_message', escapedMessage); ```
Original prompt > the github action which comments on issue closure fails when the commit message contains ` since these are js strings. Make sure to escape them.
--- ✨ Let Copilot coding agent [set things up for you](https://github.com/go-vikunja/vikunja/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: kolaente <13721712+kolaente@users.noreply.github.com> --- .github/workflows/issue-closed-comment.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/issue-closed-comment.yml b/.github/workflows/issue-closed-comment.yml index bea189c8f..dcec78aa8 100644 --- a/.github/workflows/issue-closed-comment.yml +++ b/.github/workflows/issue-closed-comment.yml @@ -53,7 +53,9 @@ jobs: core.setOutput('closed_by_commit', 'true'); core.setOutput('commit_sha', commitId); - core.setOutput('commit_message', commit.message); + // Escape backslashes, backticks and ${ to prevent breaking JS template strings + const escapedMessage = commit.message.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\$\{/g, '\\${'); + core.setOutput('commit_message', escapedMessage); core.setOutput('commit_url', closedEvent.commit_url); } else { console.log(`ℹ️ Issue #${issueNumber} was closed manually (not by commit)`);