localForage/localForage

IE 11 - Keys greater in length than 889 characters are truncated.

Open

#444 opened on Sep 4, 2015

View on GitHub
 (11 comments) (0 reactions) (0 assignees)JavaScript (24,184 stars) (1,260 forks)batch import
blockedbughelp wanted

Description

Browser: IE 11 Version: 11.0.9600.17843, Update Versions: 11.0.20 (KB3058515)

Observed Behavior: If a key of length greater than 888 characters is set in IE 11, anything beyond the 889th character is ignored. This means that if I have two keys of 900 characters in length, and only the last 10 characters are different, the last value set will be the one returned for either key.

Expected Behavior: Key length should not affect behavior. Different keys of 900 characters in length should be able to map to different values even if only the last character is different.

To reproduce in console:

function testLocalForageKeyLength(length) {
    // Clear localforage
    localforage.clear();

    // init keys and values
    var key1 = new Array(length+1).join('1'),
        key2 = key1 + '2',// Key2 is 1 character longer than key1.
        val1 = '1',
        val2 = '2';
    localforage.setItem(key1, val1).then(function(){
        localforage.setItem(key2, val2).then(function(){
            localforage.getItem(key1).then(function(v1){
                localforage.getItem(key2).then(function(v2) {
                    var err = false;
                    if (v1 === v2) {
                        err = true;
                        console.error("Failed asserting that values are different.");
                    }
                    if (v1 !== val1) {
                        err = true;
                        console.error("Failed asserting that returned value for key1 is equal to set value for key1.")
                    }
                    if (v2 !== val2) {
                        err = true;
                        console.error("Failed asserting that returned value for key2 is equal to set value for key2.")
                    }
                    if (!err) {
                        console.log("Succeeded asserting that values are different.");
                    }
                    console.log("key1 length: " + key1.length + " key2 length: " + key2.length + " key1 value returned: " + v1 + " key2 value returned: " + v2);
                })
            });
        });
    });
}

testLocalForageKeyLength(10);
// Wait for return of each test before proceeding...
testLocalForageKeyLength(100);
testLocalForageKeyLength(888);
testLocalForageKeyLength(889);

Console Output:

testLocalForageKeyLength(10);
Succeeded asserting that values are different.
key1 length: 10 key2 length: 11 key1 value returned: 1 key2 value returned: 2

testLocalForageKeyLength(100);
Succeeded asserting that values are different.
key1 length: 100 key2 length: 101 key1 value returned: 1 key2 value returned: 2

testLocalForageKeyLength(888);
Succeeded asserting that values are different.
key1 length: 888 key2 length: 889 key1 value returned: 1 key2 value returned: 2

testLocalForageKeyLength(889);
Failed asserting that values are different.
Failed asserting that returned value for key1 is equal to set value for key1.
key1 length: 889 key2 length: 890 key1 value returned: 2 key2 value returned: 2

Contributor guide