Skip to content

Commit

Permalink
Merge pull request #4 from Crazybus/not_everyone_needs_a_title
Browse files Browse the repository at this point in the history
Don't try to format urls which don't have titles
  • Loading branch information
Crazybus authored Jul 9, 2018
2 parents 49705e6 + 9f6c686 commit 20a15e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions moonsla.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func formatUrls(msg string) string {
matches := re.FindAllString(msg, -1)
for _, m := range matches {
split := strings.Split(m[1:len(m)-1], "|")
// If this is just a plain url continue since we can't format it
if len(split) == 1 {
continue
}
url := split[0 : len(split)-1][0]
title := split[len(split)-1]
formatted := fmt.Sprintf("\x1b]8;;%s\a%s\x1b]8;;\a", url, title)
Expand Down
5 changes: 5 additions & 0 deletions moonsla_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ func TestFormatUrls(t *testing.T) {
"hello <http://google.com|test> world",
"hello \x1b]8;;http://google.com\atest\x1b]8;;\a world",
},
{
"Message with a non-formatted url",
"hello <http://google.com> world",
"hello <http://google.com> world",
},
{
"Message with multiple urls",
"hello <http://google.com|test> world how <https://google.com|are you>",
Expand Down

0 comments on commit 20a15e8

Please sign in to comment.