Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix various text escaping issues #86

Merged
merged 3 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions calendar.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,19 +317,19 @@ func (calendar *Calendar) SerializeTo(w io.Writer) error {
}

func (calendar *Calendar) SetMethod(method Method, props ...PropertyParameter) {
calendar.setProperty(PropertyMethod, ToText(string(method)), props...)
calendar.setProperty(PropertyMethod, string(method), props...)
}

func (calendar *Calendar) SetXPublishedTTL(s string, props ...PropertyParameter) {
calendar.setProperty(PropertyXPublishedTTL, string(s), props...)
}

func (calendar *Calendar) SetVersion(s string, props ...PropertyParameter) {
calendar.setProperty(PropertyVersion, ToText(s), props...)
calendar.setProperty(PropertyVersion, s, props...)
}

func (calendar *Calendar) SetProductId(s string, props ...PropertyParameter) {
calendar.setProperty(PropertyProductId, ToText(s), props...)
calendar.setProperty(PropertyProductId, s, props...)
}

func (calendar *Calendar) SetName(s string, props ...PropertyParameter) {
Expand Down Expand Up @@ -358,7 +358,7 @@ func (calendar *Calendar) SetXWRCalID(s string, props ...PropertyParameter) {
}

func (calendar *Calendar) SetDescription(s string, props ...PropertyParameter) {
calendar.setProperty(PropertyDescription, ToText(s), props...)
calendar.setProperty(PropertyDescription, s, props...)
}

func (calendar *Calendar) SetLastModified(t time.Time, props ...PropertyParameter) {
Expand Down
28 changes: 27 additions & 1 deletion calendar_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ics

import (
"github.com/stretchr/testify/assert"
"io"
"io/ioutil"
"os"
Expand All @@ -11,6 +10,8 @@ import (
"testing"
"time"
"unicode/utf8"

"github.com/stretchr/testify/assert"
)

func TestTimeParsing(t *testing.T) {
Expand Down Expand Up @@ -315,6 +316,31 @@ DESCRIPTION:blablablablablablablablablablablablablablablabltesttesttest
CLASS:PUBLIC
END:VEVENT
END:VCALENDAR
`,
},
{
name: "test semicolon in attendee property parameter",
input: `BEGIN:VCALENDAR
VERSION:2.0
X-CUSTOM-FIELD:test
PRODID:-//arran4//Golang ICS Library
DESCRIPTION:test
BEGIN:VEVENT
ATTENDEE;CN=Test\;User:mailto:[email protected]
CLASS:PUBLIC
END:VEVENT
END:VCALENDAR
`,
output: `BEGIN:VCALENDAR
VERSION:2.0
X-CUSTOM-FIELD:test
PRODID:-//arran4//Golang ICS Library
DESCRIPTION:test
BEGIN:VEVENT
ATTENDEE;CN=Test\;User:mailto:[email protected]
CLASS:PUBLIC
END:VEVENT
END:VCALENDAR
`,
},
}
Expand Down
8 changes: 4 additions & 4 deletions components.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,19 @@ func (cb *ComponentBase) GetDtStampTime() (time.Time, error) {
}

func (cb *ComponentBase) SetSummary(s string, props ...PropertyParameter) {
cb.SetProperty(ComponentPropertySummary, ToText(s), props...)
cb.SetProperty(ComponentPropertySummary, s, props...)
}

func (cb *ComponentBase) SetStatus(s ObjectStatus, props ...PropertyParameter) {
cb.SetProperty(ComponentPropertyStatus, ToText(string(s)), props...)
cb.SetProperty(ComponentPropertyStatus, string(s), props...)
}

func (cb *ComponentBase) SetDescription(s string, props ...PropertyParameter) {
cb.SetProperty(ComponentPropertyDescription, ToText(s), props...)
cb.SetProperty(ComponentPropertyDescription, s, props...)
}

func (cb *ComponentBase) SetLocation(s string, props ...PropertyParameter) {
cb.SetProperty(ComponentPropertyLocation, ToText(s), props...)
cb.SetProperty(ComponentPropertyLocation, s, props...)
}

func (cb *ComponentBase) setGeo(lat interface{}, lng interface{}, props ...PropertyParameter) {
Expand Down
4 changes: 2 additions & 2 deletions property.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,17 @@ func (property *BaseProperty) serialize(w io.Writer) {
fmt.Fprint(b, ",")
}
if strings.ContainsAny(v, ";:\\\",") {
v = strings.Replace(v, "\\", "\\\\", -1)
v = strings.Replace(v, ";", "\\;", -1)
v = strings.Replace(v, ":", "\\:", -1)
v = strings.Replace(v, "\\", "\\\\", -1)
v = strings.Replace(v, "\"", "\\\"", -1)
v = strings.Replace(v, ",", "\\,", -1)
}
fmt.Fprint(b, v)
}
}
fmt.Fprint(b, ":")
fmt.Fprint(b, property.Value)
fmt.Fprint(b, ToText(property.Value))
r := b.String()
if len(r) > 75 {
l := trimUT8StringUpTo(75, r)
Expand Down
Loading