Skip to content

Commit

Permalink
Only conditionally add in the mailto: prefix for attendee and organizer
Browse files Browse the repository at this point in the history
  • Loading branch information
meain committed Mar 4, 2024
1 parent f5b4408 commit 93ca35f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
12 changes: 10 additions & 2 deletions components.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,11 @@ func (cb *ComponentBase) SetURL(s string, props ...PropertyParameter) {
}

func (cb *ComponentBase) SetOrganizer(s string, props ...PropertyParameter) {
cb.SetProperty(ComponentPropertyOrganizer, "mailto:"+s, props...)
if !strings.HasPrefix(s, "mailto:") {
s = "mailto:" + s
}

cb.SetProperty(ComponentPropertyOrganizer, s, props...)
}

func (cb *ComponentBase) SetColor(s string, props ...PropertyParameter) {
Expand All @@ -258,7 +262,11 @@ func (cb *ComponentBase) setResources(r string, props ...PropertyParameter) {
}

func (cb *ComponentBase) AddAttendee(s string, props ...PropertyParameter) {
cb.AddProperty(ComponentPropertyAttendee, "mailto:"+s, props...)
if !strings.HasPrefix(s, "mailto:") {
s = "mailto:" + s
}

cb.AddProperty(ComponentPropertyAttendee, s, props...)
}

func (cb *ComponentBase) AddExdate(s string, props ...PropertyParameter) {
Expand Down
24 changes: 24 additions & 0 deletions components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,27 @@ func TestGetLastModifiedAt(t *testing.T) {
t.Errorf("got last modified = %q, want %q", got, lastModified)
}
}

func TestSetMailtoPrefix(t *testing.T) {
e := NewEvent("test-set-organizer")

e.SetOrganizer("[email protected]")
if !strings.Contains(e.Serialize(), "ORGANIZER:mailto:[email protected]") {
t.Errorf("expected single mailto: prefix for email org1")
}

e.SetOrganizer("mailto:[email protected]")
if !strings.Contains(e.Serialize(), "ORGANIZER:mailto:[email protected]") {
t.Errorf("expected single mailto: prefix for email org2")
}

e.AddAttendee("[email protected]")
if !strings.Contains(e.Serialize(), "ATTENDEE:mailto:[email protected]") {
t.Errorf("expected single mailto: prefix for email att1")
}

e.AddAttendee("mailto:[email protected]")
if !strings.Contains(e.Serialize(), "ATTENDEE:mailto:[email protected]") {
t.Errorf("expected single mailto: prefix for email att2")
}
}

0 comments on commit 93ca35f

Please sign in to comment.