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

add method for case-insensitive query parameter existence check #294

Open
brettwgreen opened this issue May 5, 2016 · 2 comments
Open

Comments

@brettwgreen
Copy link

While according to RFC spec, query params are case-sensitive, there should be a method allowing for case-insensitive search for query params when just checking for existence.

var uri = "http://www.acme.com?test=1"
uri.hasQuery("TEST"); //returns false

New function signature would look like this:

URI.hasQueryParameter = function (data, name, caseSensitive) {
    //force undefined params
    var param3, param4;
    return URI.hasQuery(data, name, param3, param4, caseSensitive);
}

...with new param to main hasQuery method:

URI.hasQuery = function (data, name, value, withinArray, caseSensitive) {
// SNIP...
        switch (getType(value)) {
            case 'Undefined':
                // true if exists (but may be empty)
                return !caseSensitive ? name in data : return data[name] !== undefined;
// SNIP...
}
uri.hasQueryParameter("TEST", false); //returns true
uri.hasQueryParameter("TEST", true); //returns false

This approach maintains backwards compatibility without ugly calls from client script.

@rodneyrehm
Copy link
Member

Thank you for your feedback! I have yet to see a system that treats query data case-insensitive. I'll leave this to the community to decide…

@brettwgreen
Copy link
Author

Not a problem with the data... the key is the problem. I can see the key often being case-insensitive in many systems

Realized I can use RegExp in the latest URI.js for hasQuery and removeQuery... I can pass a regex like /TEST/i to get what I want.

In the version we were on, RegEx option did not yet exist for the name property (only the value). That works for hasQuery and removeQuery... doesn't really work for getting the value of the param though.

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

No branches or pull requests

2 participants