From 3ffa099f553cee70045fefbd8303743f72ddc0cc Mon Sep 17 00:00:00 2001 From: Frederik Reiter Date: Fri, 9 Feb 2024 18:44:13 +0100 Subject: [PATCH 1/3] fix: only escape property values when serializing. This commit normalizes the meaning of "property.Value". It always contains an unserialized property value. Previously, property params were deserialized when parsing but not serialized again. --- calendar.go | 8 ++++---- components.go | 8 ++++---- property.go | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/calendar.go b/calendar.go index e7f6ca0..311e952 100644 --- a/calendar.go +++ b/calendar.go @@ -317,7 +317,7 @@ 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) { @@ -325,11 +325,11 @@ func (calendar *Calendar) SetXPublishedTTL(s string, props ...PropertyParameter) } 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) { @@ -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) { diff --git a/components.go b/components.go index 7713239..9ee85a2 100644 --- a/components.go +++ b/components.go @@ -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) { diff --git a/property.go b/property.go index 5855896..1c2f33e 100644 --- a/property.go +++ b/property.go @@ -109,7 +109,7 @@ func (property *BaseProperty) serialize(w io.Writer) { } } 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) From 0f8a32553bf227a97bf4b1550b7407f2c6337dc2 Mon Sep 17 00:00:00 2001 From: Frederik Reiter Date: Fri, 9 Feb 2024 18:45:27 +0100 Subject: [PATCH 2/3] fix: reorder string replaces in escaping values. Previously, ";" was incorrectly escaped. First, ";" was replaced by "\;". Then, the backslash was escpaed to "\\", resulting in "\\;". Now, we first escape all backslashes and then escape other characters. --- property.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/property.go b/property.go index 1c2f33e..7c4c7ce 100644 --- a/property.go +++ b/property.go @@ -99,9 +99,9 @@ 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) } From 647cf9ea6dd29eece2fdc95653b2d4b8af9526a2 Mon Sep 17 00:00:00 2001 From: Frederik Reiter Date: Tue, 13 Feb 2024 14:33:55 +0100 Subject: [PATCH 3/3] test: Add test for escaped semicolons in property parameters --- calendar_test.go | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/calendar_test.go b/calendar_test.go index abbd39b..38b1b73 100644 --- a/calendar_test.go +++ b/calendar_test.go @@ -1,7 +1,6 @@ package ics import ( - "github.com/stretchr/testify/assert" "io" "io/ioutil" "os" @@ -11,6 +10,8 @@ import ( "testing" "time" "unicode/utf8" + + "github.com/stretchr/testify/assert" ) func TestTimeParsing(t *testing.T) { @@ -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 `, }, }