Saving specific Unicode characters in IE9 localStorage throws an invalid argument error

I am using localStorage in the application.

I use the XOR bit-shift operation to mask the data before it enters the repository.

Here is the masking function:

encrypt: function (str) { var encoded = []; if (!App.crypto.key) { App.crypto.init(); } for (var i = 0, len = str.length; i < len; i++) { var a = str.charCodeAt(i); var b = a ^ App.crypto.key.charCodeAt(App.crypto.key % i); encoded.push(String.fromCharCode(b)); } return encoded.join(""); } 

The key value that I use in this case is "MWZ2cyt2N3JwejhxUjA2V3ptRmwxcmVvU09IbFhORHdOcDRiWGh5SGRZMFU4Ym9VY1Y1WXU5c2d6OXhBdU9wTSt1MlpqQXOV

When I mask "[]" in IE9, I get some monster characters. When I try to install this on localStorage, this results in an invalid argument error. Does anyone know what is going on?

+4
source share
1 answer

IE (and Edge, if not already rewritten) stores localStorage as XML and disallows any character that does not match Char production in XML 1.0 ; those. you can save "any Unicode character, excluding surrogate blocks, FFFE and FFFF".

By specification, this is an error: there should be no restriction on what can be stored in localStorage (any ECMAScript line should be possible), although this error exists with IE8. (In IE8 previews, it was possible to damage the localStorage repository by preserving one of the forbidden characters, because when he tried to parse the XML file, he received a parsing error!)

+6
source

Source: https://habr.com/ru/post/1411364/


All Articles