@@ -56,7 +56,7 @@ FormData.prototype.append = function (field, value, options) {
5656 var append = CombinedStream . prototype . append . bind ( this ) ;
5757
5858 // all that streamy business can't handle numbers
59- if ( typeof value === 'number' ) {
59+ if ( typeof value === 'number' || value == null ) {
6060 value = String ( value ) ;
6161 }
6262
@@ -230,14 +230,14 @@ FormData.prototype._getContentDisposition = function (value, options) {
230230 if ( typeof options . filepath === 'string' ) {
231231 // custom filepath for relative paths
232232 filename = path . normalize ( options . filepath ) . replace ( / \\ / g, '/' ) ;
233- } else if ( options . filename || value . name || value . path ) {
233+ } else if ( options . filename || ( value && ( value . name || value . path ) ) ) {
234234 /*
235235 * custom filename take precedence
236236 * formidable and the browser add a name property
237237 * fs- and request- streams have path property
238238 */
239- filename = path . basename ( options . filename || value . name || value . path ) ;
240- } else if ( value . readable && hasOwn ( value , 'httpVersion' ) ) {
239+ filename = path . basename ( options . filename || ( value && ( value . name || value . path ) ) ) ;
240+ } else if ( value && value . readable && hasOwn ( value , 'httpVersion' ) ) {
241241 // or try http response
242242 filename = path . basename ( value . client . _httpMessage . path || '' ) ;
243243 }
@@ -255,17 +255,17 @@ FormData.prototype._getContentType = function (value, options) {
255255 var contentType = options . contentType ;
256256
257257 // or try `name` from formidable, browser
258- if ( ! contentType && value . name ) {
258+ if ( ! contentType && value && value . name ) {
259259 contentType = mime . lookup ( value . name ) ;
260260 }
261261
262262 // or try `path` from fs-, request- streams
263- if ( ! contentType && value . path ) {
263+ if ( ! contentType && value && value . path ) {
264264 contentType = mime . lookup ( value . path ) ;
265265 }
266266
267267 // or if it's http-reponse
268- if ( ! contentType && value . readable && hasOwn ( value , 'httpVersion' ) ) {
268+ if ( ! contentType && value && value . readable && hasOwn ( value , 'httpVersion' ) ) {
269269 contentType = value . headers [ 'content-type' ] ;
270270 }
271271
@@ -275,7 +275,7 @@ FormData.prototype._getContentType = function (value, options) {
275275 }
276276
277277 // fallback to the default content type if `value` is not simple value
278- if ( ! contentType && typeof value === 'object' ) {
278+ if ( ! contentType && value && typeof value === 'object' ) {
279279 contentType = FormData . DEFAULT_CONTENT_TYPE ;
280280 }
281281
0 commit comments