alekseykulikov/backbone-offline

Bug with Storage#clear

Opened this issue · 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 :)