mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-23 19:47:07 +09:00
Backport #39650 by @Kshot3000 Since the Telegram webhook switched to Bot API rich messages (https://github.com/go-gitea/gitea/pull/38298), a bare newline in `rich_message.html` is treated as insignificant whitespace, so multi-line messages — issue and PR bodies, comments, push commit lists — arrive in Telegram as a single paragraph. This restores the old layout by converting line breaks (`\n`, `\r\n`, `\r`) to `<br>` in `createTelegramPayloadHTML`, after sanitizing, covering every Telegram payload type at once. Verified: the new `Line breaks are kept in rich messages` test plus the updated Push/Issue/IssueComment/PullRequest/Review expectations fail on unpatched code (literal `\n` in the payload) and pass with the fix; the full `services/webhook` package passes, gofmt/vet clean. Fixes https://github.com/go-gitea/gitea/issues/39649 --- Tips welcome: PayPal kyleblake0659@gmail.com · BTC 3GnR7TWBXAB3pPztBWpNF4LMNEX5yX8vZK Co-authored-by: KShot <kshot9000@gmail.com>
This commit is contained in:
1 parent
5018ae1b29
commit
793e77b073
2 files changed
+17
-18
No files matched your search
@@ -201,9 +201,12 @@ func (telegramConvertor) WorkflowJob(p *api.WorkflowJobPayload) (TelegramPayload
|
||||
|
||||
func createTelegramPayloadHTML(msgHTML string) TelegramPayload {
|
||||
// https://core.telegram.org/bots/api#formatting-options
|
||||
sanitized := strings.TrimSpace(string(markup.Sanitize(msgHTML)))
|
||||
// Rich messages collapse bare newlines like HTML, so keep line breaks as <br>.
|
||||
sanitized = strings.NewReplacer("\r\n", "<br>", "\r", "<br>", "\n", "<br>").Replace(sanitized)
|
||||
return TelegramPayload{
|
||||
RichMessage: InputRichMessage{
|
||||
HTML: strings.TrimSpace(string(markup.Sanitize(msgHTML))),
|
||||
HTML: sanitized,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user