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

UTF-16 limitation on Firefox? #270

Open
Kassy2048 opened this issue Sep 22, 2024 · 0 comments
Open

UTF-16 limitation on Firefox? #270

Kassy2048 opened this issue Sep 22, 2024 · 0 comments

Comments

@Kassy2048
Copy link

From the user guide: "On Firefox and IE, localStorage cannot contain invalid UTF16 characters."

I've tried the following code in Firefox to check that, and saw no problem at all:

for(let t = 0 ; t < 100 ; ++t) {
    console.log("t=" + t);
    // Generate a 100K array with random 16-bit values
    let array = [];
    for(let i = 0 ; i < 100000 ; ++i) array.push(parseInt(Math.floor(Math.random() * 65536)));
    // Convert it to an UTF-16 string
    const src = String.fromCharCode.apply(null, new Uint16Array(array))
    // Store the string in localStorage
    localStorage._test_string = src;
    // Retrieve the string from localStorage
    const dst = localStorage._test_string;
    // Check the localStorage content matches the original array
    for(let i = 0 ; i < 100000 ; ++i) {
        if(dst.charCodeAt(i) != array[i]) console.warn("Failure for i=" + i, dst.charCodeAt(i), array[i]);
    }
    // Remove the string from localStorage
    delete localStorage._test_string;
}

Is this limitation still valid? If so, how to replicate it? If not, the documentation should probably be updated to indicate this is not a problem anymore on recent versions of all browsers.

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