alekseykulikov / backbone-offline

[Deprecated] Allows your Backbone.js app to work offline
MIT License
721 stars 56 forks source link

Bug with Storage#clear #40

Open danharper opened 11 years ago

danharper commented 11 years ago

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 :)