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

Handle null value in form parameters #1832

Closed
germanattanasio opened this issue Oct 11, 2015 · 6 comments
Closed

Handle null value in form parameters #1832

germanattanasio opened this issue Oct 11, 2015 · 6 comments

Comments

@germanattanasio
Copy link

The code below fails because key has null as value:

request({
  url: 'http://service.com/upload',
  method: 'POST',
  formData: {
    foo: 'bar',
    key: null
  }
});

Stacktrace:

if (value.hasOwnProperty('value') && value.hasOwnProperty('options')) {
               ^
TypeError: Cannot read property 'hasOwnProperty' of null
    at appendFormValue (/Users/germana/workspace/node-sdk/node_modules/request/request.js:330:16)
    at Request.init (/Users/germana/workspace/node-sdk/node_modules/request/request.js:344:11)
    at new Request (/Users/germana/workspace/node-sdk/node_modules/request/request.js:140:8)
    at request (/Users/germana/workspace/node-sdk/node_modules/request/index.js:55:10)
    at Object.<anonymous> (/Users/germana/workspace/node-sdk/dialog.js:4:1)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)

I was thinking on create a PR but I don't know how do you want to deal with this scenario?

  1. Ignore the field
  2. Leave the error as it is and invalidate this issue
  3. Send "null"
  4. ...
@simov
Copy link
Member

simov commented Oct 11, 2015

The field should be ignored. The underlying form-data module will most likely throw an error anyway. Stringifying nulls and booleans is language specific and different servers may expect different formats.

@germanattanasio
Copy link
Author

thanks @simov, do you want a PR for this ?

@krusk
Copy link

krusk commented Dec 11, 2015

I have the same issue.

@wilk
Copy link

wilk commented Apr 1, 2016

+1

1 similar comment
@markokhman
Copy link

+1

@simov
Copy link
Member

simov commented May 9, 2016

Request only passes the values to the underlying form-data module. The form-data team is planning to stringify null values in v2.0, see form-data/form-data#147

I just added a test here #2208 that expects the underlying form-data module to throw when the value is null. It still throws, but not in request.

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

5 participants