Skip to content

Commit 4d21ff3

Browse files
committed
event: Fix URL encoding
1 parent 782672f commit 4d21ff3

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

internal/event/event.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"fmt"
88
"net/url"
9+
"strings"
910
"time"
1011

1112
"github.com/icinga/icinga-go-library/database"
@@ -37,19 +38,17 @@ type Event struct {
3738

3839
// CompleteURL prefixes the URL with the given Icinga Web 2 base URL unless it already carries a URL or is empty.
3940
func (e *Event) CompleteURL(icingaWebBaseUrl string) {
40-
// Nothing to do for an empty URL.
4141
if e.URL == "" {
4242
return
4343
}
4444

45-
// If the event carries a valid URL w/ a scheme, use this.
46-
if eventUrl, err := url.Parse(e.URL); err == nil && eventUrl.Scheme != "" {
47-
return
45+
if !strings.HasSuffix(icingaWebBaseUrl, "/") {
46+
icingaWebBaseUrl += "/"
4847
}
4948

50-
// If the event carries something, put it behind the base URL.
51-
if baseUrl, err := url.Parse(icingaWebBaseUrl); err == nil {
52-
e.URL = baseUrl.JoinPath(e.URL).String()
49+
u, err := url.Parse(e.URL)
50+
if err != nil || u.Scheme == "" {
51+
e.URL = icingaWebBaseUrl + e.URL
5352
}
5453
}
5554

0 commit comments

Comments
 (0)