From ac92499b7db0e8d5b4d01c31f996b5e06c91f3eb Mon Sep 17 00:00:00 2001 From: kolaente Date: Wed, 13 Jul 2022 22:47:25 +0200 Subject: [PATCH] fix(caldav): make sure description is parsed correctly when multiline Resolves https://github.com/go-vikunja/api/issues/35 --- go.mod | 3 ++- go.sum | 2 ++ pkg/caldav/parsing.go | 24 +++++++++++++----------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 14e43338..142aff5e 100644 --- a/go.mod +++ b/go.mod @@ -21,6 +21,7 @@ require ( gitea.com/xorm/xorm-redis-cache v0.2.0 github.com/ThreeDotsLabs/watermill v1.1.1 github.com/adlio/trello v1.10.0 + github.com/arran4/golang-ical v0.0.0-20220517104411-fd89fefb0182 github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef github.com/bbrks/go-blurhash v1.1.1 github.com/c2h5oh/datasize v0.0.0-20200825124411-48ed595a09d2 @@ -42,7 +43,6 @@ require ( github.com/jinzhu/copier v0.3.5 github.com/labstack/echo/v4 v4.7.2 github.com/labstack/gommon v0.3.1 - github.com/laurent22/ical-go v0.1.1-0.20181107184520-7e5d6ade8eef github.com/lib/pq v1.10.6 github.com/magefile/mage v1.13.0 github.com/mattn/go-sqlite3 v1.14.14 @@ -107,6 +107,7 @@ require ( github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect + github.com/laurent22/ical-go v0.1.1-0.20181107184520-7e5d6ade8eef // indirect github.com/lithammer/shortuuid/v3 v3.0.4 // indirect github.com/magiconair/properties v1.8.6 // indirect github.com/mailru/easyjson v0.7.6 // indirect diff --git a/go.sum b/go.sum index aee20bf8..f7081dd5 100644 --- a/go.sum +++ b/go.sum @@ -103,6 +103,8 @@ github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmV github.com/armon/go-metrics v0.3.10/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= +github.com/arran4/golang-ical v0.0.0-20220517104411-fd89fefb0182 h1:mUsKridvWp4dgfkO/QWtgGwuLtZYpjKgsm15JRRik3o= +github.com/arran4/golang-ical v0.0.0-20220517104411-fd89fefb0182/go.mod h1:BSTTrYHuM12oAL8jDdcmPdw02SBThKYWNFHQlvEG6b0= github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef h1:46PFijGLmAjMPwCCCo7Jf0W6f9slllCkkv7vyc1yOSg= github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= diff --git a/pkg/caldav/parsing.go b/pkg/caldav/parsing.go index ead9ebcc..2136ad2a 100644 --- a/pkg/caldav/parsing.go +++ b/pkg/caldav/parsing.go @@ -23,7 +23,8 @@ import ( "code.vikunja.io/api/pkg/log" "code.vikunja.io/api/pkg/models" - "github.com/laurent22/ical-go" + + ics "github.com/arran4/golang-ical" ) func GetCaldavTodosForTasks(list *models.ListWithTasksAndBuckets, listTasks []*models.TaskWithComments) string { @@ -60,21 +61,15 @@ func GetCaldavTodosForTasks(list *models.ListWithTasksAndBuckets, listTasks []*m } func ParseTaskFromVTODO(content string) (vTask *models.Task, err error) { - parsed, err := ical.ParseCalendar(content) + parsed, err := ics.ParseCalendar(strings.NewReader(content)) if err != nil { return nil, err } // We put the task details in a map to be able to handle them more easily task := make(map[string]string) - for _, c := range parsed.Children { - if c.Name == "VTODO" { - for _, entry := range c.Children { - task[entry.Name] = entry.Value - } - // Breaking, to only process the first task - break - } + for _, c := range parsed.Components[0].UnknownPropertiesIANAProperties() { + task[c.IANAToken] = c.Value } // Parse the priority @@ -91,10 +86,13 @@ func ParseTaskFromVTODO(content string) (vTask *models.Task, err error) { // Parse the enddate duration, _ := time.ParseDuration(task["DURATION"]) + description := strings.ReplaceAll(task["DESCRIPTION"], "\\,", ",") + description = strings.ReplaceAll(description, "\\n", "\n") + vTask = &models.Task{ UID: task["UID"], Title: task["SUMMARY"], - Description: task["DESCRIPTION"], + Description: description, Priority: priority, DueDate: caldavTimeToTimestamp(task["DUE"]), Updated: caldavTimeToTimestamp(task["DTSTAMP"]), @@ -125,6 +123,10 @@ func caldavTimeToTimestamp(tstring string) time.Time { format = `20060102T150405Z` } + if len(tstring) == 8 { + format = `20060102` + } + t, err := time.Parse(format, tstring) if err != nil { log.Warningf("Error while parsing caldav time %s to TimeStamp: %s", tstring, err)