openfl.net.SharedObject.getLocal inconsistent storage id requirements JS/HTML5

https://api.openfl.org/openfl/net/SharedObject.html#getLocal

https://github.com/openfl/openfl/blob/develop/src/openfl/net/SharedObject.hx

When accessing a local storage with getLocal() you can pass the storage name without path. In this case the function creates the object id in js and html5 by appending name to the browser href using “:” as a separator:

Browser.window.location.href + ":" + name

But if you pass name AND path, the function appends the name to the path using “/” as a separator, so if I want to access the previously created local save with preset path, I can’t do so because the names are different.

var id = localPath + "/" + name;

I can’t pass the full path as a name to getLocal either, because “:” is forbidden for the name:

var illegalValues = [" ", "~", "%", "&", "\\", ";", ":", "\"", "'", ",", "<", ">", "?", "#"];

So there is no way to access the object that was created with omitted path by using the existing full path, that I believe is incorrect. In my case, the portal stores game updates in separate folders, like 1, 2, 3 etc. so I want to copy the saved games from the objects that were created with omitted paths, like

/game_name/3/index.html:save_name

But I can’t :slight_smile:

I could change it as desired by changing the way SharedObject appends name to path:

#if (js && html5)
var id = localPath + ":" + name;
#else
var id = localPath + "/" + name;
#end

But I don’t think I can suggest such a fix to the source code on GitHub, because some may relied on the current “/” delimiter previously and it will make objects created with path and name inaccessible.

A safer way would be to remove “:” from illegal values for name like this:

#if (js && html5)
var illegalValues = [" ", "~", "%", "&", "\\", ";", "\"", "'", ",", "<", ">", "?", "#"];
#else
var illegalValues = [" ", "~", "%", "&", "\\", ";", ":", "\"", "'", ",", "<", ">", "?", "#"];
#end

This sounds reasonable for me, because later the function uses illegal “:” to join path and name for HTML5/JS.

Then I will be able to access the object by passing “” as path and path_without_leading_slash+":"+name to getLocal. Like:

SharedObject.getLocal("game_name/3/index.html:save_name", "");

The function then will let the name with “:” to pass through and make a correct id after

var id = localPath + "/" + name;

But this sounds gimmicky IDK :slight_smile:

This is a tough one since breaking users data would definitely not be a good thing. Perhaps what we could do is check for both when accessing and move safely towards more correct behavior in the future somehow. Considering that “:” is already part of the illegal values, there should never be a conflict where the data path could get mistaken. If you could, please create an issue on github so I dont forget about this one and allow me some time to consider any other pitfalls and assess the situation thoroughly.

Thanks for using OpenFL!

1 Like

OK, thanks, will add an issue!

SharedObject getLocal() inconsistent storage ID naming · Issue #2775 · openfl/openfl · GitHub :sunglasses:

1 Like