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

Empty values of a POST array disappear after being submitted #7

Closed
ibaaj opened this issue Aug 6, 2014 · 8 comments
Closed

Empty values of a POST array disappear after being submitted #7

ibaaj opened this issue Aug 6, 2014 · 8 comments
Assignees
Milestone

Comments

@ibaaj
Copy link

ibaaj commented Aug 6, 2014

Following my conversation with @blipsofadoug on Twitter

He says that It is an issue when you are using "extended" urlencoded body parsing

Empty values of a POST array disappear after being submitted.

HTML :

<form action="" method="post">
        <input type="text" name="data[]" value="snow" />
        <input type="text" name="data[]" value="" />
        <input type="text" name="data[]" value="hey oh" />
        <input type="submit" value="send me the sausage" />
</form>

in php : print_r($_POST['data'])

Array ( [0] => snow [1] => [2] => hey oh )

in nodejs console.log(req.body.data)

[ 'snow', 'hey oh' ]
@dougwilson
Copy link
Contributor

Basically @Syskaw is expecting qs.parse('data[]=snow&data[]=&data[]=hey%20oh') to result in { data: ['snow', '', 'hey oh'] }.

@dougwilson
Copy link
Contributor

Oh, and FWIW, this is not a regression from qs < 1, just something users tend to find weird.

@nlf
Copy link
Collaborator

nlf commented Aug 6, 2014

Ah, so users are expecting the empty strings to stay in place for arrays? I'll take a look and see if that change would break anything, but I don't imagine it will.

@nlf nlf added the request label Aug 6, 2014
@nlf nlf added this to the 1.0.3 milestone Aug 6, 2014
@nlf nlf self-assigned this Aug 6, 2014
@dougwilson
Copy link
Contributor

so users are expecting the empty strings to stay in place for arrays?

it seems that way. I saw that pop up on twitter last night, but i've seen other people asking the same time every so often.

@dougwilson
Copy link
Contributor

mainly something to consider ;) up to you guys how you want to approach it.

@nlf
Copy link
Collaborator

nlf commented Aug 6, 2014

Looks like we already had this behavior for arrays where an index is specified, so I'll add some official tests and make sure it works for normal arrays too.

@dougwilson
Copy link
Contributor

make sure it works for normal arrays too

cool. if you guys change it, i'll make sure to rush out an update for the stuff pinned to 1.0.2

nlf added a commit that referenced this issue Aug 6, 2014
@nlf
Copy link
Collaborator

nlf commented Aug 6, 2014

Closed via 5b63418

@nlf nlf closed this as completed Aug 6, 2014
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

3 participants