diff --git a/.gitignore b/.gitignore index 5790d187..6d8a8023 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,8 @@ package-lock.json coverage/ node_modules/ test/tmp/ + +# Only apps should have lockfiles +npm-shrinkwrap.json +package-lock.json +yarn.lock diff --git a/.npmrc b/.npmrc new file mode 100644 index 00000000..43c97e71 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/lib/form_data.js b/lib/form_data.js index 93164426..39222e58 100644 --- a/lib/form_data.js +++ b/lib/form_data.js @@ -7,6 +7,7 @@ var parseUrl = require('url').parse; var fs = require('fs'); var mime = require('mime-types'); var asynckit = require('asynckit'); +var setToStringTag = require('es-set-tostringtag'); var populate = require('./populate.js'); // Public API @@ -101,7 +102,7 @@ FormData.prototype._trackLength = function(header, value, options) { FormData.LINE_BREAK.length; // empty or either doesn't have path or not an http response - if (!value || ( !value.path && !(value.readable && value.hasOwnProperty('httpVersion')) )) { + if (!value || ( !value.path && !(value.readable && Object.prototype.hasOwnProperty.call(value, 'httpVersion')) )) { return; } @@ -112,8 +113,7 @@ FormData.prototype._trackLength = function(header, value, options) { }; FormData.prototype._lengthRetriever = function(value, callback) { - - if (value.hasOwnProperty('fd')) { + if (Object.prototype.hasOwnProperty.call(value, 'fd')) { // take read range into a account // `end` = Infinity –> read file till the end @@ -148,11 +148,11 @@ FormData.prototype._lengthRetriever = function(value, callback) { } // or http response - } else if (value.hasOwnProperty('httpVersion')) { + } else if (Object.prototype.hasOwnProperty.call(value, 'httpVersion')) { callback(null, +value.headers['content-length']); // or request stream http://github.com/mikeal/request - } else if (value.hasOwnProperty('httpModule')) { + } else if (Object.prototype.hasOwnProperty.call(value, 'httpModule')) { // wait till response come back value.on('response', function(response) { value.pause(); @@ -192,22 +192,23 @@ FormData.prototype._multiPartHeader = function(field, value, options) { var header; for (var prop in headers) { - if (!headers.hasOwnProperty(prop)) continue; - header = headers[prop]; + if (Object.prototype.hasOwnProperty.call(headers, prop)) { + header = headers[prop]; - // skip nullish headers. - if (header == null) { - continue; - } + // skip nullish headers. + if (header == null) { + continue; + } - // convert all headers to arrays. - if (!Array.isArray(header)) { - header = [header]; - } + // convert all headers to arrays. + if (!Array.isArray(header)) { + header = [header]; + } - // add non-empty headers. - if (header.length) { - contents += prop + ': ' + header.join('; ') + FormData.LINE_BREAK; + // add non-empty headers. + if (header.length) { + contents += prop + ': ' + header.join('; ') + FormData.LINE_BREAK; + } } } @@ -228,7 +229,7 @@ FormData.prototype._getContentDisposition = function(value, options) { // formidable and the browser add a name property // fs- and request- streams have path property filename = path.basename(options.filename || value.name || value.path); - } else if (value.readable && value.hasOwnProperty('httpVersion')) { + } else if (value.readable && Object.prototype.hasOwnProperty.call(value, 'httpVersion')) { // or try http response filename = path.basename(value.client._httpMessage.path || ''); } @@ -256,7 +257,7 @@ FormData.prototype._getContentType = function(value, options) { } // or if it's http-reponse - if (!contentType && value.readable && value.hasOwnProperty('httpVersion')) { + if (!contentType && value.readable && Object.prototype.hasOwnProperty.call(value, 'httpVersion')) { contentType = value.headers['content-type']; } @@ -297,7 +298,7 @@ FormData.prototype.getHeaders = function(userHeaders) { }; for (header in userHeaders) { - if (userHeaders.hasOwnProperty(header)) { + if (Object.prototype.hasOwnProperty.call(userHeaders, header)) { formHeaders[header.toLowerCase()] = userHeaders[header]; } } @@ -496,3 +497,4 @@ FormData.prototype._error = function(err) { FormData.prototype.toString = function () { return '[object FormData]'; }; +setToStringTag(FormData, 'FormData'); diff --git a/package.json b/package.json index 9ced4589..37fb8a97 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Felix Geisendörfer (http://debuggable.com/)", "name": "form-data", "description": "A library to create readable \"multipart/form-data\" streams. Can be used to submit forms and file uploads to other web applications.", - "version": "3.0.2", + "version": "3.0.3", "repository": { "type": "git", "url": "git://github.com/form-data/form-data.git" @@ -43,29 +43,30 @@ "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" + "es-set-tostringtag": "^2.1.0", + "mime-types": "^2.1.35" }, "devDependencies": { - "@types/node": "^12.0.10", - "browserify": "^13.1.1", + "@types/node": "^12.20.55", + "browserify": "^13.3.0", "browserify-istanbul": "^2.0.0", - "coveralls": "^3.0.4", - "cross-spawn": "^6.0.5", - "eslint": "^6.0.1", + "coveralls": "^3.1.1", + "cross-spawn": "^6.0.6", + "eslint": "^6.8.0", "fake": "^0.2.2", "far": "^0.0.7", - "formidable": "^1.0.17", - "in-publish": "^2.0.0", + "formidable": "^1.2.6", + "in-publish": "^2.0.1", "is-node-modern": "^1.0.0", "istanbul": "^0.4.5", "obake": "^0.1.2", - "puppeteer": "^1.19.0", - "pkgfiles": "^2.3.0", - "pre-commit": "^1.1.3", - "request": "^2.88.0", + "pkgfiles": "^2.3.2", + "pre-commit": "^1.2.2", + "puppeteer": "^1.20.0", + "request": "~2.87.0", "rimraf": "^2.7.1", - "tape": "^4.6.2", - "typescript": "^3.5.2" + "tape": "^5.9.0", + "typescript": "^3.9.10" }, "license": "MIT" } diff --git a/test/common.js b/test/common.js index 7da855c1..f3d63719 100644 --- a/test/common.js +++ b/test/common.js @@ -40,7 +40,7 @@ common.testFields = function (FIELDS, callback) { var incomingForm = new IncomingForm({uploadDir: common.dir.tmp}); incomingForm.parse(req); - + common.actions.checkForm(incomingForm, FIELDS, function (fieldsChecked) { // keep track of number of the processed fields callback(fieldsPassed - fieldsChecked); @@ -55,18 +55,17 @@ common.testFields = function (FIELDS, callback) { common.actions = {}; // generic form field population -common.actions.populateFields = function(form, fields) -{ +common.actions.populateFields = function (form, fields) { var field; for (var name in fields) { - if (!fields.hasOwnProperty(name)) { continue; } - - field = fields[name]; - // important to append ReadStreams within the same tick - if ((typeof field.value == 'function')) { - field.value = field.value(); + if (Object.prototype.hasOwnProperty.call(fields, name)) { + field = fields[name]; + // important to append ReadStreams within the same tick + if ((typeof field.value == 'function')) { + field.value = field.value(); + } + form.append(name, field.value); } - form.append(name, field.value); } }; diff --git a/test/integration/test-custom-content-type.js b/test/integration/test-custom-content-type.js index d8c1b765..534fdfbd 100644 --- a/test/integration/test-custom-content-type.js +++ b/test/integration/test-custom-content-type.js @@ -67,16 +67,15 @@ server.listen(common.port, function() { var form = new FormData(); - var field; for (var name in FIELDS) { - if (!FIELDS.hasOwnProperty(name)) { continue; } - - field = FIELDS[name]; - // important to append ReadStreams within the same tick - if ((typeof field.value == 'function')) { - field.value = field.value(); + if (Object.prototype.hasOwnProperty.call(FIELDS, name)) { + var field = FIELDS[name]; + // important to append ReadStreams within the same tick + if ((typeof field.value == 'function')) { + field.value = field.value(); + } + form.append(name, field.value, field.options); } - form.append(name, field.value, field.options); } // custom params object passed to submit diff --git a/test/integration/test-pipe.js b/test/integration/test-pipe.js index c3360efc..1b41a02b 100644 --- a/test/integration/test-pipe.js +++ b/test/integration/test-pipe.js @@ -49,16 +49,15 @@ server.listen(common.port, function() { var form = new FormData(); - var field; for (var name in FIELDS) { - if (!FIELDS.hasOwnProperty(name)) { continue; } - - field = FIELDS[name]; - // important to append ReadStreams within the same tick - if ((typeof field.value == 'function')) { - field.value = field.value(); + if (Object.prototype.hasOwnProperty.call(FIELDS, name)) { + var field = FIELDS[name]; + // important to append ReadStreams within the same tick + if ((typeof field.value == 'function')) { + field.value = field.value(); + } + form.append(name, field.value); } - form.append(name, field.value); } var req = http.request({ diff --git a/test/integration/test-ranged-filestream.js b/test/integration/test-ranged-filestream.js index bac1d259..8fa0cafe 100644 --- a/test/integration/test-ranged-filestream.js +++ b/test/integration/test-ranged-filestream.js @@ -80,20 +80,18 @@ server.listen(common.port, function() { // add test subjects to the form for (name in testSubjects) { - if (!testSubjects.hasOwnProperty(name)) { - continue; - } - - options = {encoding: 'utf8'}; + if (Object.prototype.hasOwnProperty.call(testSubjects, name)) { + options = {encoding: 'utf8'}; - if (testSubjects[name].start) { options.start = testSubjects[name].start; } - if (testSubjects[name].end) { options.end = testSubjects[name].end; } + if (testSubjects[name].start) { options.start = testSubjects[name].start; } + if (testSubjects[name].end) { options.end = testSubjects[name].end; } - form.append(name, testSubjects[name].fsStream = fs.createReadStream(common.dir.fixture + '/' + testSubjects[name].file, options)); + form.append(name, testSubjects[name].fsStream = fs.createReadStream(common.dir.fixture + '/' + testSubjects[name].file, options)); - // calculate data size - testSubjects[name].readSize = 0; - testSubjects[name].fsStream.on('data', readSizeAccumulator.bind(testSubjects[name])); + // calculate data size + testSubjects[name].readSize = 0; + testSubjects[name].fsStream.on('data', readSizeAccumulator.bind(testSubjects[name])); + } } form.submit('http://localhost:' + common.port + '/', function(err, res) {