Skip to content

Spaces do not roundtrip with encode_uri #26

@fabio-looker

Description

@fabio-looker

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?

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