Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if you have a empty key in local or session storage the load breaks completely #10

Closed
jcompagner opened this issue Sep 3, 2013 · 4 comments

Comments

@jcompagner
Copy link
Contributor

this is because the code has this if:

for (var i = 0, k; i < webStorage.length && (k = webStorage.key(i)); i++) {
'ngStorage-' === k.slice(0, 10) && ($storage[k.slice(10)] = angular.fromJson(webStorage.getItem(k)));
}

i changed it to:

for (var i = 0, k; i < webStorage.length; i++) {
if ((k = webStorage.key(i))) {
'ngStorage-' === k.slice(0, 10) && ($storage[k.slice(10)] = angular.fromJson(webStorage.getItem(k)));
}
}

and then it works, because it shouldn't completely skip the whole loop if somehow "k" evalutes to false (because the key is an empty string)

somehow i get such a key in my local and session storage, can't currently find out why that is (""=null) i don't use the local and session storage at all my self so it must be a 3th party lib, that maybe tries to test if the storage are available and doesn't remove that key
But nsStorage shouldn't just not work if a key is not what it expects it to be (if that is not a key of nsStorage itself)

@gsklee
Copy link
Owner

gsklee commented Sep 4, 2013

OK this is a very interesting edge case... Can you send in your change as a PR? Many thanks!

@gsklee
Copy link
Owner

gsklee commented Sep 17, 2013

@jcompagner You gonna send in a PR? =)

@jcompagner
Copy link
Contributor Author

done

@gsklee gsklee closed this as completed in f94e17c Sep 17, 2013
@gsklee
Copy link
Owner

gsklee commented Sep 17, 2013

Cool! 😎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants