5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-26 02:01:36 +00:00

Strip markdown URLs with blank text (slack) (#392)

This commit is contained in:
Jerry Heiselman 2018-03-22 16:28:27 -05:00 committed by Wim
parent d525230abd
commit 76360f89c1

View File

@ -4,16 +4,17 @@ import (
"bytes"
"errors"
"fmt"
"github.com/42wim/matterbridge/bridge"
"github.com/42wim/matterbridge/bridge/config"
"github.com/42wim/matterbridge/bridge/helper"
"github.com/42wim/matterbridge/matterhook"
"github.com/nlopes/slack"
"html"
"regexp"
"strings"
"sync"
"time"
"github.com/42wim/matterbridge/bridge"
"github.com/42wim/matterbridge/bridge/config"
"github.com/42wim/matterbridge/bridge/helper"
"github.com/42wim/matterbridge/matterhook"
"github.com/nlopes/slack"
)
type Bslack struct {
@ -387,8 +388,12 @@ func (b *Bslack) replaceVariable(text string) string {
func (b *Bslack) replaceURL(text string) string {
results := regexp.MustCompile(`<(.*?)(\|.*?)?>`).FindAllStringSubmatch(text, -1)
for _, r := range results {
if len(strings.TrimSpace(r[2])) == 1 { // A display text separator was found, but the text was blank
text = strings.Replace(text, r[0], "", -1)
} else {
text = strings.Replace(text, r[0], r[1], -1)
}
}
return text
}