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

Key collisions for non-identical strings #4

Open
inexorabletash opened this issue Feb 20, 2013 · 0 comments
Open

Key collisions for non-identical strings #4

inexorabletash opened this issue Feb 20, 2013 · 0 comments

Comments

@inexorabletash
Copy link

The userData API storage mechanism uses HTML attributes to store key/values; attribute names are case-insensitive. The cleanKey mechanism maps all non-attribute characters to "-". Together, this means that the following keys would be treated as the same:

"A-B-C"
"a-b-c"
"a%b*c"

This could lead to data overwrites if arbitrary keys are used.

Here's one possible key escaping mechanism to avoid this:

function (key) {
key = String(key);
var m = ['k'], len = key.length;
for (var i = 0; i < len; ++i) {
m.push(key.charCodeAt(i).toString(36));
}
return m.join('-');
}

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