Skip to content

Commit

Permalink
JSON escape text fields
Browse files Browse the repository at this point in the history
Helps them to show up correctly in google calendar
  • Loading branch information
akarnani committed Aug 29, 2022
1 parent 7713bcb commit e05129a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
14 changes: 14 additions & 0 deletions helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import "encoding/json"

func jsonEscape(s string) string {
o, err := json.Marshal(s)
if err != nil {
// if it can't be json encoded just return the original
return s
}

str := string(o)
return str[1 : len(str)-1] // strip the leading/trailing quotes
}
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ func diffEvents(cfg Config, up []gocal.Event, gevent []*calendar.Event) ([]*cale
func iCalToGEvent(cfg Config, e gocal.Event) *calendar.Event {
allDay := isAllDayEvent(e)
return &calendar.Event{
Summary: e.Summary,
Location: e.Location,
Description: e.Description,
Summary: jsonEscape(e.Summary),
Location: jsonEscape(e.Location),
Description: jsonEscape(e.Description),
Start: getEventTime(*e.Start, allDay),
End: getEventTime(*e.End, allDay),
ICalUID: getIDForEvent(cfg, e),
Expand Down

0 comments on commit e05129a

Please sign in to comment.