Skip to content

Commit

Permalink
Fix Firefox 3.0.19 bug: globalStorage object needs to cast to String.
Browse files Browse the repository at this point in the history
Run the following in Firefox 3.0.19:

  gs = window.globalStorage[window.location.hostname];
  gs.s = "string value";
  document.write(typeof(gs.s) + "<br>");

and you will see: object

Despite being assigned a string value, the type is still object.  This breaks
jStorage when used with MooTools because MooTool's JSON.decode does this:

function (string, secure) {
    if ($type(string) != "string" || !string.length) {
        return null;
    }

Hence, we get the error "_storage is null" when using jStorage because it
can't initialize proper;y.  Note that it works with Prototype because their
JSON decoder looks like this:

function (str) {
    return String(str).evalJSON();
}

To fix the issue I've put the String wrapper around _storage_service.jStorage
when we try to decode it.
  • Loading branch information
Dan Hipschman authored and andris9 committed May 17, 2010
1 parent fd113a5 commit a283683
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion jstorage.js
Expand Up @@ -119,7 +119,7 @@
/* if jStorage string is retrieved, then decode it */
if(_storage_service.jStorage){
try{
_storage = json_decode(_storage_service.jStorage);
_storage = json_decode(String(_storage_service.jStorage));
}catch(E3){_storage_service.jStorage = "{}";}
}else{
_storage_service.jStorage = "{}";
Expand Down

0 comments on commit a283683

Please sign in to comment.