Skip to content

Commit 730220f

Browse files
committed
Extende unquoting to all the text
1 parent 0c092b4 commit 730220f

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

irc_server.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ var (
4040
rxSlackUser = regexp.MustCompile("<@[UW][A-Z0-9]+>")
4141
)
4242

43-
// ExpandURLs expands and unquotes URLs from Slack's messages. Slack quotes the
44-
// URLs and groups them between < and >. It also translates potential URLs into
45-
// actual URLs (e.g. when you type "example.com"), so you will get something
46-
// like <http://example.com|example.com>. This function tries to detect them and
47-
// unquote and expand them for a better visualization on IRC.
48-
func ExpandURLs(text string) string {
43+
// ExpandText expands and unquotes text and URLs from Slack's messages. Slack
44+
// quotes the text and URLS, and the latter are enclosed in < and >. It also
45+
// translates potential URLs into actual URLs (e.g. when you type "example.com"),
46+
// so you will get something like <http://example.com|example.com>. This
47+
// function tries to detect them and unquote and expand them for a better
48+
// visualization on IRC.
49+
func ExpandText(text string) string {
4950
text = rxSlackUrls.ReplaceAllStringFunc(text, func(subs string) string {
5051
if !strings.HasPrefix(subs, "<") && !strings.HasSuffix(subs, ">") {
5152
return subs
@@ -68,12 +69,13 @@ func ExpandURLs(text string) string {
6869
return subs
6970
}
7071
// Slack escapes the URLs passed by the users, let's undo that
71-
u.RawQuery = html.UnescapeString(u.RawQuery)
72+
//u.RawQuery = html.UnescapeString(u.RawQuery)
7273
if slackMsg == "" {
7374
return u.String()
7475
}
7576
return fmt.Sprintf("%s (%s)", slackMsg, u.String())
7677
})
78+
text = html.UnescapeString(text)
7779
return text
7880
}
7981

@@ -196,7 +198,7 @@ func IrcAfterLoggingIn(ctx *IrcContext, rtm *slack.RTM) error {
196198
return fmt.Sprintf("@%s", user.Name)
197199
})
198200
// replace some HTML entities
199-
text = ExpandURLs(text)
201+
text = ExpandText(text)
200202

201203
// FIXME if two instances are connected to the Slack API at the
202204
// same time, this will hide the other instance's message

0 commit comments

Comments
 (0)