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

Wrong parseQuery return value in case of query with array containing empty element #76

Closed
cherrybar opened this issue Aug 30, 2022 · 0 comments · Fixed by #103
Closed

Comments

@cherrybar
Copy link

Function parseQuery returns this object for query 'param=3&param=':

{
    param: [
        "3",
        ""
    ]
}

But return value for query 'param=&param=3' is different:

{
    param: "3"
}

As i figured out, it happens because of using if (obj[key]) condition, instead of checking if (obj[key] !== undefined)

    if (obj[key]) { <-- here is a problem 
      if (Array.isArray(obj[key])) {
        obj[key].push(value);
      } else {
        obj[key] = [obj[key], value];
      }
    } else {
      obj[key] = value;
    }
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

Successfully merging a pull request may close this issue.

1 participant