From 90be80c91a64108a0288eca9c5b0ca19bd27a8e3 Mon Sep 17 00:00:00 2001 From: Karl Ostendorf Date: Tue, 27 Oct 2020 15:30:26 +0100 Subject: [PATCH] return a nil CalendarCompRequest when empty necessary to work with iCloud # Conflicts: # caldav/caldav_test.go # caldav/client.go --- caldav/caldav_test.go | 36 ++++++++++++++++++++++++++++++++++++ caldav/client.go | 8 +++++++- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 caldav/caldav_test.go diff --git a/caldav/caldav_test.go b/caldav/caldav_test.go new file mode 100644 index 0000000..ca2bf79 --- /dev/null +++ b/caldav/caldav_test.go @@ -0,0 +1,36 @@ +package caldav_test + +import ( + "testing" + + "github.com/emersion/go-webdav/caldav" +) + +func TestCalendarCompRequest_IsEmpty(b *testing.T) { + testCases := []struct { + Name string + Request caldav.CalendarCompRequest + ExpectedResult bool + }{ + { + Name: "empty", + Request: caldav.CalendarCompRequest{}, + ExpectedResult: true, + }, + { + Name: "has-name", + Request: caldav.CalendarCompRequest{ + Name: "name", + }, + ExpectedResult: false, + }, + } + + for _, tCase := range testCases { + b.Run(tCase.Name, func(t *testing.T) { + if got, want := tCase.Request.Name == "", tCase.ExpectedResult; got != want { //nolint:scopelint + t.Errorf("bad result: %t, expected: %t", got, want) + } + }) + } +} diff --git a/caldav/client.go b/caldav/client.go index 8f7952e..cec3ba2 100644 --- a/caldav/client.go +++ b/caldav/client.go @@ -106,6 +106,10 @@ func (c *Client) FindCalendars(calendarHomeSet string) ([]Calendar, error) { } func encodeCalendarCompReq(c *CalendarCompRequest) (*comp, error) { + if c == nil || c.Name == "" { + return nil, nil + } + encoded := comp{Name: c.Name} if c.AllProps { @@ -123,7 +127,9 @@ func encodeCalendarCompReq(c *CalendarCompRequest) (*comp, error) { if err != nil { return nil, err } - encoded.Comp = append(encoded.Comp, *encodedChild) + if encodedChild != nil { + encoded.Comp = append(encoded.Comp, *encodedChild) + } } return &encoded, nil