From dc9c5a59451042e08650f38c96ebca1ae0b30ef4 Mon Sep 17 00:00:00 2001 From: Dan Esparza Date: Thu, 31 Jan 2019 13:19:53 -0500 Subject: [PATCH 1/2] Update parse.go Remove extra CRLF sequences (seen in the wild in exported Google calendar ics file) --- parse.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/parse.go b/parse.go index ea11827..66bb0ed 100644 --- a/parse.go +++ b/parse.go @@ -81,6 +81,8 @@ func Parse(r io.Reader, l *time.Location) (*Calendar, error) { p.location = l text := unfold(string(bytes)) + + // Lex p.lex = lex(text) return p.parse() } @@ -126,7 +128,16 @@ func NewParam() *Param { // unfold convert multiple line value to one line func unfold(text string) string { - return strings.Replace(text, "\r\n ", "", -1) + newstring := text + + // Convert multiple line values to a single line: + newstring = strings.Replace(newstring, "\r\n ", "", -1) + + // Remove extra CRLF sequences + newstring = strings.Replace(newstring, "\r\n\r\n", "\r\n", -1) + + // Return the new string + return newstring } // next returns the next token. From 75289bc4f54358976f682ca92f0bca9afd98ae46 Mon Sep 17 00:00:00 2001 From: Dan Esparza Date: Fri, 1 Feb 2019 13:53:17 -0500 Subject: [PATCH 2/2] Add RRule field --- parse.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/parse.go b/parse.go index 66bb0ed..0c5abf2 100644 --- a/parse.go +++ b/parse.go @@ -21,14 +21,15 @@ type Calendar struct { // An Event represent a VEVENT component in an iCalendar type Event struct { - Properties []*Property - Alarms []*Alarm - UID string - Timestamp time.Time - StartDate time.Time - EndDate time.Time - Summary string - Description string + Properties []*Property + Alarms []*Alarm + UID string + Timestamp time.Time + StartDate time.Time + EndDate time.Time + Summary string + Description string + RecurringRule string } // An Alarm represent a VALARM component in an iCalendar @@ -460,6 +461,11 @@ func (p *parser) validateEvent(v *Event) error { v.Description = prop.Value uniqueCount["DESCRIPTION"]++ } + + if prop.Name == "RRULE" { + v.RecurringRule = prop.Value + uniqueCount["RRULE"]++ + } } if p.c.Method == "" && v.Timestamp.IsZero() {