Bump form-data from 4.0.2 to 4.0.4 (#496)

* Bump form-data from 4.0.2 to 4.0.4

Bumps [form-data](https://github.com/form-data/form-data) from 4.0.2 to 4.0.4.
- [Release notes](https://github.com/form-data/form-data/releases)
- [Changelog](https://github.com/form-data/form-data/blob/master/CHANGELOG.md)
- [Commits](https://github.com/form-data/form-data/compare/v4.0.2...v4.0.4)

---
updated-dependencies:
- dependency-name: form-data
  dependency-version: 4.0.4
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

* run build

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Ansgar Mertens <ansgar@hashicorp.com>
This commit is contained in:
dependabot[bot] 2025-07-22 17:00:56 +02:00 committed by GitHub
parent 1428cf0603
commit c0a118784f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 141 additions and 147 deletions

273
dist/index.js vendored
View file

@ -16285,6 +16285,9 @@ module.exports.wrap = wrap;
/***/ 6454:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
"use strict";
var CombinedStream = __nccwpck_require__(5630);
var util = __nccwpck_require__(9023);
var path = __nccwpck_require__(6928);
@ -16293,24 +16296,20 @@ var https = __nccwpck_require__(5692);
var parseUrl = (__nccwpck_require__(7016).parse);
var fs = __nccwpck_require__(9896);
var Stream = (__nccwpck_require__(2203).Stream);
var crypto = __nccwpck_require__(6982);
var mime = __nccwpck_require__(4096);
var asynckit = __nccwpck_require__(1324);
var setToStringTag = __nccwpck_require__(8700);
var hasOwn = __nccwpck_require__(4076);
var populate = __nccwpck_require__(1835);
// Public API
module.exports = FormData;
// make it a Stream
util.inherits(FormData, CombinedStream);
/**
* Create readable "multipart/form-data" streams.
* Can be used to submit forms
* and file uploads to other web applications.
*
* @constructor
* @param {Object} options - Properties to be added/overriden for FormData and CombinedStream
* @param {object} options - Properties to be added/overriden for FormData and CombinedStream
*/
function FormData(options) {
if (!(this instanceof FormData)) {
@ -16323,35 +16322,39 @@ function FormData(options) {
CombinedStream.call(this);
options = options || {};
for (var option in options) {
options = options || {}; // eslint-disable-line no-param-reassign
for (var option in options) { // eslint-disable-line no-restricted-syntax
this[option] = options[option];
}
}
// make it a Stream
util.inherits(FormData, CombinedStream);
FormData.LINE_BREAK = '\r\n';
FormData.DEFAULT_CONTENT_TYPE = 'application/octet-stream';
FormData.prototype.append = function(field, value, options) {
options = options || {};
FormData.prototype.append = function (field, value, options) {
options = options || {}; // eslint-disable-line no-param-reassign
// allow filename as single option
if (typeof options == 'string') {
options = {filename: options};
if (typeof options === 'string') {
options = { filename: options }; // eslint-disable-line no-param-reassign
}
var append = CombinedStream.prototype.append.bind(this);
// all that streamy business can't handle numbers
if (typeof value == 'number') {
value = '' + value;
if (typeof value === 'number' || value == null) {
value = String(value); // eslint-disable-line no-param-reassign
}
// https://github.com/felixge/node-form-data/issues/38
if (Array.isArray(value)) {
// Please convert your array into string
// the way web server expects it
/*
* Please convert your array into string
* the way web server expects it
*/
this._error(new Error('Arrays are not supported.'));
return;
}
@ -16367,15 +16370,17 @@ FormData.prototype.append = function(field, value, options) {
this._trackLength(header, value, options);
};
FormData.prototype._trackLength = function(header, value, options) {
FormData.prototype._trackLength = function (header, value, options) {
var valueLength = 0;
// used w/ getLengthSync(), when length is known.
// e.g. for streaming directly from a remote server,
// w/ a known file a size, and not wanting to wait for
// incoming file to finish to get its size.
/*
* used w/ getLengthSync(), when length is known.
* e.g. for streaming directly from a remote server,
* w/ a known file a size, and not wanting to wait for
* incoming file to finish to get its size.
*/
if (options.knownLength != null) {
valueLength += +options.knownLength;
valueLength += Number(options.knownLength);
} else if (Buffer.isBuffer(value)) {
valueLength = value.length;
} else if (typeof value === 'string') {
@ -16385,12 +16390,10 @@ FormData.prototype._trackLength = function(header, value, options) {
this._valueLength += valueLength;
// @check why add CRLF? does this account for custom/multiple CRLFs?
this._overheadLength +=
Buffer.byteLength(header) +
FormData.LINE_BREAK.length;
this._overheadLength += Buffer.byteLength(header) + FormData.LINE_BREAK.length;
// empty or either doesn't have path or not an http response or not a stream
if (!value || ( !value.path && !(value.readable && Object.prototype.hasOwnProperty.call(value, 'httpVersion')) && !(value instanceof Stream))) {
if (!value || (!value.path && !(value.readable && hasOwn(value, 'httpVersion')) && !(value instanceof Stream))) {
return;
}
@ -16400,9 +16403,8 @@ FormData.prototype._trackLength = function(header, value, options) {
}
};
FormData.prototype._lengthRetriever = function(value, callback) {
if (Object.prototype.hasOwnProperty.call(value, 'fd')) {
FormData.prototype._lengthRetriever = function (value, callback) {
if (hasOwn(value, 'fd')) {
// take read range into a account
// `end` = Infinity > read file till the end
//
@ -16411,54 +16413,52 @@ FormData.prototype._lengthRetriever = function(value, callback) {
// Fix it when node fixes it.
// https://github.com/joyent/node/issues/7819
if (value.end != undefined && value.end != Infinity && value.start != undefined) {
// when end specified
// no need to calculate range
// inclusive, starts with 0
callback(null, value.end + 1 - (value.start ? value.start : 0));
callback(null, value.end + 1 - (value.start ? value.start : 0)); // eslint-disable-line callback-return
// not that fast snoopy
// not that fast snoopy
} else {
// still need to fetch file size from fs
fs.stat(value.path, function(err, stat) {
var fileSize;
fs.stat(value.path, function (err, stat) {
if (err) {
callback(err);
return;
}
// update final size based on the range options
fileSize = stat.size - (value.start ? value.start : 0);
var fileSize = stat.size - (value.start ? value.start : 0);
callback(null, fileSize);
});
}
// or http response
} else if (Object.prototype.hasOwnProperty.call(value, 'httpVersion')) {
callback(null, +value.headers['content-length']);
// or http response
} else if (hasOwn(value, 'httpVersion')) {
callback(null, Number(value.headers['content-length'])); // eslint-disable-line callback-return
// or request stream http://github.com/mikeal/request
} else if (Object.prototype.hasOwnProperty.call(value, 'httpModule')) {
// or request stream http://github.com/mikeal/request
} else if (hasOwn(value, 'httpModule')) {
// wait till response come back
value.on('response', function(response) {
value.on('response', function (response) {
value.pause();
callback(null, +response.headers['content-length']);
callback(null, Number(response.headers['content-length']));
});
value.resume();
// something else
// something else
} else {
callback('Unknown stream');
callback('Unknown stream'); // eslint-disable-line callback-return
}
};
FormData.prototype._multiPartHeader = function(field, value, options) {
// custom header specified (as string)?
// it becomes responsible for boundary
// (e.g. to handle extra CRLFs on .NET servers)
if (typeof options.header == 'string') {
FormData.prototype._multiPartHeader = function (field, value, options) {
/*
* custom header specified (as string)?
* it becomes responsible for boundary
* (e.g. to handle extra CRLFs on .NET servers)
*/
if (typeof options.header === 'string') {
return options.header;
}
@ -16466,7 +16466,7 @@ FormData.prototype._multiPartHeader = function(field, value, options) {
var contentType = this._getContentType(value, options);
var contents = '';
var headers = {
var headers = {
// add custom disposition as third element or keep it two elements if not
'Content-Disposition': ['form-data', 'name="' + field + '"'].concat(contentDisposition || []),
// if no content type. allow it to be empty array
@ -16474,18 +16474,18 @@ FormData.prototype._multiPartHeader = function(field, value, options) {
};
// allow custom headers.
if (typeof options.header == 'object') {
if (typeof options.header === 'object') {
populate(headers, options.header);
}
var header;
for (var prop in headers) {
if (Object.prototype.hasOwnProperty.call(headers, prop)) {
for (var prop in headers) { // eslint-disable-line no-restricted-syntax
if (hasOwn(headers, prop)) {
header = headers[prop];
// skip nullish headers.
if (header == null) {
continue;
continue; // eslint-disable-line no-restricted-syntax, no-continue
}
// convert all headers to arrays.
@ -16503,49 +16503,45 @@ FormData.prototype._multiPartHeader = function(field, value, options) {
return '--' + this.getBoundary() + FormData.LINE_BREAK + contents + FormData.LINE_BREAK;
};
FormData.prototype._getContentDisposition = function(value, options) {
var filename
, contentDisposition
;
FormData.prototype._getContentDisposition = function (value, options) { // eslint-disable-line consistent-return
var filename;
if (typeof options.filepath === 'string') {
// custom filepath for relative paths
filename = path.normalize(options.filepath).replace(/\\/g, '/');
} else if (options.filename || value.name || value.path) {
// custom filename take precedence
// 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 && Object.prototype.hasOwnProperty.call(value, 'httpVersion')) {
} else if (options.filename || (value && (value.name || value.path))) {
/*
* custom filename take precedence
* formidable and the browser add a name property
* fs- and request- streams have path property
*/
filename = path.basename(options.filename || (value && (value.name || value.path)));
} else if (value && value.readable && hasOwn(value, 'httpVersion')) {
// or try http response
filename = path.basename(value.client._httpMessage.path || '');
}
if (filename) {
contentDisposition = 'filename="' + filename + '"';
return 'filename="' + filename + '"';
}
return contentDisposition;
};
FormData.prototype._getContentType = function(value, options) {
FormData.prototype._getContentType = function (value, options) {
// use custom content-type above all
var contentType = options.contentType;
// or try `name` from formidable, browser
if (!contentType && value.name) {
if (!contentType && value && value.name) {
contentType = mime.lookup(value.name);
}
// or try `path` from fs-, request- streams
if (!contentType && value.path) {
if (!contentType && value && value.path) {
contentType = mime.lookup(value.path);
}
// or if it's http-reponse
if (!contentType && value.readable && Object.prototype.hasOwnProperty.call(value, 'httpVersion')) {
if (!contentType && value && value.readable && hasOwn(value, 'httpVersion')) {
contentType = value.headers['content-type'];
}
@ -16555,18 +16551,18 @@ FormData.prototype._getContentType = function(value, options) {
}
// fallback to the default content type if `value` is not simple value
if (!contentType && typeof value == 'object') {
if (!contentType && value && typeof value === 'object') {
contentType = FormData.DEFAULT_CONTENT_TYPE;
}
return contentType;
};
FormData.prototype._multiPartFooter = function() {
return function(next) {
FormData.prototype._multiPartFooter = function () {
return function (next) {
var footer = FormData.LINE_BREAK;
var lastPart = (this._streams.length === 0);
var lastPart = this._streams.length === 0;
if (lastPart) {
footer += this._lastBoundary();
}
@ -16575,18 +16571,18 @@ FormData.prototype._multiPartFooter = function() {
}.bind(this);
};
FormData.prototype._lastBoundary = function() {
FormData.prototype._lastBoundary = function () {
return '--' + this.getBoundary() + '--' + FormData.LINE_BREAK;
};
FormData.prototype.getHeaders = function(userHeaders) {
FormData.prototype.getHeaders = function (userHeaders) {
var header;
var formHeaders = {
'content-type': 'multipart/form-data; boundary=' + this.getBoundary()
};
for (header in userHeaders) {
if (Object.prototype.hasOwnProperty.call(userHeaders, header)) {
for (header in userHeaders) { // eslint-disable-line no-restricted-syntax
if (hasOwn(userHeaders, header)) {
formHeaders[header.toLowerCase()] = userHeaders[header];
}
}
@ -16594,11 +16590,14 @@ FormData.prototype.getHeaders = function(userHeaders) {
return formHeaders;
};
FormData.prototype.setBoundary = function(boundary) {
FormData.prototype.setBoundary = function (boundary) {
if (typeof boundary !== 'string') {
throw new TypeError('FormData boundary must be a string');
}
this._boundary = boundary;
};
FormData.prototype.getBoundary = function() {
FormData.prototype.getBoundary = function () {
if (!this._boundary) {
this._generateBoundary();
}
@ -16606,60 +16605,55 @@ FormData.prototype.getBoundary = function() {
return this._boundary;
};
FormData.prototype.getBuffer = function() {
var dataBuffer = new Buffer.alloc(0);
FormData.prototype.getBuffer = function () {
var dataBuffer = new Buffer.alloc(0); // eslint-disable-line new-cap
var boundary = this.getBoundary();
// Create the form content. Add Line breaks to the end of data.
for (var i = 0, len = this._streams.length; i < len; i++) {
if (typeof this._streams[i] !== 'function') {
// Add content to the buffer.
if(Buffer.isBuffer(this._streams[i])) {
dataBuffer = Buffer.concat( [dataBuffer, this._streams[i]]);
}else {
dataBuffer = Buffer.concat( [dataBuffer, Buffer.from(this._streams[i])]);
if (Buffer.isBuffer(this._streams[i])) {
dataBuffer = Buffer.concat([dataBuffer, this._streams[i]]);
} else {
dataBuffer = Buffer.concat([dataBuffer, Buffer.from(this._streams[i])]);
}
// Add break after content.
if (typeof this._streams[i] !== 'string' || this._streams[i].substring( 2, boundary.length + 2 ) !== boundary) {
dataBuffer = Buffer.concat( [dataBuffer, Buffer.from(FormData.LINE_BREAK)] );
if (typeof this._streams[i] !== 'string' || this._streams[i].substring(2, boundary.length + 2) !== boundary) {
dataBuffer = Buffer.concat([dataBuffer, Buffer.from(FormData.LINE_BREAK)]);
}
}
}
// Add the footer and return the Buffer object.
return Buffer.concat( [dataBuffer, Buffer.from(this._lastBoundary())] );
return Buffer.concat([dataBuffer, Buffer.from(this._lastBoundary())]);
};
FormData.prototype._generateBoundary = function() {
FormData.prototype._generateBoundary = function () {
// This generates a 50 character boundary similar to those used by Firefox.
// They are optimized for boyer-moore parsing.
var boundary = '--------------------------';
for (var i = 0; i < 24; i++) {
boundary += Math.floor(Math.random() * 10).toString(16);
}
this._boundary = boundary;
// They are optimized for boyer-moore parsing.
this._boundary = '--------------------------' + crypto.randomBytes(12).toString('hex');
};
// Note: getLengthSync DOESN'T calculate streams length
// As workaround one can calculate file size manually
// and add it as knownLength option
FormData.prototype.getLengthSync = function() {
// As workaround one can calculate file size manually and add it as knownLength option
FormData.prototype.getLengthSync = function () {
var knownLength = this._overheadLength + this._valueLength;
// Don't get confused, there are 3 "internal" streams for each keyval pair
// so it basically checks if there is any value added to the form
// Don't get confused, there are 3 "internal" streams for each keyval pair so it basically checks if there is any value added to the form
if (this._streams.length) {
knownLength += this._lastBoundary().length;
}
// https://github.com/form-data/form-data/issues/40
if (!this.hasKnownLength()) {
// Some async length retrievers are present
// therefore synchronous length calculation is false.
// Please use getLength(callback) to get proper length
/*
* Some async length retrievers are present
* therefore synchronous length calculation is false.
* Please use getLength(callback) to get proper length
*/
this._error(new Error('Cannot calculate proper length in synchronous way.'));
}
@ -16669,7 +16663,7 @@ FormData.prototype.getLengthSync = function() {
// Public API to check if length of added values is known
// https://github.com/form-data/form-data/issues/196
// https://github.com/form-data/form-data/issues/262
FormData.prototype.hasKnownLength = function() {
FormData.prototype.hasKnownLength = function () {
var hasKnownLength = true;
if (this._valuesToMeasure.length) {
@ -16679,7 +16673,7 @@ FormData.prototype.hasKnownLength = function() {
return hasKnownLength;
};
FormData.prototype.getLength = function(cb) {
FormData.prototype.getLength = function (cb) {
var knownLength = this._overheadLength + this._valueLength;
if (this._streams.length) {
@ -16691,13 +16685,13 @@ FormData.prototype.getLength = function(cb) {
return;
}
asynckit.parallel(this._valuesToMeasure, this._lengthRetriever, function(err, values) {
asynckit.parallel(this._valuesToMeasure, this._lengthRetriever, function (err, values) {
if (err) {
cb(err);
return;
}
values.forEach(function(length) {
values.forEach(function (length) {
knownLength += length;
});
@ -16705,31 +16699,26 @@ FormData.prototype.getLength = function(cb) {
});
};
FormData.prototype.submit = function(params, cb) {
var request
, options
, defaults = {method: 'post'}
;
FormData.prototype.submit = function (params, cb) {
var request;
var options;
var defaults = { method: 'post' };
// parse provided url if it's string
// or treat it as options object
if (typeof params == 'string') {
params = parseUrl(params);
// parse provided url if it's string or treat it as options object
if (typeof params === 'string') {
params = parseUrl(params); // eslint-disable-line no-param-reassign
/* eslint sort-keys: 0 */
options = populate({
port: params.port,
path: params.pathname,
host: params.hostname,
protocol: params.protocol
}, defaults);
// use custom params
} else {
} else { // use custom params
options = populate(params, defaults);
// if no port provided use default one
if (!options.port) {
options.port = options.protocol == 'https:' ? 443 : 80;
options.port = options.protocol === 'https:' ? 443 : 80;
}
}
@ -16737,14 +16726,14 @@ FormData.prototype.submit = function(params, cb) {
options.headers = this.getHeaders(params.headers);
// https if specified, fallback to http in any other case
if (options.protocol == 'https:') {
if (options.protocol === 'https:') {
request = https.request(options);
} else {
request = http.request(options);
}
// get content length and fire away
this.getLength(function(err, length) {
this.getLength(function (err, length) {
if (err && err !== 'Unknown stream') {
this._error(err);
return;
@ -16763,7 +16752,7 @@ FormData.prototype.submit = function(params, cb) {
request.removeListener('error', callback);
request.removeListener('response', onResponse);
return cb.call(this, error, responce);
return cb.call(this, error, responce); // eslint-disable-line no-invalid-this
};
onResponse = callback.bind(this, null);
@ -16776,7 +16765,7 @@ FormData.prototype.submit = function(params, cb) {
return request;
};
FormData.prototype._error = function(err) {
FormData.prototype._error = function (err) {
if (!this.error) {
this.error = err;
this.pause();
@ -16789,18 +16778,22 @@ FormData.prototype.toString = function () {
};
setToStringTag(FormData, 'FormData');
// Public API
module.exports = FormData;
/***/ }),
/***/ 1835:
/***/ ((module) => {
// populates missing values
module.exports = function(dst, src) {
"use strict";
Object.keys(src).forEach(function(prop)
{
dst[prop] = dst[prop] || src[prop];
// populates missing values
module.exports = function (dst, src) {
Object.keys(src).forEach(function (prop) {
dst[prop] = dst[prop] || src[prop]; // eslint-disable-line no-param-reassign
});
return dst;