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

req.field('key', 'value') is broken #1065

Closed
magicdawn opened this issue Sep 9, 2016 · 7 comments
Closed

req.field('key', 'value') is broken #1065

magicdawn opened this issue Sep 9, 2016 · 7 comments

Comments

@magicdawn
Copy link
Contributor

the 2.0.0 release use form-data@1.0.0-rc4
while will cause

TypeError: Cannot read property 'path' of null
    at FormData._getContentDisposition (/.../node_modules/superagent/node_modules/form-data/lib/form_data.js:195:43)
    at FormData._multiPartHeader (/.../node_modules/superagent/node_modules/form-data/lib/form_data.js:169:33)
    at FormData.append (/.../node_modules/superagent/node_modules/form-data/lib/form_data.js:64:21)
    at Request.exports.field (/.../node_modules/superagent/lib/request-base.js:184:23)

the call chain

@magicdawn
Copy link
Contributor Author

value.length <- the exception

@kornelski
Copy link
Contributor

That looks like a bug in FormData (I don't see what we can do about it in superagent). Can you report the problem there?

@magicdawn
Copy link
Contributor Author

I'm sorry, Just found that error happens when the value is empty.
And can be reproduced by code below:

.field('key'), value is undefined

'use strict';

const request = require('superagent');
const co = require('co');

const main = co.wrap(function*() {
  const res = yield request
    .post('http://localhost')
    .field('x');
});

if (module === process.mainModule) {
  main().catch(e => console.error(e.stack || e));
}

So should we add a assert(value, 'value can not be empty') here or the form-data repo ?

@magicdawn
Copy link
Contributor Author

what does an empty field means in a multipart/form-data ?
Looks there already got some clues

@kornelski
Copy link
Contributor

.set('header',undefined) throws, .query('field',undefined) sets query string to ?field, so it could go either way.

Throwing may be easier, but making undefined remove fields from the form could be more useful.

@magicdawn
Copy link
Contributor Author

Since form-data is going to fix this in v2, and current this will throw a unknown error
TypeError: Cannot read property 'path' of null, and I found a hidden bug in my bussiness code after figuring out what really happens. 😂

@magicdawn
Copy link
Contributor Author

I guess it's better to close solved issues to let the opening issues number down. 😂

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