slack-go / slack

Slack API in Go, originally by @nlopes; Maintainers needed, contact @parsley42
https://pkg.go.dev/github.com/slack-go/slack
BSD 2-Clause "Simplified" License
4.6k stars 1.11k forks source link

Webhook Sending Functions Seem to Use the Regular JSON Encoder Which Escapes HTML Characters Unnecessarily #1252

Open zoominGiladSher opened 5 months ago

zoominGiladSher commented 5 months ago

What happened

While working on a Github action to send a release note to a Slack channel I saw that using the PostWebhook function causes the message to have weird characters in Slack due to the HTML escaping. For example, an apostrophe is converted to '.

Expected behavior

JSON marshaller only encodes the relevant characters as defined in the Slack documentation

Steps to reproduce

Send a webhook with an apostrophe in the body of the request. See that the resulting message has an HTML escaped symbol.

reproducible code

package main

import (
    "github.com/slack-go/slack"
)

func main() {
    blocks = new(slack.Blocks)
    blocks.BlockSet = append(blocks.BlockSet, slack.NewSectionBlock(slack.NewTextBlockObject("mrkdwn", "'test' What's up", false, false), nil, nil))
    _ := slack.PostWebhook("<WebhookURL>", &slack.WebhookMessage{Blocks: blocks})
}

manifest.yaml

Not sure what this is?

Versions

zoominGiladSher commented 5 months ago

Extra context: I saw this in https://github.com/slack-go/slack/blob/e7152216dda52317d92b00a08a91e5b776c9a854/webhooks.go#L41-L63 and see that there's no use of the EscapeMessage function mentioned in https://github.com/slack-go/slack/blob/e7152216dda52317d92b00a08a91e5b776c9a854/slackutilsx/slackutilsx.go#L53-L59 Not sure if this is the solution, but this is what I saw from a very shallow look at things. Please let me know if I can help in any way or if you'd like me to try and tackle this myself!