Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should handle querystrings in case-insensitive manner #96

Closed
buddyackerman opened this issue May 10, 2017 · 3 comments
Closed

Should handle querystrings in case-insensitive manner #96

buddyackerman opened this issue May 10, 2017 · 3 comments

Comments

@buddyackerman
Copy link

You never know if a user or some other system is going to provide a querystring parameter in the same case that you expect. There should be an option that allows you to specify case insensitive handling and if this option is on (in fact it should be the default) then all querystring parameters come in as lowercase (properties or key names)

e.g

http;//www.my.website.com/somepage.html?QuerYpaRam1=somevalue

Result

{ queryparam1: somevalue }

@sindresorhus
Copy link
Owner

I disagree and none of the other querystring implementations do this either.

I want to follow URLSearchParams as much as possible:

x = new URLSearchParams('FOO=1&foo=2');
console.log(Array.from(x.keys()));
//=> ["FOO", "foo"]

@sindresorhus
Copy link
Owner

You never know if a user or some other system is going to provide a querystring parameter in the same case that you expect.

https://github.com/sindresorhus/lowercase-keys

@buddyackerman
Copy link
Author

I'll disagree with your disagreement. That no other implementations don't do it is a poor argument. This could be made part of the options object passed to the parse function. If you don't want it to be the default, fine but it should be an options. It's obvious that querystring parameters are not case sensitive and any querystring parser should handle them as such.

Anyway, I've change my local version to this

return Object.keys(ret).sort().reduce(function (result, key) {
    var val = ret[key];

    //Lowercase the key
    key = key.toLowerCase();

    if (Boolean(val) && typeof val === 'object' && !Array.isArray(val)) {
        // Sort object keys, not values
        result[key] = keysSorter(val);
    } else {
        result[key] = val;
    }

    return result;
}, Object.create(null));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants