Skip to content

Commit

Permalink
use hasOwnProperty in check against files/fields (#522)
Browse files Browse the repository at this point in the history
* use hasOwnProperty in check against files/fields

* Update CHANGELOG.md
  • Loading branch information
tunnckoCore committed Nov 28, 2019
1 parent ba01e7e commit ca2c2b1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* throw error during data parsing ([#513](https://github.com/node-formidable/node-formidable/pull/513))
* Array parameters support (array-like fields) ([#380](https://github.com/node-formidable/node-formidable/pull/380), [#340](https://github.com/node-formidable/node-formidable/pull/340), [#367](https://github.com/node-formidable/node-formidable/pull/367))
* possible partial fix of [#386](https://github.com/node-formidable/node-formidable/pull/386) with #380 (need tests and better implementation)
* use hasOwnProperty in check against files/fields ([#522](https://github.com/node-formidable/node-formidable/pull/522))

### v1.2.1 (2018-03-20)

Expand Down
8 changes: 6 additions & 2 deletions lib/incoming_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ var util = require('util'),
Stream = require('stream').Stream,
os = require('os');

function hasOwnProp(obj, key) {
return Object.prototype.hasOwnProperty.call(obj, key);
}

function IncomingForm(opts) {
if (!(this instanceof IncomingForm)) return new IncomingForm(opts);
EventEmitter.call(this);
Expand Down Expand Up @@ -86,7 +90,7 @@ IncomingForm.prototype.parse = function(req, cb) {
.on('field', function(name, value) {
if (this.multiples && name.slice(-2) === '[]') {
var realName = name.slice(0, name.length - 2);
if (realName in fields) {
if (hasOwnProp(fields, realName)) {
if (!Array.isArray(fields[realName])) {
fields[realName] = [fields[realName]];
}
Expand All @@ -100,7 +104,7 @@ IncomingForm.prototype.parse = function(req, cb) {
})
.on('file', function(name, file) {
if (this.multiples) {
if (files[name]) {
if (hasOwnProp(files, name)) {
if (!Array.isArray(files[name])) {
files[name] = [files[name]];
}
Expand Down

0 comments on commit ca2c2b1

Please sign in to comment.