Skip to content

UTF-16 limitation on Firefox? #270

@Kassy2048

Description

@Kassy2048

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions