Skip to content

Public get/set/remove methods will execute localStorage code if $cookieStore method cause exception #79

@SmilingJoe

Description

@SmilingJoe

For the public get(), set() and remove() methods, if supported == false and any type of exception occurs, the code specific to localStorage will attempt to run, even though supported == false.

For example, this is the current set():

set: function (key, value) {
    if (!supported) {
        try {
            $cookieStore.put(key, value);
            return value;
        } catch(e) {
            $log.log('Local Storage not supported, make sure you have angular-cookies enabled.');
        }
    }
    // THE FOLLOWING LINES RUN WHEN THE CATCH(E) ABOVE IS TRIGGERED
    var saver = angular.toJson(value);
    storage.setItem(key, saver);
    return privateMethods.parseValue(saver);
},

Suggest doing the following:

set: function (key, value) {
    if (!supported) {
        try {
            $cookieStore.put(key, value);
            return value;
        } catch(e) {
            $log.log('Local Storage not supported, make sure you have angular-cookies enabled.');
        }
    }
    else { // THIS CODE WILL NOW ONLY EVER EXECUTE IF (supported)
        var saver = angular.toJson(value);
        storage.setItem(key, saver);
        return privateMethods.parseValue(saver);
    }
},

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