etesync / etesync-web

An EteSync web client
https://www.etesync.com
GNU Affero General Public License v3.0
247 stars 31 forks source link

Bug: Event/Task `clone` doesn't deep clone #119

Closed AbleLincoln closed 4 years ago

AbleLincoln commented 4 years ago

The clone function uses ical's toJson function to make a copy. Unfortunately, this function just returns the object representation of a component, it doesn't actually make a json copy as one would expect. This is dangerous: as the documentation says, "The returned object is a live jCal object and should be cloned if modified".

This is causing problems for instance in the Tasks recurrence code. When I handle completing a recurring task, I need to use copy to create the next occurrence, modify it, and save it. Since the underlying jCal objects for both tasks are really just the same object, anything I modify on the "clone" is modified on the original (only in memory, until I inevitably save them).

AbleLincoln commented 4 years ago

One possible solution would be to use the toString and fromString methods to safely deep clone.