Skip to content

Function to Serialize JS objects in Query String Parameters #161

@ericperez

Description

@ericperez

This is in reference to this line in the code:
o.data = Object.keys(o.data).map(function(key){ return key + "=" + encodeURIComponent(o.data[key]); }).join("&");

I just noticed that there is a very helpful utility function nested in 'fetch' that is not testable and not reusable even though it has pretty generic functionality (serializing objects into Query String params.)

Thoughts on moving this functionality into it's own utility method that is testable and reusable?

Lastly, I can make a pull request if necessary but I would suggest adding encodeURIComponent to the 'key' variable as well because JavaScript allows characters in object keys that need to be encoded in order to be valid query parameter keys. e.g. var params = { "tom & jerry": "friends" };

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