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

Bug with clearAll and regexes using preset prefix. #338

Open
daredevil82 opened this issue Nov 18, 2016 · 0 comments
Open

Bug with clearAll and regexes using preset prefix. #338

daredevil82 opened this issue Nov 18, 2016 · 0 comments

Comments

@daredevil82
Copy link

Lets say I have my localstorage entries prefixed with dd82-app, and I want to clear all keys with that prefix. I do this with localStorageService.clearAll('^' + this._constants.prefix + '.');

This call always returns true, although the keys and values still exist in localstorage. Digging through the code reveals the issue at line 305:

      // Only remove items that are for this app and match the regular expression
      if (prefixRegex.test(key) && testRegex.test(key.substr(prefixLength))) {

So, with my prefix dd82-app, results in a prefixRegex value of /^dd82-app./ and testRegex matching

So, for a sample key dd82-app.access_token, the first part of the conditional, prefixRegex.test(key) works. It fails on the second part, because key.substr(prefixLength) returns a value of access-token, which does not match testRegex. Because that conditonal fails, the key is never removed.

In my case, this can be fixed by adding 0, resulting in a key.substr(0, prefixLength) call, but may break other cases.

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

1 participant