fix double-escaping in Slack webhook payloads#2994
Open
unasuke wants to merge 1 commit into
Open
Conversation
Event::Description#to_plain_text HTML-escapes its output, so Slack notifications showed literal entities like " and &basecamp#39;. Slack renders plain text rather than HTML and only wants &, <, and > converted to entities: https://docs.slack.dev/messaging/formatting-message-text/#escaping Undo the HTML escaping with CGI.unescapeHTML, then escape just the three Slack control characters. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts Slack webhook payload generation to avoid double-escaped HTML entities in event descriptions, aligning outbound Slack message text with Slack’s documented escaping rules.
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Changes:
- Update Slack payload text generation to unescape HTML entities and then re-escape only Slack control characters (
&,<,>). - Update/rename the Slack webhook payload test to assert quotes are preserved while Slack control characters are escaped.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| app/models/webhook/delivery.rb | Changes Slack payload text escaping behavior to prevent double-escaped entities in Slack notifications. |
| test/models/webhook/delivery_test.rb | Updates Slack payload expectation and test name to validate the new escaping behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| def slack_payload | ||
| text = event.description_for(nil).to_plain_text | ||
| text = CGI.unescapeHTML(event.description_for(nil).to_plain_text).gsub(/[&<>]/, SLACK_ESCAPE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Event::Description#to_plain_textHTML-escapes its output, so Slack notifications showed literal entities like"and'. Slack renders plain text rather than HTML and only wants&,<, and>converted to entities:https://docs.slack.dev/messaging/formatting-message-text/#escaping
Undo the HTML escaping with
CGI.unescapeHTML, then escape just the three Slack control characters.