Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb70869d

Browse files
committed
[Fix]append: avoid a crash on nullish values
Fixes#577
1 parent131ae5e commitb70869d

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

‎lib/form_data.js‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ FormData.prototype.append = function (field, value, options) {
5757
varappend=CombinedStream.prototype.append.bind(this);
5858

5959
// all that streamy business can't handle numbers
60-
if(typeofvalue==='number'){
60+
if(typeofvalue==='number'||value==null){
6161
value=String(value);
6262
}
6363

@@ -231,14 +231,14 @@ FormData.prototype._getContentDisposition = function (value, options) {
231231
if(typeofoptions.filepath==='string'){
232232
// custom filepath for relative paths
233233
filename=path.normalize(options.filepath).replace(/\\/g,'/');
234-
}elseif(options.filename||value.name||value.path){
234+
}elseif(options.filename||(value&&(value.name||value.path))){
235235
/*
236236
* custom filename take precedence
237237
* formidable and the browser add a name property
238238
* fs- and request- streams have path property
239239
*/
240-
filename=path.basename(options.filename||value.name||value.path);
241-
}elseif(value.readable&&hasOwn(value,'httpVersion')){
240+
filename=path.basename(options.filename||(value&&(value.name||value.path)));
241+
}elseif(value&&value.readable&&hasOwn(value,'httpVersion')){
242242
// or try http response
243243
filename=path.basename(value.client._httpMessage.path||'');
244244
}
@@ -256,17 +256,17 @@ FormData.prototype._getContentType = function (value, options) {
256256
varcontentType=options.contentType;
257257

258258
// or try `name` from formidable, browser
259-
if(!contentType&&value.name){
259+
if(!contentType&&value&&value.name){
260260
contentType=mime.lookup(value.name);
261261
}
262262

263263
// or try `path` from fs-, request- streams
264-
if(!contentType&&value.path){
264+
if(!contentType&&value&&value.path){
265265
contentType=mime.lookup(value.path);
266266
}
267267

268268
// or if it's http-reponse
269-
if(!contentType&&value.readable&&hasOwn(value,'httpVersion')){
269+
if(!contentType&&value&&value.readable&&hasOwn(value,'httpVersion')){
270270
contentType=value.headers['content-type'];
271271
}
272272

@@ -276,7 +276,7 @@ FormData.prototype._getContentType = function (value, options) {
276276
}
277277

278278
// fallback to the default content type if `value` is not simple value
279-
if(!contentType&&typeofvalue==='object'){
279+
if(!contentType&&value&&typeofvalue==='object'){
280280
contentType=FormData.DEFAULT_CONTENT_TYPE;
281281
}
282282

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
3+
varcommon=require('../common');
4+
varassert=common.assert;
5+
6+
varFormData=require(common.dir.lib+'/form_data');
7+
8+
(functiontestSetUndefined(){
9+
varform=newFormData();
10+
11+
assert.doesNotThrow(function(){
12+
form.append('key',undefined);
13+
});
14+
15+
varbuffer=form.getBuffer();
16+
17+
assert.deepEqual(buffer.toString().split(form.getBoundary()),[
18+
'--',
19+
'\r\nContent-Disposition: form-data; name="key"\r\n\r\nundefined\r\n--',
20+
'--\r\n',
21+
]);
22+
}());

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp