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

No need for [] when skipping index for an array #28

Closed
binarykitchen opened this issue Feb 14, 2020 · 6 comments
Closed

No need for [] when skipping index for an array #28

binarykitchen opened this issue Feb 14, 2020 · 6 comments

Comments

@binarykitchen
Copy link

binarykitchen commented Feb 14, 2020

When I have a multi-value attribute like

const formData = {
  name: ['apple', 'bananas']
}

and run this through formurlencoded(formData, { skipIndex: true })

then I expect this to be

name=apple&name=bananas
// in parsed form:
// name: apple
// name: bananas

but not

name%5B%5D=apple&name%5B%5D=bananas
// in parsed form:
// name[]: apple
// name[]: bananas
@binarykitchen
Copy link
Author

To reproduce: Go to https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_form_checkbox

then use this HTML

<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php" method="get">
  <input type="text" name="test" value="Bike">
  <input type="text" name="test" value="Bike2">
  <input type="text" name="test" value="Bike3">
  <input type="text" name="test" value="Bike4">
  <input type="submit" value="Submit">
</form>
</body>
</html>

that will yield test=Bike&test=Bike2&test=Bike3&test=Bike4

@iambumblehead
Copy link
Owner

@binarykitchen I'm not sure when I will be available to look into this. Is it an important issue for you?

Do you think the change would be safe for packages using this package?

@binarykitchen
Copy link
Author

@iambumblehead i think this will become a breaking change. recommend a new version with that behaviour and to add new options for those who want the old behaviour.

yep, important here. i could do a PR today to speeden things up. would you accept that?

@iambumblehead
Copy link
Owner

@binarykitchen that's very kind of you. Yes, a PR with a test would be accepted.

@binarykitchen
Copy link
Author

@iambumblehead lol, forget it. discovered a hidden parameter skipBracket in your code. works now for me. maybe you should document it one day ...

@iambumblehead
Copy link
Owner

I'm sorry for your trouble @binarykitchen. yes it should be documented.

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