Skip to content

Commit

Permalink
Merge pull request #86 from JM-Lemmi/fix/text_escaping
Browse files Browse the repository at this point in the history
Fix various text escaping issues
  • Loading branch information
arran4 authored Feb 14, 2024
2 parents 51fa6f1 + 647cf9e commit 542d6e5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
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:user@example.com
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:user@example.com
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

0 comments on commit 542d6e5

Please sign in to comment.