backbone-offline icon indicating copy to clipboard operation
backbone-offline copied to clipboard

Bug with Storage#clear

Open danharper opened this issue 11 years ago • 0 comments

https://github.com/Ask11/backbone.offline/blob/master/src/backbone_offline.coffee#L173

The RegExp checking if a localStorage key belongs to the collection being cleared checks whether the key simply contains the collection's name, and not if it begins with it.

So if when clearing a collection named items, it will also remove the localStorage keys for dictionaryitems.

Instead, we should check the key starts with the name:

(new RegExp "^#{@name}").test(key)

This had me scratching my head for days wondering why localStorage was magically losing data before I narrowed it down :)

danharper avatar Apr 18 '13 13:04 danharper