Let's say I want to put a JSON object into a query/hash parameter. For example, obj={x:" &"}
URL querystrings/hashes often contain multiple ampersand-delimited parameters. So...
function getHash(key){
return document.location.hash.slice(1).split("&")
.filter(param => param.indexOf(encodeURIComponent(key)+"=")===0)
.map(param => decodeURIComponent(param.split("=").slice(1).join("=")))
[0]
}
Great, now let's try rison.encode
document.location = "#obj="+rison.encode(obj);
// #obj=(x:' &')
rison.decode(getHash('obj'))
// rison parser error: unmatched "'"
// (because & gets treated as a delimiter before rison...)
Hmm, ok, let's try rison.encode_uri
document.location = "#obj="+rison.encode_uri(obj);
// #obj=(x:'+%26')
rison.decode(getHash('obj'))
// {x: "+&"}
// :(
I guess I have to use the corresponding decoder?
rison.decode_uri
// undefined
// :(
Yes, this is easy to work around, but it seems there is no right way to do this with the out-of-the-box methods?
Let's say I want to put a JSON object into a query/hash parameter. For example,
obj={x:" &"}URL querystrings/hashes often contain multiple ampersand-delimited parameters. So...
Great, now let's try rison.encode
Hmm, ok, let's try rison.encode_uri
I guess I have to use the corresponding decoder?
Yes, this is easy to work around, but it seems there is no right way to do this with the out-of-the-box methods?