-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
IE 7 throws error if number, or string starting with number, is used as key #40
Comments
Fascinating! I think prefixing IE keys with "_" is a perfectly reasonable Cheers! On Fri, Mar 16, 2012 at 5:04 AM, Paul D. Waite <
My code http://github.com/marcuswestin |
Cheers Martin, I’ll get something together for your consideration next week. Yours sincerely, On 17 Mar 2012, at 1:15 a.m., Marcus Westin wrote:
|
Fixed in d0a5e64 |
Now that’s service, cheers Marcus. Yours sincerely, On 22 Mar 2012, at 12:34 AM, Marcus Westin reply@reply.github.com wrote:
|
Happy to help :) -- while mobile On Mar 26, 2012, at 11:29 PM, "Paul D. Waite"reply@reply.github.com wrote:
|
Hi , I just tested the library ( GR8 job ! ) and have something on this : my IE7 complains about anything that's not alphanumeric ( eg : /,(,% etc ) . I came across this issue trying to port saiku-ui to IE7 ( localStorage problem ) . I am currently working around the issue by adding a .replace(/\W/g, "") to the key when returning from ieKeyFix(key). Still need to extensively test it but am 85% sure that fixes all of the other cases |
Aha! Nice find @mferretti! I'm hesitant to simply remove them all since it could result in key collisions that would be very subtle and hard to debug (only keys with obscure combinations of characters, and in IE7 only). I wonder if there's a straight forward encoding that we could apply to all keys. Have you tried using encodeURIComponent? E.g.
I would love the help with adding test cases to |
well the return encodeURIComponent('_'+key) would translate the string adding chars like '%' which, again, would return an error. |
Ah, of course. I wonder if an encodeURIComponent that then special cases + and % would Anyways - looking forward to see what you come up with! On Tue, Jul 10, 2012 at 11:37 AM, Marco Ferretti <
|
ok, this means that encodeURIComponent is not sufficient. function ieKeyFix(key) { // In IE7, keys may not begin with numbers. // See https://github.com/marcuswestin/store.js/issues/40#issuecomment-4617842 //remove spaces,remove % key = key.replace(/\s/g,'').replace(/%/g,''); //remove / key = key.replace(/\//g,''); //remove ( key = key.replace(/\(/g,''); //remove ) key = key.replace(/\)/g,''); return '_'+key; } which is not THAT far from return '_'+key.replace(/\W/g, "") ; |
Nice work! I would gladly accept a patch for this - think I would prefer to Also, we should add a Contributors section to README - feel free to add On Wed, Jul 11, 2012 at 1:30 AM, Marco Ferretti <
|
mmm ... looks like you cannot use any "special" char here I came up with this test git://gist.github.com/3097343.git : basically testing all the ASCII table. The result is that in IE7 the following chars cannot be used within a key ( skipping non printable chars ) : code 9 throwed an This name may not contain the ' ' character: _key--> <-- code 10 throwed an This name may not contain the ' ' character: _key--> <-- code 11 throwed an This name may not contain the ' ' character: _key--> <-- code 12 throwed an This name may not contain the ' ' character: _key--> <-- code 13 throwed an This name may not contain the ' ' character: _key--> <-- code 32 throwed an This name may not contain the ' ' character: _key--> <-- code 33 throwed an This name may not contain the '!' character: _key-->!<-- code 34 throwed an This name may not contain the '"' character: _key-->"<-- code 35 throwed an This name may not contain the '#' character: _key-->#<-- code 36 throwed an This name may not contain the '$' character: _key-->$<-- code 37 throwed an This name may not contain the '%' character: _key-->%<-- code 38 throwed an This name may not contain the '&' character: _key-->&<-- code 39 throwed an This name may not contain the ''' character: _key-->'<-- code 40 throwed an This name may not contain the '(' character: _key-->(<-- code 41 throwed an This name may not contain the ')' character: _key-->)<-- code 42 throwed an This name may not contain the '_' character: key--><-- code 43 throwed an This name may not contain the '+' character: _key-->+<-- code 44 throwed an This name may not contain the ',' character: _key-->,<-- code 47 throwed an This name may not contain the '/' character: _key-->/<-- code 58 throwed an This name may not contain the ':' character: _key-->:<-- code 59 throwed an This name may not contain the ';' character: _key-->;<-- code 60 throwed an This name may not contain the '<' character: _key--><<-- code 61 throwed an This name may not contain the '=' character: _key-->=<-- code 62 throwed an This name may not contain the '>' character: _key-->><-- code 63 throwed an This name may not contain the '?' character: _key-->?<-- code 64 throwed an This name may not contain the '@' character: _key-->@<-- code 91 throwed an This name may not contain the '[' character: _key-->[<-- code 92 throwed an This name may not contain the '' character: _key--><-- code 93 throwed an This name may not contain the ']' character: _key-->]<-- code 94 throwed an This name may not contain the '^' character: _key-->^<-- code 96 throwed an This name may not contain the ' code 123 throwed an This name may not contain the '{' character: _key-->{<-- code 124 throwed an This name may not contain the '|' character: _key-->|<-- code 125 throwed an This name may not contain the '}' character: _key-->}<-- code 126 throwed an This name may not contain the ' The bottom line is that all the "special chars" cannot be used thus, if we fear the collision, I suggest to go for a substitution table that does something like : col for ":" and so on .... What do you think ? |
I have come up with a ( hopefully ) more elegant solution. What happens is ( eg ) : 'something{note_the_graph' --> 'something_123_note_the_graph' if we're not hitting some max length here I think we can safely assume this is going to work :) Under the hood : I am testing if key != key.replace(/\W/g, "") , if that happens then we need to check the key and change the offending chars. Also, I added ( copied from mozilla ) an indexOf to the array ( IE doesn't support it I think until version 9 or something ) so that we can make things work a little faster. now .... how do you want me to submit the patch ? shall i fork and push or just send it over to you via email/gist ? |
…which are not allowed. This addresses issue #40 and merges the relevant changes by @mferretti in PR #49
If you attempt to use a number, or a string starting with a number, as a key, then IE 7 will throw an error, e.g.
I’m not sure if using numbers or strings starting with numbers as keys is meant to be supported, but it seems to work in IE 8 and other browsers.
Test page:
I’ve worked around the issue by patching store.js to append 'string_' to the key within the get(), set() and remove() functions passed to withIEStorage(), but I’m not sure if this is optimal.
The text was updated successfully, but these errors were encountered: