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

TypeError: formData.hasOwnProperty is not a function #2619

Closed
52cik opened this issue Mar 30, 2017 · 2 comments
Closed

TypeError: formData.hasOwnProperty is not a function #2619

52cik opened this issue Mar 30, 2017 · 2 comments
Labels

Comments

@52cik
Copy link

52cik commented Mar 30, 2017

When formData is created by Object.create(null), the bug is triggered.
Ps: express req.body object is such objects.

const request = require('request');

const formData = Object.create(null);
formData.test = 'test';

request.post({ url: 'http://localhost:3000', formData: formData }, function(err, res, body) {
  if (err) {
    return console.error('upload failed:', err);
  }
  console.log('Upload successful!  Server responded with:', body);
});
$ node app.js
/Users/cik/Desktop/bug/node_modules/request/request.js:330
      if (formData.hasOwnProperty(formKey)) {
                   ^

TypeError: formData.hasOwnProperty is not a function
    at Request.init (/Users/cik/Desktop/bug/node_modules/request/request.js:330:20)
    at new Request (/Users/cik/Desktop/bug/node_modules/request/request.js:130:8)
    at request (/Users/cik/Desktop/bug/node_modules/request/index.js:54:10)
    at Function.post (/Users/cik/Desktop/bug/node_modules/request/index.js:62:12)
    at Object.<anonymous> (/Users/cik/Desktop/bug/app.js:6:9)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
@blinktag
Copy link

Chaging formData.hasOwnProperty(formKey) to Object.prototype.hasOwnProperty.call(formData, formKey) should fix this

@stale
Copy link

stale bot commented Nov 23, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 23, 2018
@52cik 52cik closed this as completed Nov 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants