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

Fix changes introduced in https://github.com/request/request/pull/1282 #1310

Merged
merged 3 commits into from Dec 10, 2014

Conversation

simov
Copy link
Member

@simov simov commented Dec 9, 2014

Fixes #1309

Reverting back the changes introduced in #1282 more info here #1281

For some reason this change brakes the form option when it's object. See below

From the docs

form - when passed an object or a querystring, this sets body to a querystring representation of value, and adds Content-type: application/x-www-form-urlencoded header.

No idea why it brakes yet, that's just the fix. I can confirm the bug by running my system tests in https://github.com/simov/purest/blob/master/test/request/post.js

For some reason this change brakes the form option when it's object
@simov
Copy link
Member Author

simov commented Dec 9, 2014

This is very bad, it turns out that the unit test doesn't catch the bug.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.09%) when pulling f9f96e6 on simov:fix-form-option into 67b4b1a on request:master.

@simov
Copy link
Member Author

simov commented Dec 10, 2014

The problem is that here body is set to a string, and self.form is called before self.json is called and therefore here we're stringifying the body string again.

In short with the current implementation we can support only non string JSON bodies

if (typeof self.body !== 'string')

but that's just too magical.

And of course we need a proper unit test for that combination of options before making any changes to that behavior.

`form` is object, and `json` is set to `true`
Example:
{form: {some: 'url', encoded: 'data'}, json: true}
@simov
Copy link
Member Author

simov commented Dec 10, 2014

Added the missing test case. Now changing if (typeof self.body === 'object') to if (self.body !== undefined) on line https://github.com/simov/request/blob/fix-form-option/request.js#L1485 would throw an error. So #1282 wouldn't even pass.

application/x-www-form-urlencoded requests
as they have their body already stringified as url encoded string
inside the `form` method
@simov
Copy link
Member Author

simov commented Dec 10, 2014

@nylen pushed a fix, also re-enabled the tests for #1282
I think this is really urgent to merge and publish, as more bug reports will definitely arrive.

EDIT: I can confirm this fixes the problem in my module as well.

nylen added a commit that referenced this pull request Dec 10, 2014
@nylen nylen merged commit 4225f05 into request:master Dec 10, 2014
@nylen
Copy link
Member

nylen commented Dec 10, 2014

I have not been following this issue very closely, so thank you for the support!

Version 2.51.0 is out now with this fix.

@simov simov changed the title Revert changes introduced in https://github.com/request/request/pull/1282 Fix changes introduced in https://github.com/request/request/pull/1282 Dec 12, 2014
@simov simov mentioned this pull request Jun 28, 2015
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 this pull request may close these issues.

Weird POST behaviour after upgrading to 2.50.0 (from 2.49.0)
3 participants