From b816a4d79669748bb6f6e06a35df3e932d3764d6 Mon Sep 17 00:00:00 2001 From: Matt Edmonston Date: Sat, 14 Nov 2026 05:49:41 +0000 Subject: [PATCH] Escape mrkdwn control characters in the example Slack template Slack requires &, < and > in message text to be escaped. Unescaped, `List` was mangled and a literal `` in piped output would ping the whole channel. Escape subject and message with nested replace calls; no new template function. Fixes #30 --- templates/slack.json.tmpl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/templates/slack.json.tmpl b/templates/slack.json.tmpl index 431c5c0..08196b1 100644 --- a/templates/slack.json.tmpl +++ b/templates/slack.json.tmpl @@ -1,9 +1,11 @@ +{{- $subject := replace (replace (replace .Subject "&" "&") "<" "<") ">" ">" -}} +{{- $message := replace (replace (replace .Message "&" "&") "<" "<") ">" ">" -}} { - "text": {{ json (printf "*%s*\n%s" .Subject .Message) }}, + "text": {{ json (printf "*%s*\n%s" $subject $message) }}, "blocks": [ { "type": "section", - "text": { "type": "mrkdwn", "text": {{ json (printf "*%s*\n%s" .Subject .Message) }} } + "text": { "type": "mrkdwn", "text": {{ json (printf "*%s*\n%s" $subject $message) }} } }, { "type": "context",