Skip to content

Commit 1c27c8d

Browse files
FIX: html escape
1 parent 31757f4 commit 1c27c8d

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

utils/parser.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package utils
33
import (
44
"fmt"
55
"github-telegram-notify/types"
6+
"html"
67
"strings"
78
)
89

@@ -108,7 +109,7 @@ func createPushText(event *types.PushEvent) string {
108109
text += fmt.Sprintf("• <a href='%s'>%s</a> - %s by <a href='%s'>%s</a>\n",
109110
commit.Url,
110111
commit.Id[:7],
111-
commit.Message,
112+
html.EscapeString(commit.Message),
112113
commit.Author.HTMLURL,
113114
commit.Author.Name,
114115
)
@@ -133,7 +134,7 @@ func createIssueCommentText(event *types.IssueCommentEvent) string {
133134
event.Sender.HTMLURL,
134135
event.Sender.Login,
135136
event.Issue.HTMLURL,
136-
event.Issue.Title,
137+
html.EscapeString(event.Issue.Title),
137138
event.Repo.HTMLURL,
138139
event.Repo.FullName,
139140
)
@@ -145,7 +146,7 @@ func createIssuesText(event *types.IssuesEvent) string {
145146
event.Sender.Login,
146147
event.Action,
147148
event.Issue.HTMLURL,
148-
event.Issue.Title,
149+
html.EscapeString(event.Issue.Title),
149150
event.Repo.HTMLURL,
150151
event.Repo.FullName,
151152
)
@@ -158,7 +159,7 @@ func createPullRequestText(event *types.PullRequestEvent) (text string) {
158159
text += " a new"
159160
}
160161
text += " pull request "
161-
text += fmt.Sprintf("<a href='%s'>%s</a>", event.PullRequest.HTMLURL, event.PullRequest.Title)
162+
text += fmt.Sprintf("<a href='%s'>%s</a>", event.PullRequest.HTMLURL, html.EscapeString(event.PullRequest.Title))
162163
text += fmt.Sprintf(" in <a href='%s'>%s</a>", event.Repo.HTMLURL, event.Repo.FullName)
163164
return text
164165
}
@@ -168,7 +169,7 @@ func createPullRequestReviewCommentText(event *types.PullRequestReviewCommentEve
168169
event.Sender.HTMLURL,
169170
event.Sender.Login,
170171
event.PullRequest.HTMLURL,
171-
event.PullRequest.Title,
172+
html.EscapeString(event.PullRequest.Title),
172173
event.Repo.HTMLURL,
173174
event.Repo.FullName,
174175
)
@@ -190,7 +191,7 @@ func createReleaseText(event *types.ReleaseEvent) (text string) {
190191
if event.Release.Assets != nil {
191192
text += "📦 <b>Assets:</b>\n"
192193
for _, asset := range event.Release.Assets {
193-
text += fmt.Sprintf("• <a href='%s'>%s</a>\n", asset.BrowserDownloadURL, asset.Name)
194+
text += fmt.Sprintf("• <a href='%s'>%s</a>\n", asset.BrowserDownloadURL, html.EscapeString(asset.Name))
194195
}
195196
}
196197

utils/telegram.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"encoding/json"
55
"fmt"
66
"github-telegram-notify/types"
7-
"html"
87
"io/ioutil"
98
"net/http"
109
"net/url"
@@ -15,8 +14,7 @@ func SendMessage(token string, chatID string, text string, markupText string, ma
1514
req_url, _ := url.Parse(fmt.Sprint(apiBaseUri, "/bot", token, "/sendMessage"))
1615
params := url.Values{}
1716
params.Set("chat_id", chatID)
18-
escaped_text := html.EscapeString(text)
19-
params.Set("text", escaped_text)
17+
params.Set("text", text)
2018
params.Set("parse_mode", "html")
2119
params.Set("disable_web_page_preview", "true")
2220
kyb, err := json.Marshal(map[string][][]map[string]string{

0 commit comments

Comments
 (0)