Update to NPM version
This commit is contained in:
92
ProjectSourceCode/node_modules/formidable/CHANGELOG.md
generated
vendored
Normal file
92
ProjectSourceCode/node_modules/formidable/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
# Changelog
|
||||
|
||||
### Unreleased (`canary` & `dev` dist-tags)
|
||||
|
||||
* feat: add options.filter ([#716](https://github.com/node-formidable/formidable/pull/716))
|
||||
* feat: add code and httpCode to most errors ([#686](https://github.com/node-formidable/formidable/pull/686))
|
||||
* rename: option.hash into option.hashAlgorithm ([#689](https://github.com/node-formidable/formidable/pull/689))
|
||||
* rename: file.path into file.filepath ([#689](https://github.com/node-formidable/formidable/pull/689))
|
||||
* rename: file.type into file.mimetype ([#689](https://github.com/node-formidable/formidable/pull/689))
|
||||
* refactor: split file.name into file.newFilename and file.originalFilename ([#689](https://github.com/node-formidable/formidable/pull/689))
|
||||
* feat: prevent directory traversal attacks by default ([#689](https://github.com/node-formidable/formidable/pull/689))
|
||||
* meta: stop including test files in npm ([7003c](https://github.com/node-formidable/formidable/commit/7003cd6133f90c384081accb51743688d5e1f4be))
|
||||
* fix: handle invalid filenames ([d0a34](https://github.com/node-formidable/formidable/commit/d0a3484b048b8c177e62d66aecb03f5928f7a857))
|
||||
* feat: add fileWriteStreamHandler option
|
||||
* feat: add allowEmptyFiles and minFileSize options
|
||||
* feat: Array support for fields and files ([#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), [#33](https://github.com/node-formidable/node-formidable/issues/33), [#498](https://github.com/node-formidable/node-formidable/issues/498), [#280](https://github.com/node-formidable/node-formidable/issues/280), [#483](https://github.com/node-formidable/node-formidable/issues/483))
|
||||
* possible partial fix of [#386](https://github.com/node-formidable/node-formidable/pull/386) with #380 (need tests and better implementation)
|
||||
* refactor: use hasOwnProperty in check against files/fields ([#522](https://github.com/node-formidable/node-formidable/pull/522))
|
||||
* meta: do not promote `IncomingForm` and add `exports.default` ([#529](https://github.com/node-formidable/node-formidable/pull/529))
|
||||
* meta: Improve examples and tests ([#523](https://github.com/node-formidable/node-formidable/pull/523))
|
||||
* refactor: First step of Code quality improvements ([#525](https://github.com/node-formidable/node-formidable/pull/525))
|
||||
* chore(funding): remove patreon & add npm funding field ([#525](https://github.com/node-formidable/node-formidable/pull/532)
|
||||
* feat: use Modern Streams API ([#531](https://github.com/node-formidable/node-formidable/pull/531))
|
||||
* fix: urlencoded parsing to emit end [#543](https://github.com/node-formidable/node-formidable/pull/543), introduced in [#531](https://github.com/node-formidable/node-formidable/pull/531)
|
||||
* fix(tests): include multipart and qs parser unit tests, part of [#415](https://github.com/node-formidable/node-formidable/issues/415)
|
||||
* fix: reorganize exports + move parsers to `src/parsers/`
|
||||
* fix: update docs and examples [#544](https://github.com/node-formidable/node-formidable/pull/544) ([#248](https://github.com/node-formidable/node-formidable/issues/248), [#335](https://github.com/node-formidable/node-formidable/issues/335), [#371](https://github.com/node-formidable/node-formidable/issues/371), [#372](https://github.com/node-formidable/node-formidable/issues/372), [#387](https://github.com/node-formidable/node-formidable/issues/387), partly [#471](https://github.com/node-formidable/node-formidable/issues/471), [#535](https://github.com/node-formidable/node-formidable/issues/535))
|
||||
* feat: introduce Plugins API, fix silent failing tests ([#545](https://github.com/node-formidable/node-formidable/pull/545), [#391](https://github.com/node-formidable/node-formidable/pull/391), [#407](https://github.com/node-formidable/node-formidable/pull/407), [#386](https://github.com/node-formidable/node-formidable/pull/386), [#374](https://github.com/node-formidable/node-formidable/pull/374), [#521](https://github.com/node-formidable/node-formidable/pull/521), [#267](https://github.com/node-formidable/node-formidable/pull/267))
|
||||
* fix: exposing file writable stream errors ([#520](https://github.com/node-formidable/node-formidable/pull/520), [#316](https://github.com/node-formidable/node-formidable/pull/316), [#469](https://github.com/node-formidable/node-formidable/pull/469), [#470](https://github.com/node-formidable/node-formidable/pull/470))
|
||||
* feat: custom file (re)naming, thru options.filename ([#591](https://github.com/node-formidable/node-formidable/pull/591), [#84](https://github.com/node-formidable/node-formidable/issues/84), [#86](https://github.com/node-formidable/node-formidable/issues/86), [#94](https://github.com/node-formidable/node-formidable/issues/94), [#154](https://github.com/node-formidable/node-formidable/issues/154), [#158](https://github.com/node-formidable/node-formidable/issues/158), [#488](https://github.com/node-formidable/node-formidable/issues/488), [#595](https://github.com/node-formidable/node-formidable/issues/595))
|
||||
|
||||
|
||||
|
||||
### v1.2.1 (2018-03-20)
|
||||
|
||||
* `maxFileSize` option with default of 200MB (Charlike Mike Reagent, Nima Shahri)
|
||||
* Simplified buffering in JSON parser to avoid denial of service attack (Kornel)
|
||||
* Fixed upload file cleanup on aborted requests (liaoweiqiang)
|
||||
* Fixed error handling of closed _writeStream (Vitalii)
|
||||
|
||||
### v1.1.1 (2017-01-15)
|
||||
|
||||
* Fix DeprecationWarning about os.tmpDir() (Christian)
|
||||
* Update `buffer.write` order of arguments for Node 7 (Kornel Lesiński)
|
||||
* JSON Parser emits error events to the IncomingForm (alessio.montagnani)
|
||||
* Improved Content-Disposition parsing (Sebastien)
|
||||
* Access WriteStream of fs during runtime instead of include time (Jonas Amundsen)
|
||||
* Use built-in toString to convert buffer to hex (Charmander)
|
||||
* Add hash to json if present (Nick Stamas)
|
||||
* Add license to package.json (Simen Bekkhus)
|
||||
|
||||
### v1.0.14 (2013-05-03)
|
||||
|
||||
* Add failing hash tests. (Ben Trask)
|
||||
* Enable hash calculation again (Eugene Girshov)
|
||||
* Test for immediate data events (Tim Smart)
|
||||
* Re-arrange IncomingForm#parse (Tim Smart)
|
||||
|
||||
### v1.0.13
|
||||
|
||||
* Only update hash if update method exists (Sven Lito)
|
||||
* According to travis v0.10 needs to go quoted (Sven Lito)
|
||||
* Bumping build node versions (Sven Lito)
|
||||
* Additional fix for empty requests (Eugene Girshov)
|
||||
* Change the default to 1000, to match the new Node behaviour. (OrangeDog)
|
||||
* Add ability to control maxKeys in the querystring parser. (OrangeDog)
|
||||
* Adjust test case to work with node 0.9.x (Eugene Girshov)
|
||||
* Update package.json (Sven Lito)
|
||||
* Path adjustment according to eb4468b (Markus Ast)
|
||||
|
||||
### v1.0.12
|
||||
|
||||
* Emit error on aborted connections (Eugene Girshov)
|
||||
* Add support for empty requests (Eugene Girshov)
|
||||
* Fix name/filename handling in Content-Disposition (jesperp)
|
||||
* Tolerate malformed closing boundary in multipart (Eugene Girshov)
|
||||
* Ignore preamble in multipart messages (Eugene Girshov)
|
||||
* Add support for application/json (Mike Frey, Carlos Rodriguez)
|
||||
* Add support for Base64 encoding (Elmer Bulthuis)
|
||||
* Add File#toJSON (TJ Holowaychuk)
|
||||
* Remove support for Node.js 0.4 & 0.6 (Andrew Kelley)
|
||||
* Documentation improvements (Sven Lito, Andre Azevedo)
|
||||
* Add support for application/octet-stream (Ion Lupascu, Chris Scribner)
|
||||
* Use os.tmpdir() to get tmp directory (Andrew Kelley)
|
||||
* Improve package.json (Andrew Kelley, Sven Lito)
|
||||
* Fix benchmark script (Andrew Kelley)
|
||||
* Fix scope issue in incoming_forms (Sven Lito)
|
||||
* Fix file handle leak on error (OrangeDog)
|
||||
|
||||
---
|
||||
|
||||
[First commit, #3270eb4b1f8b (May 4th, 2010)](https://github.com/node-formidable/formidable/commit/3270eb4b1f8bb667b8c12f64c36a4e7b854216d8)
|
||||
21
ProjectSourceCode/node_modules/formidable/LICENSE
generated
vendored
Normal file
21
ProjectSourceCode/node_modules/formidable/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2011-present Felix Geisendörfer, and contributors.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
826
ProjectSourceCode/node_modules/formidable/README.md
generated
vendored
Normal file
826
ProjectSourceCode/node_modules/formidable/README.md
generated
vendored
Normal file
@@ -0,0 +1,826 @@
|
||||
<p align="center">
|
||||
<img alt="npm formidable package logo" src="https://raw.githubusercontent.com/node-formidable/formidable/master/logo.png" />
|
||||
</p>
|
||||
|
||||
# formidable [![npm version][npmv-img]][npmv-url] [![MIT license][license-img]][license-url] [![Libera Manifesto][libera-manifesto-img]][libera-manifesto-url] [![Twitter][twitter-img]][twitter-url]
|
||||
|
||||
> A Node.js module for parsing form data, especially file uploads.
|
||||
|
||||
[![Code style][codestyle-img]][codestyle-url]
|
||||
[![codecoverage][codecov-img]][codecov-url]
|
||||
[![linux build status][linux-build-img]][build-url]
|
||||
[![windows build status][windows-build-img]][build-url]
|
||||
[![macos build status][macos-build-img]][build-url]
|
||||
|
||||
If you have any _how-to_ kind of questions, please read the [Contributing
|
||||
Guide][contributing-url] and [Code of Conduct][code_of_conduct-url]
|
||||
documents.<br /> For bugs reports and feature requests, [please create an
|
||||
issue][open-issue-url] or ping [@tunnckoCore / @3a1FcBx0](https://twitter.com/3a1FcBx0)
|
||||
at Twitter.
|
||||
|
||||
[![Conventional Commits][ccommits-img]][ccommits-url]
|
||||
[![Minimum Required Nodejs][nodejs-img]][npmv-url]
|
||||
[![Tidelift Subcsription][tidelift-img]][tidelift-url]
|
||||
[![Buy me a Kofi][kofi-img]][kofi-url]
|
||||
[![Renovate App Status][renovateapp-img]][renovateapp-url]
|
||||
[![Make A Pull Request][prs-welcome-img]][prs-welcome-url]
|
||||
|
||||
This project is [semantically versioned](https://semver.org) and available as
|
||||
part of the [Tidelift Subscription][tidelift-url] for professional grade
|
||||
assurances, enhanced support and security.
|
||||
[Learn more.](https://tidelift.com/subscription/pkg/npm-formidable?utm_source=npm-formidable&utm_medium=referral&utm_campaign=enterprise)
|
||||
|
||||
_The maintainers of `formidable` and thousands of other packages are working
|
||||
with Tidelift to deliver commercial support and maintenance for the Open Source
|
||||
dependencies you use to build your applications. Save time, reduce risk, and
|
||||
improve code health, while paying the maintainers of the exact dependencies you
|
||||
use._
|
||||
|
||||
[![][npm-weekly-img]][npmv-url] [![][npm-monthly-img]][npmv-url]
|
||||
[![][npm-yearly-img]][npmv-url] [![][npm-alltime-img]][npmv-url]
|
||||
|
||||
## Project Status: Maintained
|
||||
|
||||
_Check [VERSION NOTES](https://github.com/node-formidable/formidable/blob/master/VERSION_NOTES.md) for more information on v1, v2, and v3 plans, NPM dist-tags and branches._
|
||||
|
||||
This module was initially developed by
|
||||
[**@felixge**](https://github.com/felixge) for
|
||||
[Transloadit](http://transloadit.com/), a service focused on uploading and
|
||||
encoding images and videos. It has been battle-tested against hundreds of GBs of
|
||||
file uploads from a large variety of clients and is considered production-ready
|
||||
and is used in production for years.
|
||||
|
||||
Currently, we are few maintainers trying to deal with it. :) More contributors
|
||||
are always welcome! :heart: Jump on
|
||||
[issue #412](https://github.com/felixge/node-formidable/issues/412) which is
|
||||
closed, but if you are interested we can discuss it and add you after strict
|
||||
rules, like enabling Two-Factor Auth in your npm and GitHub accounts.
|
||||
|
||||
## Highlights
|
||||
|
||||
- [Fast (~900-2500 mb/sec)](#benchmarks) & streaming multipart parser
|
||||
- Automatically writing file uploads to disk (optional, see
|
||||
[`options.fileWriteStreamHandler`](#options))
|
||||
- [Plugins API](#useplugin-plugin) - allowing custom parsers and plugins
|
||||
- Low memory footprint
|
||||
- Graceful error handling
|
||||
- Very high test coverage
|
||||
|
||||
## Install
|
||||
|
||||
This project requires `Node.js >= 10.13`. Install it using
|
||||
[yarn](https://yarnpkg.com) or [npm](https://npmjs.com).<br /> _We highly
|
||||
recommend to use Yarn when you think to contribute to this project._
|
||||
|
||||
This is a low-level package, and if you're using a high-level framework it _may_
|
||||
already be included. Check the examples below and the [examples/](https://github.com/node-formidable/formidable/tree/master/examples) folder.
|
||||
|
||||
```sh
|
||||
# v2
|
||||
npm install formidable
|
||||
npm install formidable@latest
|
||||
npm install formidable@v2
|
||||
|
||||
# or v3
|
||||
npm install formidable@v3
|
||||
```
|
||||
|
||||
_**Note:** In near future v3 will be published on the `latest` NPM dist-tag. Future not ready releases will continue to be published on `canary` dist-tag._
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
For more examples look at the `examples/` directory.
|
||||
|
||||
### with Node.js http module
|
||||
|
||||
Parse an incoming file upload, with the
|
||||
[Node.js's built-in `http` module](https://nodejs.org/api/http.html).
|
||||
|
||||
```js
|
||||
const http = require('http');
|
||||
const formidable = require('formidable');
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
if (req.url === '/api/upload' && req.method.toLowerCase() === 'post') {
|
||||
// parse a file upload
|
||||
const form = formidable({ multiples: true });
|
||||
|
||||
form.parse(req, (err, fields, files) => {
|
||||
if (err) {
|
||||
res.writeHead(err.httpCode || 400, { 'Content-Type': 'text/plain' });
|
||||
res.end(String(err));
|
||||
return;
|
||||
}
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({ fields, files }, null, 2));
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// show a file upload form
|
||||
res.writeHead(200, { 'Content-Type': 'text/html' });
|
||||
res.end(`
|
||||
<h2>With Node.js <code>"http"</code> module</h2>
|
||||
<form action="/api/upload" enctype="multipart/form-data" method="post">
|
||||
<div>Text field title: <input type="text" name="title" /></div>
|
||||
<div>File: <input type="file" name="multipleFiles" multiple="multiple" /></div>
|
||||
<input type="submit" value="Upload" />
|
||||
</form>
|
||||
`);
|
||||
});
|
||||
|
||||
server.listen(8080, () => {
|
||||
console.log('Server listening on http://localhost:8080/ ...');
|
||||
});
|
||||
```
|
||||
|
||||
### with Express.js
|
||||
|
||||
There are multiple variants to do this, but Formidable just need Node.js Request
|
||||
stream, so something like the following example should work just fine, without
|
||||
any third-party [Express.js](https://ghub.now.sh/express) middleware.
|
||||
|
||||
Or try the
|
||||
[examples/with-express.js](https://github.com/node-formidable/formidable/blob/master/examples/with-express.js)
|
||||
|
||||
```js
|
||||
const express = require('express');
|
||||
const formidable = require('formidable');
|
||||
|
||||
const app = express();
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.send(`
|
||||
<h2>With <code>"express"</code> npm package</h2>
|
||||
<form action="/api/upload" enctype="multipart/form-data" method="post">
|
||||
<div>Text field title: <input type="text" name="title" /></div>
|
||||
<div>File: <input type="file" name="someExpressFiles" multiple="multiple" /></div>
|
||||
<input type="submit" value="Upload" />
|
||||
</form>
|
||||
`);
|
||||
});
|
||||
|
||||
app.post('/api/upload', (req, res, next) => {
|
||||
const form = formidable({ multiples: true });
|
||||
|
||||
form.parse(req, (err, fields, files) => {
|
||||
if (err) {
|
||||
next(err);
|
||||
return;
|
||||
}
|
||||
res.json({ fields, files });
|
||||
});
|
||||
});
|
||||
|
||||
app.listen(3000, () => {
|
||||
console.log('Server listening on http://localhost:3000 ...');
|
||||
});
|
||||
```
|
||||
|
||||
### with Koa and Formidable
|
||||
|
||||
Of course, with [Koa v1, v2 or future v3](https://ghub.now.sh/koa) the things
|
||||
are very similar. You can use `formidable` manually as shown below or through
|
||||
the [koa-better-body](https://ghub.now.sh/koa-better-body) package which is
|
||||
using `formidable` under the hood and support more features and different
|
||||
request bodies, check its documentation for more info.
|
||||
|
||||
_Note: this example is assuming Koa v2. Be aware that you should pass `ctx.req`
|
||||
which is Node.js's Request, and **NOT** the `ctx.request` which is Koa's Request
|
||||
object - there is a difference._
|
||||
|
||||
```js
|
||||
const Koa = require('koa');
|
||||
const formidable = require('formidable');
|
||||
|
||||
const app = new Koa();
|
||||
|
||||
app.on('error', (err) => {
|
||||
console.error('server error', err);
|
||||
});
|
||||
|
||||
app.use(async (ctx, next) => {
|
||||
if (ctx.url === '/api/upload' && ctx.method.toLowerCase() === 'post') {
|
||||
const form = formidable({ multiples: true });
|
||||
|
||||
// not very elegant, but that's for now if you don't want to use `koa-better-body`
|
||||
// or other middlewares.
|
||||
await new Promise((resolve, reject) => {
|
||||
form.parse(ctx.req, (err, fields, files) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.set('Content-Type', 'application/json');
|
||||
ctx.status = 200;
|
||||
ctx.state = { fields, files };
|
||||
ctx.body = JSON.stringify(ctx.state, null, 2);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
await next();
|
||||
return;
|
||||
}
|
||||
|
||||
// show a file upload form
|
||||
ctx.set('Content-Type', 'text/html');
|
||||
ctx.status = 200;
|
||||
ctx.body = `
|
||||
<h2>With <code>"koa"</code> npm package</h2>
|
||||
<form action="/api/upload" enctype="multipart/form-data" method="post">
|
||||
<div>Text field title: <input type="text" name="title" /></div>
|
||||
<div>File: <input type="file" name="koaFiles" multiple="multiple" /></div>
|
||||
<input type="submit" value="Upload" />
|
||||
</form>
|
||||
`;
|
||||
});
|
||||
|
||||
app.use((ctx) => {
|
||||
console.log('The next middleware is called');
|
||||
console.log('Results:', ctx.state);
|
||||
});
|
||||
|
||||
app.listen(3000, () => {
|
||||
console.log('Server listening on http://localhost:3000 ...');
|
||||
});
|
||||
```
|
||||
|
||||
## Benchmarks
|
||||
|
||||
The benchmark is quite old, from the old codebase. But maybe quite true though.
|
||||
Previously the numbers was around ~500 mb/sec. Currently with moving to the new
|
||||
Node.js Streams API it's faster. You can clearly see the differences between the
|
||||
Node versions.
|
||||
|
||||
_Note: a lot better benchmarking could and should be done in future._
|
||||
|
||||
Benchmarked on 8GB RAM, Xeon X3440 (2.53 GHz, 4 cores, 8 threads)
|
||||
|
||||
```
|
||||
~/github/node-formidable master
|
||||
❯ nve --parallel 8 10 12 13 node benchmark/bench-multipart-parser.js
|
||||
|
||||
⬢ Node 8
|
||||
|
||||
1261.08 mb/sec
|
||||
|
||||
⬢ Node 10
|
||||
|
||||
1113.04 mb/sec
|
||||
|
||||
⬢ Node 12
|
||||
|
||||
2107.00 mb/sec
|
||||
|
||||
⬢ Node 13
|
||||
|
||||
2566.42 mb/sec
|
||||
```
|
||||
|
||||

|
||||
|
||||
## API
|
||||
|
||||
### Formidable / IncomingForm
|
||||
|
||||
All shown are equivalent.
|
||||
|
||||
_Please pass [`options`](#options) to the function/constructor, not by assigning
|
||||
them to the instance `form`_
|
||||
|
||||
```js
|
||||
const formidable = require('formidable');
|
||||
const form = formidable(options);
|
||||
|
||||
// or
|
||||
const { formidable } = require('formidable');
|
||||
const form = formidable(options);
|
||||
|
||||
// or
|
||||
const { IncomingForm } = require('formidable');
|
||||
const form = new IncomingForm(options);
|
||||
|
||||
// or
|
||||
const { Formidable } = require('formidable');
|
||||
const form = new Formidable(options);
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
See it's defaults in [src/Formidable.js DEFAULT_OPTIONS](./src/Formidable.js)
|
||||
(the `DEFAULT_OPTIONS` constant).
|
||||
|
||||
- `options.encoding` **{string}** - default `'utf-8'`; sets encoding for
|
||||
incoming form fields,
|
||||
- `options.uploadDir` **{string}** - default `os.tmpdir()`; the directory for
|
||||
placing file uploads in. You can move them later by using `fs.rename()`.
|
||||
- `options.keepExtensions` **{boolean}** - default `false`; to include the
|
||||
extensions of the original files or not
|
||||
- `options.allowEmptyFiles` **{boolean}** - default `true`; allow upload empty
|
||||
files
|
||||
- `options.minFileSize` **{number}** - default `1` (1byte); the minium size of
|
||||
uploaded file.
|
||||
- `options.maxFileSize` **{number}** - default `200 * 1024 * 1024` (200mb);
|
||||
limit the size of uploaded file.
|
||||
- `options.maxFields` **{number}** - default `1000`; limit the number of fields, set 0 for unlimited
|
||||
- `options.maxFieldsSize` **{number}** - default `20 * 1024 * 1024` (20mb);
|
||||
limit the amount of memory all fields together (except files) can allocate in
|
||||
bytes.
|
||||
- `options.hashAlgorithm` **{string | false}** - default `false`; include checksums calculated
|
||||
for incoming files, set this to some hash algorithm, see
|
||||
[crypto.createHash](https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm_options)
|
||||
for available algorithms
|
||||
- `options.fileWriteStreamHandler` **{function}** - default `null`, which by
|
||||
default writes to host machine file system every file parsed; The function
|
||||
should return an instance of a
|
||||
[Writable stream](https://nodejs.org/api/stream.html#stream_class_stream_writable)
|
||||
that will receive the uploaded file data. With this option, you can have any
|
||||
custom behavior regarding where the uploaded file data will be streamed for.
|
||||
If you are looking to write the file uploaded in other types of cloud storages
|
||||
(AWS S3, Azure blob storage, Google cloud storage) or private file storage,
|
||||
this is the option you're looking for. When this option is defined the default
|
||||
behavior of writing the file in the host machine file system is lost.
|
||||
- `options.multiples` **{boolean}** - default `false`; when you call the
|
||||
`.parse` method, the `files` argument (of the callback) will contain arrays of
|
||||
files for inputs which submit multiple files using the HTML5 `multiple`
|
||||
attribute. Also, the `fields` argument will contain arrays of values for
|
||||
fields that have names ending with '[]'.
|
||||
- `options.filename` **{function}** - default `undefined` Use it to control
|
||||
newFilename. Must return a string. Will be joined with options.uploadDir.
|
||||
|
||||
- `options.filter` **{function}** - default function that always returns true.
|
||||
Use it to filter files before they are uploaded. Must return a boolean.
|
||||
|
||||
|
||||
#### `options.filename` **{function}** function (name, ext, part, form) -> string
|
||||
|
||||
_**Note:** If this size of combined fields, or size of some file is exceeded, an
|
||||
`'error'` event is fired._
|
||||
|
||||
```js
|
||||
// The amount of bytes received for this form so far.
|
||||
form.bytesReceived;
|
||||
```
|
||||
|
||||
```js
|
||||
// The expected number of bytes in this form.
|
||||
form.bytesExpected;
|
||||
```
|
||||
|
||||
#### `options.filter` **{function}** function ({name, originalFilename, mimetype}) -> boolean
|
||||
|
||||
**Note:** use an outside variable to cancel all uploads upon the first error
|
||||
|
||||
```js
|
||||
const options = {
|
||||
filter: function ({name, originalFilename, mimetype}) {
|
||||
// keep only images
|
||||
return mimetype && mimetype.includes("image");
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
|
||||
### .parse(request, callback)
|
||||
|
||||
Parses an incoming Node.js `request` containing form data. If `callback` is
|
||||
provided, all fields and files are collected and passed to the callback.
|
||||
|
||||
```js
|
||||
const formidable = require('formidable');
|
||||
|
||||
const form = formidable({ multiples: true, uploadDir: __dirname });
|
||||
|
||||
form.parse(req, (err, fields, files) => {
|
||||
console.log('fields:', fields);
|
||||
console.log('files:', files);
|
||||
});
|
||||
```
|
||||
|
||||
You may overwrite this method if you are interested in directly accessing the
|
||||
multipart stream. Doing so will disable any `'field'` / `'file'` events
|
||||
processing which would occur otherwise, making you fully responsible for
|
||||
handling the processing.
|
||||
|
||||
About `uploadDir`, given the following directory structure
|
||||
```
|
||||
project-name
|
||||
├── src
|
||||
│ └── server.js
|
||||
│
|
||||
└── uploads
|
||||
└── image.jpg
|
||||
```
|
||||
|
||||
`__dirname` would be the same directory as the source file itself (src)
|
||||
|
||||
|
||||
```js
|
||||
`${__dirname}/../uploads`
|
||||
```
|
||||
|
||||
to put files in uploads.
|
||||
|
||||
Omitting `__dirname` would make the path relative to the current working directory. This would be the same if server.js is launched from src but not project-name.
|
||||
|
||||
|
||||
`null` will use default which is `os.tmpdir()`
|
||||
|
||||
Note: If the directory does not exist, the uploaded files are __silently discarded__. To make sure it exists:
|
||||
|
||||
```js
|
||||
import {createNecessaryDirectoriesSync} from "filesac";
|
||||
|
||||
|
||||
const uploadPath = `${__dirname}/../uploads`;
|
||||
createNecessaryDirectoriesSync(`${uploadPath}/x`);
|
||||
```
|
||||
|
||||
|
||||
In the example below, we listen on couple of events and direct them to the
|
||||
`data` listener, so you can do whatever you choose there, based on whether its
|
||||
before the file been emitted, the header value, the header name, on field, on
|
||||
file and etc.
|
||||
|
||||
Or the other way could be to just override the `form.onPart` as it's shown a bit
|
||||
later.
|
||||
|
||||
```js
|
||||
form.once('error', console.error);
|
||||
|
||||
form.on('fileBegin', (formname, file) => {
|
||||
form.emit('data', { name: 'fileBegin', formname, value: file });
|
||||
});
|
||||
|
||||
form.on('file', (formname, file) => {
|
||||
form.emit('data', { name: 'file', formname, value: file });
|
||||
});
|
||||
|
||||
form.on('field', (fieldName, fieldValue) => {
|
||||
form.emit('data', { name: 'field', key: fieldName, value: fieldValue });
|
||||
});
|
||||
|
||||
form.once('end', () => {
|
||||
console.log('Done!');
|
||||
});
|
||||
|
||||
// If you want to customize whatever you want...
|
||||
form.on('data', ({ name, key, value, buffer, start, end, formname, ...more }) => {
|
||||
if (name === 'partBegin') {
|
||||
}
|
||||
if (name === 'partData') {
|
||||
}
|
||||
if (name === 'headerField') {
|
||||
}
|
||||
if (name === 'headerValue') {
|
||||
}
|
||||
if (name === 'headerEnd') {
|
||||
}
|
||||
if (name === 'headersEnd') {
|
||||
}
|
||||
if (name === 'field') {
|
||||
console.log('field name:', key);
|
||||
console.log('field value:', value);
|
||||
}
|
||||
if (name === 'file') {
|
||||
console.log('file:', formname, value);
|
||||
}
|
||||
if (name === 'fileBegin') {
|
||||
console.log('fileBegin:', formname, value);
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### .use(plugin: Plugin)
|
||||
|
||||
A method that allows you to extend the Formidable library. By default we include
|
||||
4 plugins, which esentially are adapters to plug the different built-in parsers.
|
||||
|
||||
**The plugins added by this method are always enabled.**
|
||||
|
||||
_See [src/plugins/](./src/plugins/) for more detailed look on default plugins._
|
||||
|
||||
The `plugin` param has such signature:
|
||||
|
||||
```typescript
|
||||
function(formidable: Formidable, options: Options): void;
|
||||
```
|
||||
|
||||
The architecture is simple. The `plugin` is a function that is passed with the
|
||||
Formidable instance (the `form` across the README examples) and the options.
|
||||
|
||||
**Note:** the plugin function's `this` context is also the same instance.
|
||||
|
||||
```js
|
||||
const formidable = require('formidable');
|
||||
|
||||
const form = formidable({ keepExtensions: true });
|
||||
|
||||
form.use((self, options) => {
|
||||
// self === this === form
|
||||
console.log('woohoo, custom plugin');
|
||||
// do your stuff; check `src/plugins` for inspiration
|
||||
});
|
||||
|
||||
form.parse(req, (error, fields, files) => {
|
||||
console.log('done!');
|
||||
});
|
||||
```
|
||||
|
||||
**Important to note**, is that inside plugin `this.options`, `self.options` and
|
||||
`options` MAY or MAY NOT be the same. General best practice is to always use the
|
||||
`this`, so you can later test your plugin independently and more easily.
|
||||
|
||||
If you want to disable some parsing capabilities of Formidable, you can disable
|
||||
the plugin which corresponds to the parser. For example, if you want to disable
|
||||
multipart parsing (so the [src/parsers/Multipart.js](./src/parsers/Multipart.js)
|
||||
which is used in [src/plugins/multipart.js](./src/plugins/multipart.js)), then
|
||||
you can remove it from the `options.enabledPlugins`, like so
|
||||
|
||||
```js
|
||||
const { Formidable } = require('formidable');
|
||||
|
||||
const form = new Formidable({
|
||||
hashAlgorithm: 'sha1',
|
||||
enabledPlugins: ['octetstream', 'querystring', 'json'],
|
||||
});
|
||||
```
|
||||
|
||||
**Be aware** that the order _MAY_ be important too. The names corresponds 1:1 to
|
||||
files in [src/plugins/](./src/plugins) folder.
|
||||
|
||||
Pull requests for new built-in plugins MAY be accepted - for example, more
|
||||
advanced querystring parser. Add your plugin as a new file in `src/plugins/`
|
||||
folder (lowercased) and follow how the other plugins are made.
|
||||
|
||||
### form.onPart
|
||||
|
||||
If you want to use Formidable to only handle certain parts for you, you can do
|
||||
something similar. Or see
|
||||
[#387](https://github.com/node-formidable/node-formidable/issues/387) for
|
||||
inspiration, you can for example validate the mime-type.
|
||||
|
||||
```js
|
||||
const form = formidable();
|
||||
|
||||
form.onPart = (part) => {
|
||||
part.on('data', (buffer) => {
|
||||
// do whatever you want here
|
||||
});
|
||||
};
|
||||
```
|
||||
|
||||
For example, force Formidable to be used only on non-file "parts" (i.e., html
|
||||
fields)
|
||||
|
||||
```js
|
||||
const form = formidable();
|
||||
|
||||
form.onPart = function (part) {
|
||||
// let formidable handle only non-file parts
|
||||
if (part.originalFilename === '' || !part.mimetype) {
|
||||
// used internally, please do not override!
|
||||
form._handlePart(part);
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
### File
|
||||
|
||||
```ts
|
||||
export interface File {
|
||||
// The size of the uploaded file in bytes.
|
||||
// If the file is still being uploaded (see `'fileBegin'` event),
|
||||
// this property says how many bytes of the file have been written to disk yet.
|
||||
file.size: number;
|
||||
|
||||
// The path this file is being written to. You can modify this in the `'fileBegin'` event in
|
||||
// case you are unhappy with the way formidable generates a temporary path for your files.
|
||||
file.filepath: string;
|
||||
|
||||
// The name this file had according to the uploading client.
|
||||
file.originalFilename: string | null;
|
||||
|
||||
// calculated based on options provided
|
||||
file.newFilename: string | null;
|
||||
|
||||
// The mime type of this file, according to the uploading client.
|
||||
file.mimetype: string | null;
|
||||
|
||||
// A Date object (or `null`) containing the time this file was last written to.
|
||||
// Mostly here for compatibility with the [W3C File API Draft](http://dev.w3.org/2006/webapi/FileAPI/).
|
||||
file.mtime: Date | null;
|
||||
|
||||
file.hashAlgorithm: false | |'sha1' | 'md5' | 'sha256'
|
||||
// If `options.hashAlgorithm` calculation was set, you can read the hex digest out of this var (at the end it will be a string)
|
||||
file.hash: string | object | null;
|
||||
}
|
||||
```
|
||||
|
||||
#### file.toJSON()
|
||||
|
||||
This method returns a JSON-representation of the file, allowing you to
|
||||
`JSON.stringify()` the file which is useful for logging and responding to
|
||||
requests.
|
||||
|
||||
### Events
|
||||
|
||||
#### `'progress'`
|
||||
|
||||
Emitted after each incoming chunk of data that has been parsed. Can be used to
|
||||
roll your own progress bar.
|
||||
|
||||
```js
|
||||
form.on('progress', (bytesReceived, bytesExpected) => {});
|
||||
```
|
||||
|
||||
#### `'field'`
|
||||
|
||||
Emitted whenever a field / value pair has been received.
|
||||
|
||||
```js
|
||||
form.on('field', (name, value) => {});
|
||||
```
|
||||
|
||||
#### `'fileBegin'`
|
||||
|
||||
Emitted whenever a new file is detected in the upload stream. Use this event if
|
||||
you want to stream the file to somewhere else while buffering the upload on the
|
||||
file system.
|
||||
|
||||
```js
|
||||
form.on('fileBegin', (formName, file) => {
|
||||
// accessible here
|
||||
// formName the name in the form (<input name="thisname" type="file">) or http filename for octetstream
|
||||
// file.originalFilename http filename or null if there was a parsing error
|
||||
// file.newFilename generated hexoid or what options.filename returned
|
||||
// file.filepath default pathnme as per options.uploadDir and options.filename
|
||||
// file.filepath = CUSTOM_PATH // to change the final path
|
||||
});
|
||||
```
|
||||
|
||||
#### `'file'`
|
||||
|
||||
Emitted whenever a field / file pair has been received. `file` is an instance of
|
||||
`File`.
|
||||
|
||||
```js
|
||||
form.on('file', (formname, file) => {
|
||||
// same as fileBegin, except
|
||||
// it is too late to change file.filepath
|
||||
// file.hash is available if options.hash was used
|
||||
});
|
||||
```
|
||||
|
||||
#### `'error'`
|
||||
|
||||
Emitted when there is an error processing the incoming form. A request that
|
||||
experiences an error is automatically paused, you will have to manually call
|
||||
`request.resume()` if you want the request to continue firing `'data'` events.
|
||||
|
||||
May have `error.httpCode` and `error.code` attached.
|
||||
|
||||
```js
|
||||
form.on('error', (err) => {});
|
||||
```
|
||||
|
||||
#### `'aborted'`
|
||||
|
||||
Emitted when the request was aborted by the user. Right now this can be due to a
|
||||
'timeout' or 'close' event on the socket. After this event is emitted, an
|
||||
`error` event will follow. In the future there will be a separate 'timeout'
|
||||
event (needs a change in the node core).
|
||||
|
||||
```js
|
||||
form.on('aborted', () => {});
|
||||
```
|
||||
|
||||
#### `'end'`
|
||||
|
||||
Emitted when the entire request has been received, and all contained files have
|
||||
finished flushing to disk. This is a great place for you to send your response.
|
||||
|
||||
```js
|
||||
form.on('end', () => {});
|
||||
```
|
||||
|
||||
## Changelog
|
||||
|
||||
[./CHANGELOG.md](./CHANGELOG.md)
|
||||
|
||||
## Ports & Credits
|
||||
|
||||
- [multipart-parser](http://github.com/FooBarWidget/multipart-parser): a C++
|
||||
parser based on formidable
|
||||
- [Ryan Dahl](http://twitter.com/ryah) for his work on
|
||||
[http-parser](http://github.com/ry/http-parser) which heavily inspired the
|
||||
initial `multipart_parser.js`.
|
||||
|
||||
## Contributing
|
||||
|
||||
If the documentation is unclear or has a typo, please click on the page's `Edit`
|
||||
button (pencil icon) and suggest a correction. If you would like to help us fix
|
||||
a bug or add a new feature, please check our [Contributing
|
||||
Guide][contributing-url]. Pull requests are welcome!
|
||||
|
||||
Thanks goes to these wonderful people
|
||||
([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
||||
|
||||
<!-- ALL-CONTRIBUTORS-LIST:START -->
|
||||
<!-- prettier-ignore-start -->
|
||||
<!-- markdownlint-disable -->
|
||||
<table>
|
||||
<tr>
|
||||
<td align="center"><a href="https://twitter.com/felixge"><img src="https://avatars3.githubusercontent.com/u/15000?s=460&v=4" width="100px;" alt=""/><br /><sub><b>Felix Geisendörfer</b></sub></a><br /><a href="https://github.com/node-formidable/node-formidable/commits?author=felixge" title="Code">💻</a> <a href="#design-felixge" title="Design">🎨</a> <a href="#ideas-felixge" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/node-formidable/node-formidable/commits?author=felixge" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://tunnckoCore.com"><img src="https://avatars3.githubusercontent.com/u/5038030?v=4" width="100px;" alt=""/><br /><sub><b>Charlike Mike Reagent</b></sub></a><br /><a href="https://github.com/node-formidable/node-formidable/issues?q=author%3AtunnckoCore" title="Bug reports">🐛</a> <a href="#infra-tunnckoCore" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#design-tunnckoCore" title="Design">🎨</a> <a href="https://github.com/node-formidable/node-formidable/commits?author=tunnckoCore" title="Code">💻</a> <a href="https://github.com/node-formidable/node-formidable/commits?author=tunnckoCore" title="Documentation">📖</a> <a href="#example-tunnckoCore" title="Examples">💡</a> <a href="#ideas-tunnckoCore" title="Ideas, Planning, & Feedback">🤔</a> <a href="#maintenance-tunnckoCore" title="Maintenance">🚧</a> <a href="https://github.com/node-formidable/node-formidable/commits?author=tunnckoCore" title="Tests">⚠️</a></td>
|
||||
<td align="center"><a href="https://github.com/kedarv"><img src="https://avatars1.githubusercontent.com/u/1365665?v=4" width="100px;" alt=""/><br /><sub><b>Kedar</b></sub></a><br /><a href="https://github.com/node-formidable/node-formidable/commits?author=kedarv" title="Code">💻</a> <a href="https://github.com/node-formidable/node-formidable/commits?author=kedarv" title="Tests">⚠️</a> <a href="#question-kedarv" title="Answering Questions">💬</a> <a href="https://github.com/node-formidable/node-formidable/issues?q=author%3Akedarv" title="Bug reports">🐛</a></td>
|
||||
<td align="center"><a href="https://github.com/GrosSacASac"><img src="https://avatars0.githubusercontent.com/u/5721194?v=4" width="100px;" alt=""/><br /><sub><b>Walle Cyril</b></sub></a><br /><a href="#question-GrosSacASac" title="Answering Questions">💬</a> <a href="https://github.com/node-formidable/node-formidable/issues?q=author%3AGrosSacASac" title="Bug reports">🐛</a> <a href="https://github.com/node-formidable/node-formidable/commits?author=GrosSacASac" title="Code">💻</a> <a href="#financial-GrosSacASac" title="Financial">💵</a> <a href="#ideas-GrosSacASac" title="Ideas, Planning, & Feedback">🤔</a> <a href="#maintenance-GrosSacASac" title="Maintenance">🚧</a></td>
|
||||
<td align="center"><a href="https://github.com/xarguments"><img src="https://avatars2.githubusercontent.com/u/40522463?v=4" width="100px;" alt=""/><br /><sub><b>Xargs</b></sub></a><br /><a href="#question-xarguments" title="Answering Questions">💬</a> <a href="https://github.com/node-formidable/node-formidable/issues?q=author%3Axarguments" title="Bug reports">🐛</a> <a href="https://github.com/node-formidable/node-formidable/commits?author=xarguments" title="Code">💻</a> <a href="#maintenance-xarguments" title="Maintenance">🚧</a></td>
|
||||
<td align="center"><a href="https://github.com/Amit-A"><img src="https://avatars1.githubusercontent.com/u/7987238?v=4" width="100px;" alt=""/><br /><sub><b>Amit-A</b></sub></a><br /><a href="#question-Amit-A" title="Answering Questions">💬</a> <a href="https://github.com/node-formidable/node-formidable/issues?q=author%3AAmit-A" title="Bug reports">🐛</a> <a href="https://github.com/node-formidable/node-formidable/commits?author=Amit-A" title="Code">💻</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><a href="https://charmander.me/"><img src="https://avatars1.githubusercontent.com/u/1889843?v=4" width="100px;" alt=""/><br /><sub><b>Charmander</b></sub></a><br /><a href="#question-charmander" title="Answering Questions">💬</a> <a href="https://github.com/node-formidable/node-formidable/issues?q=author%3Acharmander" title="Bug reports">🐛</a> <a href="https://github.com/node-formidable/node-formidable/commits?author=charmander" title="Code">💻</a> <a href="#ideas-charmander" title="Ideas, Planning, & Feedback">🤔</a> <a href="#maintenance-charmander" title="Maintenance">🚧</a></td>
|
||||
<td align="center"><a href="https://twitter.com/dylan_piercey"><img src="https://avatars2.githubusercontent.com/u/4985201?v=4" width="100px;" alt=""/><br /><sub><b>Dylan Piercey</b></sub></a><br /><a href="#ideas-DylanPiercey" title="Ideas, Planning, & Feedback">🤔</a></td>
|
||||
<td align="center"><a href="http://ochrona.jawne.info.pl"><img src="https://avatars1.githubusercontent.com/u/3618479?v=4" width="100px;" alt=""/><br /><sub><b>Adam Dobrawy</b></sub></a><br /><a href="https://github.com/node-formidable/node-formidable/issues?q=author%3Aad-m" title="Bug reports">🐛</a> <a href="https://github.com/node-formidable/node-formidable/commits?author=ad-m" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://github.com/amitrohatgi"><img src="https://avatars3.githubusercontent.com/u/12177021?v=4" width="100px;" alt=""/><br /><sub><b>amitrohatgi</b></sub></a><br /><a href="#ideas-amitrohatgi" title="Ideas, Planning, & Feedback">🤔</a></td>
|
||||
<td align="center"><a href="https://github.com/fengxinming"><img src="https://avatars2.githubusercontent.com/u/6262382?v=4" width="100px;" alt=""/><br /><sub><b>Jesse Feng</b></sub></a><br /><a href="https://github.com/node-formidable/node-formidable/issues?q=author%3Afengxinming" title="Bug reports">🐛</a></td>
|
||||
<td align="center"><a href="https://qtmsheep.com"><img src="https://avatars1.githubusercontent.com/u/7271496?v=4" width="100px;" alt=""/><br /><sub><b>Nathanael Demacon</b></sub></a><br /><a href="#question-quantumsheep" title="Answering Questions">💬</a> <a href="https://github.com/node-formidable/node-formidable/commits?author=quantumsheep" title="Code">💻</a> <a href="https://github.com/node-formidable/node-formidable/pulls?q=is%3Apr+reviewed-by%3Aquantumsheep" title="Reviewed Pull Requests">👀</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><a href="https://github.com/MunMunMiao"><img src="https://avatars1.githubusercontent.com/u/18216142?v=4" width="100px;" alt=""/><br /><sub><b>MunMunMiao</b></sub></a><br /><a href="https://github.com/node-formidable/node-formidable/issues?q=author%3AMunMunMiao" title="Bug reports">🐛</a></td>
|
||||
<td align="center"><a href="https://github.com/gabipetrovay"><img src="https://avatars0.githubusercontent.com/u/1170398?v=4" width="100px;" alt=""/><br /><sub><b>Gabriel Petrovay</b></sub></a><br /><a href="https://github.com/node-formidable/node-formidable/issues?q=author%3Agabipetrovay" title="Bug reports">🐛</a> <a href="https://github.com/node-formidable/node-formidable/commits?author=gabipetrovay" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/Elzair"><img src="https://avatars0.githubusercontent.com/u/2352818?v=4" width="100px;" alt=""/><br /><sub><b>Philip Woods</b></sub></a><br /><a href="https://github.com/node-formidable/node-formidable/commits?author=Elzair" title="Code">💻</a> <a href="#ideas-Elzair" title="Ideas, Planning, & Feedback">🤔</a></td>
|
||||
<td align="center"><a href="https://github.com/dmolim"><img src="https://avatars2.githubusercontent.com/u/7090374?v=4" width="100px;" alt=""/><br /><sub><b>Dmitry Ivonin</b></sub></a><br /><a href="https://github.com/node-formidable/node-formidable/commits?author=dmolim" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://audiobox.fm"><img src="https://avatars1.githubusercontent.com/u/12844?v=4" width="100px;" alt=""/><br /><sub><b>Claudio Poli</b></sub></a><br /><a href="https://github.com/node-formidable/node-formidable/commits?author=masterkain" title="Code">💻</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<!-- markdownlint-enable -->
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
||||
|
||||
From a [Felix blog post](https://felixge.de/2013/03/11/the-pull-request-hack/):
|
||||
|
||||
- [Sven Lito](https://github.com/svnlto) for fixing bugs and merging patches
|
||||
- [egirshov](https://github.com/egirshov) for contributing many improvements to the node-formidable multipart parser
|
||||
- [Andrew Kelley](https://github.com/superjoe30) for also helping with fixing bugs and making improvements
|
||||
- [Mike Frey](https://github.com/mikefrey) for contributing JSON support
|
||||
|
||||
## License
|
||||
|
||||
Formidable is licensed under the [MIT License][license-url].
|
||||
|
||||
<!-- badges -->
|
||||
<!-- prettier-ignore-start -->
|
||||
|
||||
[codestyle-url]: https://github.com/airbnb/javascript
|
||||
[codestyle-img]: https://badgen.net/badge/code%20style/airbnb%20%2B%20prettier/ff5a5f?icon=airbnb&cache=300
|
||||
[codecov-url]: https://codecov.io/gh/node-formidable/formidable
|
||||
[codecov-img]: https://badgen.net/codecov/c/github/node-formidable/formidable/master?icon=codecov
|
||||
[npmv-canary-img]: https://badgen.net/npm/v/formidable/canary?icon=npm
|
||||
[npmv-dev-img]: https://badgen.net/npm/v/formidable/dev?icon=npm
|
||||
[npmv-img]: https://badgen.net/npm/v/formidable?icon=npm
|
||||
[npmv-url]: https://npmjs.com/package/formidable
|
||||
[license-img]: https://badgen.net/npm/license/formidable
|
||||
[license-url]: https://github.com/node-formidable/formidable/blob/master/LICENSE
|
||||
[chat-img]: https://badgen.net/badge/chat/on%20gitter/46BC99?icon=gitter
|
||||
[chat-url]: https://gitter.im/node-formidable/Lobby
|
||||
[libera-manifesto-url]: https://liberamanifesto.com
|
||||
[libera-manifesto-img]: https://badgen.net/badge/libera/manifesto/grey
|
||||
[renovateapp-url]: https://renovatebot.com
|
||||
[renovateapp-img]: https://badgen.net/badge/renovate/enabled/green?cache=300
|
||||
[prs-welcome-img]: https://badgen.net/badge/PRs/welcome/green?cache=300
|
||||
[prs-welcome-url]: http://makeapullrequest.com
|
||||
[twitter-url]: https://twitter.com/3a1fcBx0
|
||||
[twitter-img]: https://badgen.net/twitter/follow/3a1fcBx0?icon=twitter&color=1da1f2&cache=300
|
||||
|
||||
[npm-weekly-img]: https://badgen.net/npm/dw/formidable?icon=npm&cache=300
|
||||
[npm-monthly-img]: https://badgen.net/npm/dm/formidable?icon=npm&cache=300
|
||||
[npm-yearly-img]: https://badgen.net/npm/dy/formidable?icon=npm&cache=300
|
||||
[npm-alltime-img]: https://badgen.net/npm/dt/formidable?icon=npm&cache=300&label=total%20downloads
|
||||
|
||||
[nodejs-img]: https://badgen.net/badge/node/>=%2010.13/green?cache=300
|
||||
|
||||
[ccommits-url]: https://conventionalcommits.org/
|
||||
[ccommits-img]: https://badgen.net/badge/conventional%20commits/v1.0.0/green?cache=300
|
||||
|
||||
[contributing-url]: https://github.com/node-formidable/.github/blob/master/CONTRIBUTING.md
|
||||
[code_of_conduct-url]: https://github.com/node-formidable/.github/blob/master/CODE_OF_CONDUCT.md
|
||||
|
||||
[open-issue-url]: https://github.com/node-formidable/formidable/issues/new
|
||||
|
||||
[tidelift-url]: https://tidelift.com/subscription/pkg/npm-formidable?utm_source=npm-formidable&utm_medium=referral&utm_campaign=enterprise
|
||||
[tidelift-img]: https://badgen.net/badge/tidelift/subscription/4B5168?labelColor=F6914D
|
||||
|
||||
[kofi-url]: https://ko-fi.com/tunnckoCore/commissions
|
||||
[kofi-img]: https://badgen.net/badge/ko-fi/support/29abe0c2?cache=300&icon=https://rawcdn.githack.com/tunnckoCore/badgen-icons/f8264c6414e0bec449dd86f2241d50a9b89a1203/icons/kofi.svg
|
||||
|
||||
[linux-build-img]: https://badgen.net/github/checks/node-formidable/formidable/master/ubuntu?cache=300&label=linux%20build&icon=github
|
||||
[macos-build-img]: https://badgen.net/github/checks/node-formidable/formidable/master/macos?cache=300&label=macos%20build&icon=github
|
||||
[windows-build-img]: https://badgen.net/github/checks/node-formidable/formidable/master/windows?cache=300&label=windows%20build&icon=github
|
||||
[build-url]: https://github.com/node-formidable/formidable/actions?query=workflow%3Anodejs
|
||||
<!-- prettier-ignore-end -->
|
||||
43
ProjectSourceCode/node_modules/formidable/node_modules/qs/.editorconfig
generated
vendored
Normal file
43
ProjectSourceCode/node_modules/formidable/node_modules/qs/.editorconfig
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
max_line_length = 160
|
||||
quote_type = single
|
||||
|
||||
[test/*]
|
||||
max_line_length = off
|
||||
|
||||
[LICENSE.md]
|
||||
indent_size = off
|
||||
|
||||
[*.md]
|
||||
max_line_length = off
|
||||
|
||||
[*.json]
|
||||
max_line_length = off
|
||||
|
||||
[Makefile]
|
||||
max_line_length = off
|
||||
|
||||
[CHANGELOG.md]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[LICENSE]
|
||||
indent_size = 2
|
||||
max_line_length = off
|
||||
|
||||
[coverage/**/*]
|
||||
indent_size = off
|
||||
indent_style = off
|
||||
indent = off
|
||||
max_line_length = off
|
||||
|
||||
[.nycrc]
|
||||
indent_style = tab
|
||||
38
ProjectSourceCode/node_modules/formidable/node_modules/qs/.eslintrc
generated
vendored
Normal file
38
ProjectSourceCode/node_modules/formidable/node_modules/qs/.eslintrc
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"root": true,
|
||||
|
||||
"extends": "@ljharb",
|
||||
|
||||
"ignorePatterns": [
|
||||
"dist/",
|
||||
],
|
||||
|
||||
"rules": {
|
||||
"complexity": 0,
|
||||
"consistent-return": 1,
|
||||
"func-name-matching": 0,
|
||||
"id-length": [2, { "min": 1, "max": 25, "properties": "never" }],
|
||||
"indent": [2, 4],
|
||||
"max-lines-per-function": [2, { "max": 150 }],
|
||||
"max-params": [2, 18],
|
||||
"max-statements": [2, 100],
|
||||
"multiline-comment-style": 0,
|
||||
"no-continue": 1,
|
||||
"no-magic-numbers": 0,
|
||||
"no-restricted-syntax": [2, "BreakStatement", "DebuggerStatement", "ForInStatement", "LabeledStatement", "WithStatement"],
|
||||
},
|
||||
|
||||
"overrides": [
|
||||
{
|
||||
"files": "test/**",
|
||||
"rules": {
|
||||
"function-paren-newline": 0,
|
||||
"max-lines-per-function": 0,
|
||||
"max-statements": 0,
|
||||
"no-buffer-constructor": 0,
|
||||
"no-extend-native": 0,
|
||||
"no-throw-literal": 0,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
12
ProjectSourceCode/node_modules/formidable/node_modules/qs/.github/FUNDING.yml
generated
vendored
Normal file
12
ProjectSourceCode/node_modules/formidable/node_modules/qs/.github/FUNDING.yml
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: [ljharb]
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: npm/qs
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
custom: # Replace with a single custom sponsorship URL
|
||||
13
ProjectSourceCode/node_modules/formidable/node_modules/qs/.nycrc
generated
vendored
Normal file
13
ProjectSourceCode/node_modules/formidable/node_modules/qs/.nycrc
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"all": true,
|
||||
"check-coverage": false,
|
||||
"reporter": ["text-summary", "text", "html", "json"],
|
||||
"lines": 86,
|
||||
"statements": 85.93,
|
||||
"functions": 82.43,
|
||||
"branches": 76.06,
|
||||
"exclude": [
|
||||
"coverage",
|
||||
"dist"
|
||||
]
|
||||
}
|
||||
582
ProjectSourceCode/node_modules/formidable/node_modules/qs/CHANGELOG.md
generated
vendored
Normal file
582
ProjectSourceCode/node_modules/formidable/node_modules/qs/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,582 @@
|
||||
## **6.12.0**
|
||||
|
||||
- [New] `parse`/`stringify`: add `decodeDotInKeys`/`encodeDotKeys` options (#488)
|
||||
- [New] `parse`: add `duplicates` option
|
||||
- [New] `parse`/`stringify`: add `allowEmptyArrays` option to allow [] in object values (#487)
|
||||
- [Refactor] `parse`/`stringify`: move allowDots config logic to its own variable
|
||||
- [Refactor] `stringify`: move option-handling code into `normalizeStringifyOptions`
|
||||
- [readme] update readme, add logos (#484)
|
||||
- [readme] `stringify`: clarify default `arrayFormat` behavior
|
||||
- [readme] fix line wrapping
|
||||
- [readme] remove dead badges
|
||||
- [Deps] update `side-channel`
|
||||
- [meta] make the dist build 50% smaller
|
||||
- [meta] add `sideEffects` flag
|
||||
- [meta] run build in prepack, not prepublish
|
||||
- [Tests] `parse`: remove useless tests; add coverage
|
||||
- [Tests] `stringify`: increase coverage
|
||||
- [Tests] use `mock-property`
|
||||
- [Tests] `stringify`: improve coverage
|
||||
- [Dev Deps] update `@ljharb/eslint-config `, `aud`, `has-override-mistake`, `has-property-descriptors`, `mock-property`, `npmignore`, `object-inspect`, `tape`
|
||||
- [Dev Deps] pin `glob`, since v10.3.8+ requires a broken `jackspeak`
|
||||
- [Dev Deps] pin `jackspeak` since 2.1.2+ depends on npm aliases, which kill the install process in npm < 6
|
||||
|
||||
## **6.11.2**
|
||||
- [Fix] `parse`: Fix parsing when the global Object prototype is frozen (#473)
|
||||
- [Tests] add passing test cases with empty keys (#473)
|
||||
|
||||
## **6.11.1**
|
||||
- [Fix] `stringify`: encode comma values more consistently (#463)
|
||||
- [readme] add usage of `filter` option for injecting custom serialization, i.e. of custom types (#447)
|
||||
- [meta] remove extraneous code backticks (#457)
|
||||
- [meta] fix changelog markdown
|
||||
- [actions] update checkout action
|
||||
- [actions] restrict action permissions
|
||||
- [Dev Deps] update `@ljharb/eslint-config`, `aud`, `object-inspect`, `tape`
|
||||
|
||||
## **6.11.0**
|
||||
- [New] [Fix] `stringify`: revert 0e903c0; add `commaRoundTrip` option (#442)
|
||||
- [readme] fix version badge
|
||||
|
||||
## **6.10.5**
|
||||
- [Fix] `stringify`: with `arrayFormat: comma`, properly include an explicit `[]` on a single-item array (#434)
|
||||
|
||||
## **6.10.4**
|
||||
- [Fix] `stringify`: with `arrayFormat: comma`, include an explicit `[]` on a single-item array (#441)
|
||||
- [meta] use `npmignore` to autogenerate an npmignore file
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `has-symbol`, `object-inspect`, `tape`
|
||||
|
||||
## **6.10.3**
|
||||
- [Fix] `parse`: ignore `__proto__` keys (#428)
|
||||
- [Robustness] `stringify`: avoid relying on a global `undefined` (#427)
|
||||
- [actions] reuse common workflows
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `object-inspect`, `tape`
|
||||
|
||||
## **6.10.2**
|
||||
- [Fix] `stringify`: actually fix cyclic references (#426)
|
||||
- [Fix] `stringify`: avoid encoding arrayformat comma when `encodeValuesOnly = true` (#424)
|
||||
- [readme] remove travis badge; add github actions/codecov badges; update URLs
|
||||
- [Docs] add note and links for coercing primitive values (#408)
|
||||
- [actions] update codecov uploader
|
||||
- [actions] update workflows
|
||||
- [Tests] clean up stringify tests slightly
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `object-inspect`, `safe-publish-latest`, `tape`
|
||||
|
||||
## **6.10.1**
|
||||
- [Fix] `stringify`: avoid exception on repeated object values (#402)
|
||||
|
||||
## **6.10.0**
|
||||
- [New] `stringify`: throw on cycles, instead of an infinite loop (#395, #394, #393)
|
||||
- [New] `parse`: add `allowSparse` option for collapsing arrays with missing indices (#312)
|
||||
- [meta] fix README.md (#399)
|
||||
- [meta] only run `npm run dist` in publish, not install
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `has-symbols`, `tape`
|
||||
- [Tests] fix tests on node v0.6
|
||||
- [Tests] use `ljharb/actions/node/install` instead of `ljharb/actions/node/run`
|
||||
- [Tests] Revert "[meta] ignore eclint transitive audit warning"
|
||||
|
||||
## **6.9.7**
|
||||
- [Fix] `parse`: ignore `__proto__` keys (#428)
|
||||
- [Fix] `stringify`: avoid encoding arrayformat comma when `encodeValuesOnly = true` (#424)
|
||||
- [Robustness] `stringify`: avoid relying on a global `undefined` (#427)
|
||||
- [readme] remove travis badge; add github actions/codecov badges; update URLs
|
||||
- [Docs] add note and links for coercing primitive values (#408)
|
||||
- [Tests] clean up stringify tests slightly
|
||||
- [meta] fix README.md (#399)
|
||||
- Revert "[meta] ignore eclint transitive audit warning"
|
||||
- [actions] backport actions from main
|
||||
- [Dev Deps] backport updates from main
|
||||
|
||||
## **6.9.6**
|
||||
- [Fix] restore `dist` dir; mistakenly removed in d4f6c32
|
||||
|
||||
## **6.9.5**
|
||||
- [Fix] `stringify`: do not encode parens for RFC1738
|
||||
- [Fix] `stringify`: fix arrayFormat comma with empty array/objects (#350)
|
||||
- [Refactor] `format`: remove `util.assign` call
|
||||
- [meta] add "Allow Edits" workflow; update rebase workflow
|
||||
- [actions] switch Automatic Rebase workflow to `pull_request_target` event
|
||||
- [Tests] `stringify`: add tests for #378
|
||||
- [Tests] migrate tests to Github Actions
|
||||
- [Tests] run `nyc` on all tests; use `tape` runner
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `browserify`, `mkdirp`, `object-inspect`, `tape`; add `aud`
|
||||
|
||||
## **6.9.4**
|
||||
- [Fix] `stringify`: when `arrayFormat` is `comma`, respect `serializeDate` (#364)
|
||||
- [Refactor] `stringify`: reduce branching (part of #350)
|
||||
- [Refactor] move `maybeMap` to `utils`
|
||||
- [Dev Deps] update `browserify`, `tape`
|
||||
|
||||
## **6.9.3**
|
||||
- [Fix] proper comma parsing of URL-encoded commas (#361)
|
||||
- [Fix] parses comma delimited array while having percent-encoded comma treated as normal text (#336)
|
||||
|
||||
## **6.9.2**
|
||||
- [Fix] `parse`: Fix parsing array from object with `comma` true (#359)
|
||||
- [Fix] `parse`: throw a TypeError instead of an Error for bad charset (#349)
|
||||
- [meta] ignore eclint transitive audit warning
|
||||
- [meta] fix indentation in package.json
|
||||
- [meta] add tidelift marketing copy
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `object-inspect`, `has-symbols`, `tape`, `mkdirp`, `iconv-lite`
|
||||
- [actions] add automatic rebasing / merge commit blocking
|
||||
|
||||
## **6.9.1**
|
||||
- [Fix] `parse`: with comma true, handle field that holds an array of arrays (#335)
|
||||
- [Fix] `parse`: with comma true, do not split non-string values (#334)
|
||||
- [meta] add `funding` field
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`
|
||||
- [Tests] use shared travis-ci config
|
||||
|
||||
## **6.9.0**
|
||||
- [New] `parse`/`stringify`: Pass extra key/value argument to `decoder` (#333)
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `evalmd`
|
||||
- [Tests] `parse`: add passing `arrayFormat` tests
|
||||
- [Tests] add `posttest` using `npx aud` to run `npm audit` without a lockfile
|
||||
- [Tests] up to `node` `v12.10`, `v11.15`, `v10.16`, `v8.16`
|
||||
- [Tests] `Buffer.from` in node v5.0-v5.9 and v4.0-v4.4 requires a TypedArray
|
||||
|
||||
## **6.8.3**
|
||||
- [Fix] `parse`: ignore `__proto__` keys (#428)
|
||||
- [Robustness] `stringify`: avoid relying on a global `undefined` (#427)
|
||||
- [Fix] `stringify`: avoid encoding arrayformat comma when `encodeValuesOnly = true` (#424)
|
||||
- [readme] remove travis badge; add github actions/codecov badges; update URLs
|
||||
- [Tests] clean up stringify tests slightly
|
||||
- [Docs] add note and links for coercing primitive values (#408)
|
||||
- [meta] fix README.md (#399)
|
||||
- [actions] backport actions from main
|
||||
- [Dev Deps] backport updates from main
|
||||
- [Refactor] `stringify`: reduce branching
|
||||
- [meta] do not publish workflow files
|
||||
|
||||
## **6.8.2**
|
||||
- [Fix] proper comma parsing of URL-encoded commas (#361)
|
||||
- [Fix] parses comma delimited array while having percent-encoded comma treated as normal text (#336)
|
||||
|
||||
## **6.8.1**
|
||||
- [Fix] `parse`: Fix parsing array from object with `comma` true (#359)
|
||||
- [Fix] `parse`: throw a TypeError instead of an Error for bad charset (#349)
|
||||
- [Fix] `parse`: with comma true, handle field that holds an array of arrays (#335)
|
||||
- [fix] `parse`: with comma true, do not split non-string values (#334)
|
||||
- [meta] add tidelift marketing copy
|
||||
- [meta] add `funding` field
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `tape`, `safe-publish-latest`, `evalmd`, `has-symbols`, `iconv-lite`, `mkdirp`, `object-inspect`
|
||||
- [Tests] `parse`: add passing `arrayFormat` tests
|
||||
- [Tests] use shared travis-ci configs
|
||||
- [Tests] `Buffer.from` in node v5.0-v5.9 and v4.0-v4.4 requires a TypedArray
|
||||
- [actions] add automatic rebasing / merge commit blocking
|
||||
|
||||
## **6.8.0**
|
||||
- [New] add `depth=false` to preserve the original key; [Fix] `depth=0` should preserve the original key (#326)
|
||||
- [New] [Fix] stringify symbols and bigints
|
||||
- [Fix] ensure node 0.12 can stringify Symbols
|
||||
- [Fix] fix for an impossible situation: when the formatter is called with a non-string value
|
||||
- [Refactor] `formats`: tiny bit of cleanup.
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `browserify`, `safe-publish-latest`, `iconv-lite`, `tape`
|
||||
- [Tests] add tests for `depth=0` and `depth=false` behavior, both current and intuitive/intended (#326)
|
||||
- [Tests] use `eclint` instead of `editorconfig-tools`
|
||||
- [docs] readme: add security note
|
||||
- [meta] add github sponsorship
|
||||
- [meta] add FUNDING.yml
|
||||
- [meta] Clean up license text so it’s properly detected as BSD-3-Clause
|
||||
|
||||
## **6.7.3**
|
||||
- [Fix] `parse`: ignore `__proto__` keys (#428)
|
||||
- [Fix] `stringify`: avoid encoding arrayformat comma when `encodeValuesOnly = true` (#424)
|
||||
- [Robustness] `stringify`: avoid relying on a global `undefined` (#427)
|
||||
- [readme] remove travis badge; add github actions/codecov badges; update URLs
|
||||
- [Docs] add note and links for coercing primitive values (#408)
|
||||
- [meta] fix README.md (#399)
|
||||
- [meta] do not publish workflow files
|
||||
- [actions] backport actions from main
|
||||
- [Dev Deps] backport updates from main
|
||||
- [Tests] use `nyc` for coverage
|
||||
- [Tests] clean up stringify tests slightly
|
||||
|
||||
## **6.7.2**
|
||||
- [Fix] proper comma parsing of URL-encoded commas (#361)
|
||||
- [Fix] parses comma delimited array while having percent-encoded comma treated as normal text (#336)
|
||||
|
||||
## **6.7.1**
|
||||
- [Fix] `parse`: Fix parsing array from object with `comma` true (#359)
|
||||
- [Fix] `parse`: with comma true, handle field that holds an array of arrays (#335)
|
||||
- [fix] `parse`: with comma true, do not split non-string values (#334)
|
||||
- [Fix] `parse`: throw a TypeError instead of an Error for bad charset (#349)
|
||||
- [Fix] fix for an impossible situation: when the formatter is called with a non-string value
|
||||
- [Refactor] `formats`: tiny bit of cleanup.
|
||||
- readme: add security note
|
||||
- [meta] add tidelift marketing copy
|
||||
- [meta] add `funding` field
|
||||
- [meta] add FUNDING.yml
|
||||
- [meta] Clean up license text so it’s properly detected as BSD-3-Clause
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `tape`, `safe-publish-latest`, `evalmd`, `iconv-lite`, `mkdirp`, `object-inspect`, `browserify`
|
||||
- [Tests] `parse`: add passing `arrayFormat` tests
|
||||
- [Tests] use shared travis-ci configs
|
||||
- [Tests] `Buffer.from` in node v5.0-v5.9 and v4.0-v4.4 requires a TypedArray
|
||||
- [Tests] add tests for `depth=0` and `depth=false` behavior, both current and intuitive/intended
|
||||
- [Tests] use `eclint` instead of `editorconfig-tools`
|
||||
- [actions] add automatic rebasing / merge commit blocking
|
||||
|
||||
## **6.7.0**
|
||||
- [New] `stringify`/`parse`: add `comma` as an `arrayFormat` option (#276, #219)
|
||||
- [Fix] correctly parse nested arrays (#212)
|
||||
- [Fix] `utils.merge`: avoid a crash with a null target and a truthy non-array source, also with an array source
|
||||
- [Robustness] `stringify`: cache `Object.prototype.hasOwnProperty`
|
||||
- [Refactor] `utils`: `isBuffer`: small tweak; add tests
|
||||
- [Refactor] use cached `Array.isArray`
|
||||
- [Refactor] `parse`/`stringify`: make a function to normalize the options
|
||||
- [Refactor] `utils`: reduce observable [[Get]]s
|
||||
- [Refactor] `stringify`/`utils`: cache `Array.isArray`
|
||||
- [Tests] always use `String(x)` over `x.toString()`
|
||||
- [Tests] fix Buffer tests to work in node < 4.5 and node < 5.10
|
||||
- [Tests] temporarily allow coverage to fail
|
||||
|
||||
## **6.6.1**
|
||||
- [Fix] `parse`: ignore `__proto__` keys (#428)
|
||||
- [Fix] fix for an impossible situation: when the formatter is called with a non-string value
|
||||
- [Fix] `utils.merge`: avoid a crash with a null target and an array source
|
||||
- [Fix] `utils.merge`: avoid a crash with a null target and a truthy non-array source
|
||||
- [Fix] correctly parse nested arrays
|
||||
- [Robustness] `stringify`: avoid relying on a global `undefined` (#427)
|
||||
- [Robustness] `stringify`: cache `Object.prototype.hasOwnProperty`
|
||||
- [Refactor] `formats`: tiny bit of cleanup.
|
||||
- [Refactor] `utils`: `isBuffer`: small tweak; add tests
|
||||
- [Refactor]: `stringify`/`utils`: cache `Array.isArray`
|
||||
- [Refactor] `utils`: reduce observable [[Get]]s
|
||||
- [Refactor] use cached `Array.isArray`
|
||||
- [Refactor] `parse`/`stringify`: make a function to normalize the options
|
||||
- [readme] remove travis badge; add github actions/codecov badges; update URLs
|
||||
- [Docs] Clarify the need for "arrayLimit" option
|
||||
- [meta] fix README.md (#399)
|
||||
- [meta] do not publish workflow files
|
||||
- [meta] Clean up license text so it’s properly detected as BSD-3-Clause
|
||||
- [meta] add FUNDING.yml
|
||||
- [meta] Fixes typo in CHANGELOG.md
|
||||
- [actions] backport actions from main
|
||||
- [Tests] fix Buffer tests to work in node < 4.5 and node < 5.10
|
||||
- [Tests] always use `String(x)` over `x.toString()`
|
||||
- [Dev Deps] backport from main
|
||||
|
||||
## **6.6.0**
|
||||
- [New] Add support for iso-8859-1, utf8 "sentinel" and numeric entities (#268)
|
||||
- [New] move two-value combine to a `utils` function (#189)
|
||||
- [Fix] `stringify`: fix a crash with `strictNullHandling` and a custom `filter`/`serializeDate` (#279)
|
||||
- [Fix] when `parseArrays` is false, properly handle keys ending in `[]` (#260)
|
||||
- [Fix] `stringify`: do not crash in an obscure combo of `interpretNumericEntities`, a bad custom `decoder`, & `iso-8859-1`
|
||||
- [Fix] `utils`: `merge`: fix crash when `source` is a truthy primitive & no options are provided
|
||||
- [refactor] `stringify`: Avoid arr = arr.concat(...), push to the existing instance (#269)
|
||||
- [Refactor] `parse`: only need to reassign the var once
|
||||
- [Refactor] `parse`/`stringify`: clean up `charset` options checking; fix defaults
|
||||
- [Refactor] add missing defaults
|
||||
- [Refactor] `parse`: one less `concat` call
|
||||
- [Refactor] `utils`: `compactQueue`: make it explicitly side-effecting
|
||||
- [Dev Deps] update `browserify`, `eslint`, `@ljharb/eslint-config`, `iconv-lite`, `safe-publish-latest`, `tape`
|
||||
- [Tests] up to `node` `v10.10`, `v9.11`, `v8.12`, `v6.14`, `v4.9`; pin included builds to LTS
|
||||
|
||||
## **6.5.3**
|
||||
- [Fix] `parse`: ignore `__proto__` keys (#428)
|
||||
- [Fix] `utils.merge`: avoid a crash with a null target and a truthy non-array source
|
||||
- [Fix] correctly parse nested arrays
|
||||
- [Fix] `stringify`: fix a crash with `strictNullHandling` and a custom `filter`/`serializeDate` (#279)
|
||||
- [Fix] `utils`: `merge`: fix crash when `source` is a truthy primitive & no options are provided
|
||||
- [Fix] when `parseArrays` is false, properly handle keys ending in `[]`
|
||||
- [Fix] fix for an impossible situation: when the formatter is called with a non-string value
|
||||
- [Fix] `utils.merge`: avoid a crash with a null target and an array source
|
||||
- [Refactor] `utils`: reduce observable [[Get]]s
|
||||
- [Refactor] use cached `Array.isArray`
|
||||
- [Refactor] `stringify`: Avoid arr = arr.concat(...), push to the existing instance (#269)
|
||||
- [Refactor] `parse`: only need to reassign the var once
|
||||
- [Robustness] `stringify`: avoid relying on a global `undefined` (#427)
|
||||
- [readme] remove travis badge; add github actions/codecov badges; update URLs
|
||||
- [Docs] Clean up license text so it’s properly detected as BSD-3-Clause
|
||||
- [Docs] Clarify the need for "arrayLimit" option
|
||||
- [meta] fix README.md (#399)
|
||||
- [meta] add FUNDING.yml
|
||||
- [actions] backport actions from main
|
||||
- [Tests] always use `String(x)` over `x.toString()`
|
||||
- [Tests] remove nonexistent tape option
|
||||
- [Dev Deps] backport from main
|
||||
|
||||
## **6.5.2**
|
||||
- [Fix] use `safer-buffer` instead of `Buffer` constructor
|
||||
- [Refactor] utils: `module.exports` one thing, instead of mutating `exports` (#230)
|
||||
- [Dev Deps] update `browserify`, `eslint`, `iconv-lite`, `safer-buffer`, `tape`, `browserify`
|
||||
|
||||
## **6.5.1**
|
||||
- [Fix] Fix parsing & compacting very deep objects (#224)
|
||||
- [Refactor] name utils functions
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `tape`
|
||||
- [Tests] up to `node` `v8.4`; use `nvm install-latest-npm` so newer npm doesn’t break older node
|
||||
- [Tests] Use precise dist for Node.js 0.6 runtime (#225)
|
||||
- [Tests] make 0.6 required, now that it’s passing
|
||||
- [Tests] on `node` `v8.2`; fix npm on node 0.6
|
||||
|
||||
## **6.5.0**
|
||||
- [New] add `utils.assign`
|
||||
- [New] pass default encoder/decoder to custom encoder/decoder functions (#206)
|
||||
- [New] `parse`/`stringify`: add `ignoreQueryPrefix`/`addQueryPrefix` options, respectively (#213)
|
||||
- [Fix] Handle stringifying empty objects with addQueryPrefix (#217)
|
||||
- [Fix] do not mutate `options` argument (#207)
|
||||
- [Refactor] `parse`: cache index to reuse in else statement (#182)
|
||||
- [Docs] add various badges to readme (#208)
|
||||
- [Dev Deps] update `eslint`, `browserify`, `iconv-lite`, `tape`
|
||||
- [Tests] up to `node` `v8.1`, `v7.10`, `v6.11`; npm v4.6 breaks on node < v1; npm v5+ breaks on node < v4
|
||||
- [Tests] add `editorconfig-tools`
|
||||
|
||||
## **6.4.1**
|
||||
- [Fix] `parse`: ignore `__proto__` keys (#428)
|
||||
- [Fix] fix for an impossible situation: when the formatter is called with a non-string value
|
||||
- [Fix] use `safer-buffer` instead of `Buffer` constructor
|
||||
- [Fix] `utils.merge`: avoid a crash with a null target and an array source
|
||||
- [Fix] `utils.merge`: avoid a crash with a null target and a truthy non-array source
|
||||
- [Fix] `stringify`: fix a crash with `strictNullHandling` and a custom `filter`/`serializeDate` (#279)
|
||||
- [Fix] `utils`: `merge`: fix crash when `source` is a truthy primitive & no options are provided
|
||||
- [Fix] when `parseArrays` is false, properly handle keys ending in `[]`
|
||||
- [Robustness] `stringify`: avoid relying on a global `undefined` (#427)
|
||||
- [Refactor] use cached `Array.isArray`
|
||||
- [Refactor] `stringify`: Avoid arr = arr.concat(...), push to the existing instance (#269)
|
||||
- [readme] remove travis badge; add github actions/codecov badges; update URLs
|
||||
- [Docs] Clarify the need for "arrayLimit" option
|
||||
- [meta] fix README.md (#399)
|
||||
- [meta] Clean up license text so it’s properly detected as BSD-3-Clause
|
||||
- [meta] add FUNDING.yml
|
||||
- [actions] backport actions from main
|
||||
- [Tests] remove nonexistent tape option
|
||||
- [Dev Deps] backport from main
|
||||
|
||||
## **6.4.0**
|
||||
- [New] `qs.stringify`: add `encodeValuesOnly` option
|
||||
- [Fix] follow `allowPrototypes` option during merge (#201, #201)
|
||||
- [Fix] support keys starting with brackets (#202, #200)
|
||||
- [Fix] chmod a-x
|
||||
- [Dev Deps] update `eslint`
|
||||
- [Tests] up to `node` `v7.7`, `v6.10`,` v4.8`; disable osx builds since they block linux builds
|
||||
- [eslint] reduce warnings
|
||||
|
||||
## **6.3.3**
|
||||
- [Fix] `parse`: ignore `__proto__` keys (#428)
|
||||
- [Fix] fix for an impossible situation: when the formatter is called with a non-string value
|
||||
- [Fix] `utils.merge`: avoid a crash with a null target and an array source
|
||||
- [Fix] `utils.merge`: avoid a crash with a null target and a truthy non-array source
|
||||
- [Fix] `stringify`: fix a crash with `strictNullHandling` and a custom `filter`/`serializeDate` (#279)
|
||||
- [Fix] `utils`: `merge`: fix crash when `source` is a truthy primitive & no options are provided
|
||||
- [Fix] when `parseArrays` is false, properly handle keys ending in `[]`
|
||||
- [Robustness] `stringify`: avoid relying on a global `undefined` (#427)
|
||||
- [Refactor] use cached `Array.isArray`
|
||||
- [Refactor] `stringify`: Avoid arr = arr.concat(...), push to the existing instance (#269)
|
||||
- [Docs] Clarify the need for "arrayLimit" option
|
||||
- [meta] fix README.md (#399)
|
||||
- [meta] Clean up license text so it’s properly detected as BSD-3-Clause
|
||||
- [meta] add FUNDING.yml
|
||||
- [actions] backport actions from main
|
||||
- [Tests] use `safer-buffer` instead of `Buffer` constructor
|
||||
- [Tests] remove nonexistent tape option
|
||||
- [Dev Deps] backport from main
|
||||
|
||||
## **6.3.2**
|
||||
- [Fix] follow `allowPrototypes` option during merge (#201, #200)
|
||||
- [Dev Deps] update `eslint`
|
||||
- [Fix] chmod a-x
|
||||
- [Fix] support keys starting with brackets (#202, #200)
|
||||
- [Tests] up to `node` `v7.7`, `v6.10`,` v4.8`; disable osx builds since they block linux builds
|
||||
|
||||
## **6.3.1**
|
||||
- [Fix] ensure that `allowPrototypes: false` does not ever shadow Object.prototype properties (thanks, @snyk!)
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `browserify`, `iconv-lite`, `qs-iconv`, `tape`
|
||||
- [Tests] on all node minors; improve test matrix
|
||||
- [Docs] document stringify option `allowDots` (#195)
|
||||
- [Docs] add empty object and array values example (#195)
|
||||
- [Docs] Fix minor inconsistency/typo (#192)
|
||||
- [Docs] document stringify option `sort` (#191)
|
||||
- [Refactor] `stringify`: throw faster with an invalid encoder
|
||||
- [Refactor] remove unnecessary escapes (#184)
|
||||
- Remove contributing.md, since `qs` is no longer part of `hapi` (#183)
|
||||
|
||||
## **6.3.0**
|
||||
- [New] Add support for RFC 1738 (#174, #173)
|
||||
- [New] `stringify`: Add `serializeDate` option to customize Date serialization (#159)
|
||||
- [Fix] ensure `utils.merge` handles merging two arrays
|
||||
- [Refactor] only constructors should be capitalized
|
||||
- [Refactor] capitalized var names are for constructors only
|
||||
- [Refactor] avoid using a sparse array
|
||||
- [Robustness] `formats`: cache `String#replace`
|
||||
- [Dev Deps] update `browserify`, `eslint`, `@ljharb/eslint-config`; add `safe-publish-latest`
|
||||
- [Tests] up to `node` `v6.8`, `v4.6`; improve test matrix
|
||||
- [Tests] flesh out arrayLimit/arrayFormat tests (#107)
|
||||
- [Tests] skip Object.create tests when null objects are not available
|
||||
- [Tests] Turn on eslint for test files (#175)
|
||||
|
||||
## **6.2.4**
|
||||
- [Fix] `parse`: ignore `__proto__` keys (#428)
|
||||
- [Fix] `utils.merge`: avoid a crash with a null target and an array source
|
||||
- [Fix] `utils.merge`: avoid a crash with a null target and a truthy non-array source
|
||||
- [Fix] `utils`: `merge`: fix crash when `source` is a truthy primitive & no options are provided
|
||||
- [Fix] when `parseArrays` is false, properly handle keys ending in `[]`
|
||||
- [Robustness] `stringify`: avoid relying on a global `undefined` (#427)
|
||||
- [Refactor] use cached `Array.isArray`
|
||||
- [Docs] Clarify the need for "arrayLimit" option
|
||||
- [meta] fix README.md (#399)
|
||||
- [meta] Clean up license text so it’s properly detected as BSD-3-Clause
|
||||
- [meta] add FUNDING.yml
|
||||
- [actions] backport actions from main
|
||||
- [Tests] use `safer-buffer` instead of `Buffer` constructor
|
||||
- [Tests] remove nonexistent tape option
|
||||
- [Dev Deps] backport from main
|
||||
|
||||
## **6.2.3**
|
||||
- [Fix] follow `allowPrototypes` option during merge (#201, #200)
|
||||
- [Fix] chmod a-x
|
||||
- [Fix] support keys starting with brackets (#202, #200)
|
||||
- [Tests] up to `node` `v7.7`, `v6.10`,` v4.8`; disable osx builds since they block linux builds
|
||||
|
||||
## **6.2.2**
|
||||
- [Fix] ensure that `allowPrototypes: false` does not ever shadow Object.prototype properties
|
||||
|
||||
## **6.2.1**
|
||||
- [Fix] ensure `key[]=x&key[]&key[]=y` results in 3, not 2, values
|
||||
- [Refactor] Be explicit and use `Object.prototype.hasOwnProperty.call`
|
||||
- [Tests] remove `parallelshell` since it does not reliably report failures
|
||||
- [Tests] up to `node` `v6.3`, `v5.12`
|
||||
- [Dev Deps] update `tape`, `eslint`, `@ljharb/eslint-config`, `qs-iconv`
|
||||
|
||||
## [**6.2.0**](https://github.com/ljharb/qs/issues?milestone=36&state=closed)
|
||||
- [New] pass Buffers to the encoder/decoder directly (#161)
|
||||
- [New] add "encoder" and "decoder" options, for custom param encoding/decoding (#160)
|
||||
- [Fix] fix compacting of nested sparse arrays (#150)
|
||||
|
||||
## **6.1.2**
|
||||
- [Fix] follow `allowPrototypes` option during merge (#201, #200)
|
||||
- [Fix] chmod a-x
|
||||
- [Fix] support keys starting with brackets (#202, #200)
|
||||
- [Tests] up to `node` `v7.7`, `v6.10`,` v4.8`; disable osx builds since they block linux builds
|
||||
|
||||
## **6.1.1**
|
||||
- [Fix] ensure that `allowPrototypes: false` does not ever shadow Object.prototype properties
|
||||
|
||||
## [**6.1.0**](https://github.com/ljharb/qs/issues?milestone=35&state=closed)
|
||||
- [New] allowDots option for `stringify` (#151)
|
||||
- [Fix] "sort" option should work at a depth of 3 or more (#151)
|
||||
- [Fix] Restore `dist` directory; will be removed in v7 (#148)
|
||||
|
||||
## **6.0.4**
|
||||
- [Fix] follow `allowPrototypes` option during merge (#201, #200)
|
||||
- [Fix] chmod a-x
|
||||
- [Fix] support keys starting with brackets (#202, #200)
|
||||
- [Tests] up to `node` `v7.7`, `v6.10`,` v4.8`; disable osx builds since they block linux builds
|
||||
|
||||
## **6.0.3**
|
||||
- [Fix] ensure that `allowPrototypes: false` does not ever shadow Object.prototype properties
|
||||
- [Fix] Restore `dist` directory; will be removed in v7 (#148)
|
||||
|
||||
## [**6.0.2**](https://github.com/ljharb/qs/issues?milestone=33&state=closed)
|
||||
- Revert ES6 requirement and restore support for node down to v0.8.
|
||||
|
||||
## [**6.0.1**](https://github.com/ljharb/qs/issues?milestone=32&state=closed)
|
||||
- [**#127**](https://github.com/ljharb/qs/pull/127) Fix engines definition in package.json
|
||||
|
||||
## [**6.0.0**](https://github.com/ljharb/qs/issues?milestone=31&state=closed)
|
||||
- [**#124**](https://github.com/ljharb/qs/issues/124) Use ES6 and drop support for node < v4
|
||||
|
||||
## **5.2.1**
|
||||
- [Fix] ensure `key[]=x&key[]&key[]=y` results in 3, not 2, values
|
||||
|
||||
## [**5.2.0**](https://github.com/ljharb/qs/issues?milestone=30&state=closed)
|
||||
- [**#64**](https://github.com/ljharb/qs/issues/64) Add option to sort object keys in the query string
|
||||
|
||||
## [**5.1.0**](https://github.com/ljharb/qs/issues?milestone=29&state=closed)
|
||||
- [**#117**](https://github.com/ljharb/qs/issues/117) make URI encoding stringified results optional
|
||||
- [**#106**](https://github.com/ljharb/qs/issues/106) Add flag `skipNulls` to optionally skip null values in stringify
|
||||
|
||||
## [**5.0.0**](https://github.com/ljharb/qs/issues?milestone=28&state=closed)
|
||||
- [**#114**](https://github.com/ljharb/qs/issues/114) default allowDots to false
|
||||
- [**#100**](https://github.com/ljharb/qs/issues/100) include dist to npm
|
||||
|
||||
## [**4.0.0**](https://github.com/ljharb/qs/issues?milestone=26&state=closed)
|
||||
- [**#98**](https://github.com/ljharb/qs/issues/98) make returning plain objects and allowing prototype overwriting properties optional
|
||||
|
||||
## [**3.1.0**](https://github.com/ljharb/qs/issues?milestone=24&state=closed)
|
||||
- [**#89**](https://github.com/ljharb/qs/issues/89) Add option to disable "Transform dot notation to bracket notation"
|
||||
|
||||
## [**3.0.0**](https://github.com/ljharb/qs/issues?milestone=23&state=closed)
|
||||
- [**#80**](https://github.com/ljharb/qs/issues/80) qs.parse silently drops properties
|
||||
- [**#77**](https://github.com/ljharb/qs/issues/77) Perf boost
|
||||
- [**#60**](https://github.com/ljharb/qs/issues/60) Add explicit option to disable array parsing
|
||||
- [**#74**](https://github.com/ljharb/qs/issues/74) Bad parse when turning array into object
|
||||
- [**#81**](https://github.com/ljharb/qs/issues/81) Add a `filter` option
|
||||
- [**#68**](https://github.com/ljharb/qs/issues/68) Fixed issue with recursion and passing strings into objects.
|
||||
- [**#66**](https://github.com/ljharb/qs/issues/66) Add mixed array and object dot notation support Closes: #47
|
||||
- [**#76**](https://github.com/ljharb/qs/issues/76) RFC 3986
|
||||
- [**#85**](https://github.com/ljharb/qs/issues/85) No equal sign
|
||||
- [**#84**](https://github.com/ljharb/qs/issues/84) update license attribute
|
||||
|
||||
## [**2.4.1**](https://github.com/ljharb/qs/issues?milestone=20&state=closed)
|
||||
- [**#73**](https://github.com/ljharb/qs/issues/73) Property 'hasOwnProperty' of object #<Object> is not a function
|
||||
|
||||
## [**2.4.0**](https://github.com/ljharb/qs/issues?milestone=19&state=closed)
|
||||
- [**#70**](https://github.com/ljharb/qs/issues/70) Add arrayFormat option
|
||||
|
||||
## [**2.3.3**](https://github.com/ljharb/qs/issues?milestone=18&state=closed)
|
||||
- [**#59**](https://github.com/ljharb/qs/issues/59) make sure array indexes are >= 0, closes #57
|
||||
- [**#58**](https://github.com/ljharb/qs/issues/58) make qs usable for browser loader
|
||||
|
||||
## [**2.3.2**](https://github.com/ljharb/qs/issues?milestone=17&state=closed)
|
||||
- [**#55**](https://github.com/ljharb/qs/issues/55) allow merging a string into an object
|
||||
|
||||
## [**2.3.1**](https://github.com/ljharb/qs/issues?milestone=16&state=closed)
|
||||
- [**#52**](https://github.com/ljharb/qs/issues/52) Return "undefined" and "false" instead of throwing "TypeError".
|
||||
|
||||
## [**2.3.0**](https://github.com/ljharb/qs/issues?milestone=15&state=closed)
|
||||
- [**#50**](https://github.com/ljharb/qs/issues/50) add option to omit array indices, closes #46
|
||||
|
||||
## [**2.2.5**](https://github.com/ljharb/qs/issues?milestone=14&state=closed)
|
||||
- [**#39**](https://github.com/ljharb/qs/issues/39) Is there an alternative to Buffer.isBuffer?
|
||||
- [**#49**](https://github.com/ljharb/qs/issues/49) refactor utils.merge, fixes #45
|
||||
- [**#41**](https://github.com/ljharb/qs/issues/41) avoid browserifying Buffer, for #39
|
||||
|
||||
## [**2.2.4**](https://github.com/ljharb/qs/issues?milestone=13&state=closed)
|
||||
- [**#38**](https://github.com/ljharb/qs/issues/38) how to handle object keys beginning with a number
|
||||
|
||||
## [**2.2.3**](https://github.com/ljharb/qs/issues?milestone=12&state=closed)
|
||||
- [**#37**](https://github.com/ljharb/qs/issues/37) parser discards first empty value in array
|
||||
- [**#36**](https://github.com/ljharb/qs/issues/36) Update to lab 4.x
|
||||
|
||||
## [**2.2.2**](https://github.com/ljharb/qs/issues?milestone=11&state=closed)
|
||||
- [**#33**](https://github.com/ljharb/qs/issues/33) Error when plain object in a value
|
||||
- [**#34**](https://github.com/ljharb/qs/issues/34) use Object.prototype.hasOwnProperty.call instead of obj.hasOwnProperty
|
||||
- [**#24**](https://github.com/ljharb/qs/issues/24) Changelog? Semver?
|
||||
|
||||
## [**2.2.1**](https://github.com/ljharb/qs/issues?milestone=10&state=closed)
|
||||
- [**#32**](https://github.com/ljharb/qs/issues/32) account for circular references properly, closes #31
|
||||
- [**#31**](https://github.com/ljharb/qs/issues/31) qs.parse stackoverflow on circular objects
|
||||
|
||||
## [**2.2.0**](https://github.com/ljharb/qs/issues?milestone=9&state=closed)
|
||||
- [**#26**](https://github.com/ljharb/qs/issues/26) Don't use Buffer global if it's not present
|
||||
- [**#30**](https://github.com/ljharb/qs/issues/30) Bug when merging non-object values into arrays
|
||||
- [**#29**](https://github.com/ljharb/qs/issues/29) Don't call Utils.clone at the top of Utils.merge
|
||||
- [**#23**](https://github.com/ljharb/qs/issues/23) Ability to not limit parameters?
|
||||
|
||||
## [**2.1.0**](https://github.com/ljharb/qs/issues?milestone=8&state=closed)
|
||||
- [**#22**](https://github.com/ljharb/qs/issues/22) Enable using a RegExp as delimiter
|
||||
|
||||
## [**2.0.0**](https://github.com/ljharb/qs/issues?milestone=7&state=closed)
|
||||
- [**#18**](https://github.com/ljharb/qs/issues/18) Why is there arrayLimit?
|
||||
- [**#20**](https://github.com/ljharb/qs/issues/20) Configurable parametersLimit
|
||||
- [**#21**](https://github.com/ljharb/qs/issues/21) make all limits optional, for #18, for #20
|
||||
|
||||
## [**1.2.2**](https://github.com/ljharb/qs/issues?milestone=6&state=closed)
|
||||
- [**#19**](https://github.com/ljharb/qs/issues/19) Don't overwrite null values
|
||||
|
||||
## [**1.2.1**](https://github.com/ljharb/qs/issues?milestone=5&state=closed)
|
||||
- [**#16**](https://github.com/ljharb/qs/issues/16) ignore non-string delimiters
|
||||
- [**#15**](https://github.com/ljharb/qs/issues/15) Close code block
|
||||
|
||||
## [**1.2.0**](https://github.com/ljharb/qs/issues?milestone=4&state=closed)
|
||||
- [**#12**](https://github.com/ljharb/qs/issues/12) Add optional delim argument
|
||||
- [**#13**](https://github.com/ljharb/qs/issues/13) fix #11: flattened keys in array are now correctly parsed
|
||||
|
||||
## [**1.1.0**](https://github.com/ljharb/qs/issues?milestone=3&state=closed)
|
||||
- [**#7**](https://github.com/ljharb/qs/issues/7) Empty values of a POST array disappear after being submitted
|
||||
- [**#9**](https://github.com/ljharb/qs/issues/9) Should not omit equals signs (=) when value is null
|
||||
- [**#6**](https://github.com/ljharb/qs/issues/6) Minor grammar fix in README
|
||||
|
||||
## [**1.0.2**](https://github.com/ljharb/qs/issues?milestone=2&state=closed)
|
||||
- [**#5**](https://github.com/ljharb/qs/issues/5) array holes incorrectly copied into object on large index
|
||||
29
ProjectSourceCode/node_modules/formidable/node_modules/qs/LICENSE.md
generated
vendored
Normal file
29
ProjectSourceCode/node_modules/formidable/node_modules/qs/LICENSE.md
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2014, Nathan LaFreniere and other [contributors](https://github.com/ljharb/qs/graphs/contributors)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
697
ProjectSourceCode/node_modules/formidable/node_modules/qs/README.md
generated
vendored
Normal file
697
ProjectSourceCode/node_modules/formidable/node_modules/qs/README.md
generated
vendored
Normal file
@@ -0,0 +1,697 @@
|
||||
<p align="center">
|
||||
<img alt="qs" src="./logos/banner_default.png" width="800" />
|
||||
</p>
|
||||
|
||||
# qs <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
|
||||
|
||||
[![github actions][actions-image]][actions-url]
|
||||
[![coverage][codecov-image]][codecov-url]
|
||||
[![License][license-image]][license-url]
|
||||
[![Downloads][downloads-image]][downloads-url]
|
||||
|
||||
[![npm badge][npm-badge-png]][package-url]
|
||||
|
||||
A querystring parsing and stringifying library with some added security.
|
||||
|
||||
Lead Maintainer: [Jordan Harband](https://github.com/ljharb)
|
||||
|
||||
The **qs** module was originally created and maintained by [TJ Holowaychuk](https://github.com/visionmedia/node-querystring).
|
||||
|
||||
## Usage
|
||||
|
||||
```javascript
|
||||
var qs = require('qs');
|
||||
var assert = require('assert');
|
||||
|
||||
var obj = qs.parse('a=c');
|
||||
assert.deepEqual(obj, { a: 'c' });
|
||||
|
||||
var str = qs.stringify(obj);
|
||||
assert.equal(str, 'a=c');
|
||||
```
|
||||
|
||||
### Parsing Objects
|
||||
|
||||
[](#preventEval)
|
||||
```javascript
|
||||
qs.parse(string, [options]);
|
||||
```
|
||||
|
||||
**qs** allows you to create nested objects within your query strings, by surrounding the name of sub-keys with square brackets `[]`.
|
||||
For example, the string `'foo[bar]=baz'` converts to:
|
||||
|
||||
```javascript
|
||||
assert.deepEqual(qs.parse('foo[bar]=baz'), {
|
||||
foo: {
|
||||
bar: 'baz'
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
When using the `plainObjects` option the parsed value is returned as a null object, created via `Object.create(null)` and as such you should be aware that prototype methods will not exist on it and a user may set those names to whatever value they like:
|
||||
|
||||
```javascript
|
||||
var nullObject = qs.parse('a[hasOwnProperty]=b', { plainObjects: true });
|
||||
assert.deepEqual(nullObject, { a: { hasOwnProperty: 'b' } });
|
||||
```
|
||||
|
||||
By default parameters that would overwrite properties on the object prototype are ignored, if you wish to keep the data from those fields either use `plainObjects` as mentioned above, or set `allowPrototypes` to `true` which will allow user input to overwrite those properties.
|
||||
*WARNING* It is generally a bad idea to enable this option as it can cause problems when attempting to use the properties that have been overwritten.
|
||||
Always be careful with this option.
|
||||
|
||||
```javascript
|
||||
var protoObject = qs.parse('a[hasOwnProperty]=b', { allowPrototypes: true });
|
||||
assert.deepEqual(protoObject, { a: { hasOwnProperty: 'b' } });
|
||||
```
|
||||
|
||||
URI encoded strings work too:
|
||||
|
||||
```javascript
|
||||
assert.deepEqual(qs.parse('a%5Bb%5D=c'), {
|
||||
a: { b: 'c' }
|
||||
});
|
||||
```
|
||||
|
||||
You can also nest your objects, like `'foo[bar][baz]=foobarbaz'`:
|
||||
|
||||
```javascript
|
||||
assert.deepEqual(qs.parse('foo[bar][baz]=foobarbaz'), {
|
||||
foo: {
|
||||
bar: {
|
||||
baz: 'foobarbaz'
|
||||
}
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
By default, when nesting objects **qs** will only parse up to 5 children deep.
|
||||
This means if you attempt to parse a string like `'a[b][c][d][e][f][g][h][i]=j'` your resulting object will be:
|
||||
|
||||
```javascript
|
||||
var expected = {
|
||||
a: {
|
||||
b: {
|
||||
c: {
|
||||
d: {
|
||||
e: {
|
||||
f: {
|
||||
'[g][h][i]': 'j'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
var string = 'a[b][c][d][e][f][g][h][i]=j';
|
||||
assert.deepEqual(qs.parse(string), expected);
|
||||
```
|
||||
|
||||
This depth can be overridden by passing a `depth` option to `qs.parse(string, [options])`:
|
||||
|
||||
```javascript
|
||||
var deep = qs.parse('a[b][c][d][e][f][g][h][i]=j', { depth: 1 });
|
||||
assert.deepEqual(deep, { a: { b: { '[c][d][e][f][g][h][i]': 'j' } } });
|
||||
```
|
||||
|
||||
The depth limit helps mitigate abuse when **qs** is used to parse user input, and it is recommended to keep it a reasonably small number.
|
||||
|
||||
For similar reasons, by default **qs** will only parse up to 1000 parameters. This can be overridden by passing a `parameterLimit` option:
|
||||
|
||||
```javascript
|
||||
var limited = qs.parse('a=b&c=d', { parameterLimit: 1 });
|
||||
assert.deepEqual(limited, { a: 'b' });
|
||||
```
|
||||
|
||||
To bypass the leading question mark, use `ignoreQueryPrefix`:
|
||||
|
||||
```javascript
|
||||
var prefixed = qs.parse('?a=b&c=d', { ignoreQueryPrefix: true });
|
||||
assert.deepEqual(prefixed, { a: 'b', c: 'd' });
|
||||
```
|
||||
|
||||
An optional delimiter can also be passed:
|
||||
|
||||
```javascript
|
||||
var delimited = qs.parse('a=b;c=d', { delimiter: ';' });
|
||||
assert.deepEqual(delimited, { a: 'b', c: 'd' });
|
||||
```
|
||||
|
||||
Delimiters can be a regular expression too:
|
||||
|
||||
```javascript
|
||||
var regexed = qs.parse('a=b;c=d,e=f', { delimiter: /[;,]/ });
|
||||
assert.deepEqual(regexed, { a: 'b', c: 'd', e: 'f' });
|
||||
```
|
||||
|
||||
Option `allowDots` can be used to enable dot notation:
|
||||
|
||||
```javascript
|
||||
var withDots = qs.parse('a.b=c', { allowDots: true });
|
||||
assert.deepEqual(withDots, { a: { b: 'c' } });
|
||||
```
|
||||
|
||||
Option `decodeDotInKeys` can be used to decode dots in keys
|
||||
Note: it implies `allowDots`, so `parse` will error if you set `decodeDotInKeys` to `true`, and `allowDots` to `false`.
|
||||
|
||||
```javascript
|
||||
var withDots = qs.parse('name%252Eobj.first=John&name%252Eobj.last=Doe', { decodeDotInKeys: true });
|
||||
assert.deepEqual(withDots, { 'name.obj': { first: 'John', last: 'Doe' }});
|
||||
```
|
||||
|
||||
Option `allowEmptyArrays` can be used to allowing empty array values in object
|
||||
```javascript
|
||||
var withEmptyArrays = qs.parse('foo[]&bar=baz', { allowEmptyArrays: true });
|
||||
assert.deepEqual(withEmptyArrays, { foo: [], bar: 'baz' });
|
||||
```
|
||||
|
||||
Option `duplicates` can be used to change the behavior when duplicate keys are encountered
|
||||
```javascript
|
||||
assert.deepEqual(qs.parse('foo=bar&foo=baz'), { foo: ['bar', 'baz'] });
|
||||
assert.deepEqual(qs.parse('foo=bar&foo=baz', { duplicates: 'combine' }), { foo: ['bar', 'baz'] });
|
||||
assert.deepEqual(qs.parse('foo=bar&foo=baz', { duplicates: 'first' }), { foo: 'bar' });
|
||||
assert.deepEqual(qs.parse('foo=bar&foo=baz', { duplicates: 'last' }), { foo: 'baz' });
|
||||
```
|
||||
|
||||
If you have to deal with legacy browsers or services, there's also support for decoding percent-encoded octets as iso-8859-1:
|
||||
|
||||
```javascript
|
||||
var oldCharset = qs.parse('a=%A7', { charset: 'iso-8859-1' });
|
||||
assert.deepEqual(oldCharset, { a: '§' });
|
||||
```
|
||||
|
||||
Some services add an initial `utf8=✓` value to forms so that old Internet Explorer versions are more likely to submit the form as utf-8.
|
||||
Additionally, the server can check the value against wrong encodings of the checkmark character and detect that a query string or `application/x-www-form-urlencoded` body was *not* sent as utf-8, eg. if the form had an `accept-charset` parameter or the containing page had a different character set.
|
||||
|
||||
**qs** supports this mechanism via the `charsetSentinel` option.
|
||||
If specified, the `utf8` parameter will be omitted from the returned object.
|
||||
It will be used to switch to `iso-8859-1`/`utf-8` mode depending on how the checkmark is encoded.
|
||||
|
||||
**Important**: When you specify both the `charset` option and the `charsetSentinel` option, the `charset` will be overridden when the request contains a `utf8` parameter from which the actual charset can be deduced.
|
||||
In that sense the `charset` will behave as the default charset rather than the authoritative charset.
|
||||
|
||||
```javascript
|
||||
var detectedAsUtf8 = qs.parse('utf8=%E2%9C%93&a=%C3%B8', {
|
||||
charset: 'iso-8859-1',
|
||||
charsetSentinel: true
|
||||
});
|
||||
assert.deepEqual(detectedAsUtf8, { a: 'ø' });
|
||||
|
||||
// Browsers encode the checkmark as ✓ when submitting as iso-8859-1:
|
||||
var detectedAsIso8859_1 = qs.parse('utf8=%26%2310003%3B&a=%F8', {
|
||||
charset: 'utf-8',
|
||||
charsetSentinel: true
|
||||
});
|
||||
assert.deepEqual(detectedAsIso8859_1, { a: 'ø' });
|
||||
```
|
||||
|
||||
If you want to decode the `&#...;` syntax to the actual character, you can specify the `interpretNumericEntities` option as well:
|
||||
|
||||
```javascript
|
||||
var detectedAsIso8859_1 = qs.parse('a=%26%239786%3B', {
|
||||
charset: 'iso-8859-1',
|
||||
interpretNumericEntities: true
|
||||
});
|
||||
assert.deepEqual(detectedAsIso8859_1, { a: '☺' });
|
||||
```
|
||||
|
||||
It also works when the charset has been detected in `charsetSentinel` mode.
|
||||
|
||||
### Parsing Arrays
|
||||
|
||||
**qs** can also parse arrays using a similar `[]` notation:
|
||||
|
||||
```javascript
|
||||
var withArray = qs.parse('a[]=b&a[]=c');
|
||||
assert.deepEqual(withArray, { a: ['b', 'c'] });
|
||||
```
|
||||
|
||||
You may specify an index as well:
|
||||
|
||||
```javascript
|
||||
var withIndexes = qs.parse('a[1]=c&a[0]=b');
|
||||
assert.deepEqual(withIndexes, { a: ['b', 'c'] });
|
||||
```
|
||||
|
||||
Note that the only difference between an index in an array and a key in an object is that the value between the brackets must be a number to create an array.
|
||||
When creating arrays with specific indices, **qs** will compact a sparse array to only the existing values preserving their order:
|
||||
|
||||
```javascript
|
||||
var noSparse = qs.parse('a[1]=b&a[15]=c');
|
||||
assert.deepEqual(noSparse, { a: ['b', 'c'] });
|
||||
```
|
||||
|
||||
You may also use `allowSparse` option to parse sparse arrays:
|
||||
|
||||
```javascript
|
||||
var sparseArray = qs.parse('a[1]=2&a[3]=5', { allowSparse: true });
|
||||
assert.deepEqual(sparseArray, { a: [, '2', , '5'] });
|
||||
```
|
||||
|
||||
Note that an empty string is also a value, and will be preserved:
|
||||
|
||||
```javascript
|
||||
var withEmptyString = qs.parse('a[]=&a[]=b');
|
||||
assert.deepEqual(withEmptyString, { a: ['', 'b'] });
|
||||
|
||||
var withIndexedEmptyString = qs.parse('a[0]=b&a[1]=&a[2]=c');
|
||||
assert.deepEqual(withIndexedEmptyString, { a: ['b', '', 'c'] });
|
||||
```
|
||||
|
||||
**qs** will also limit specifying indices in an array to a maximum index of `20`.
|
||||
Any array members with an index of greater than `20` will instead be converted to an object with the index as the key.
|
||||
This is needed to handle cases when someone sent, for example, `a[999999999]` and it will take significant time to iterate over this huge array.
|
||||
|
||||
```javascript
|
||||
var withMaxIndex = qs.parse('a[100]=b');
|
||||
assert.deepEqual(withMaxIndex, { a: { '100': 'b' } });
|
||||
```
|
||||
|
||||
This limit can be overridden by passing an `arrayLimit` option:
|
||||
|
||||
```javascript
|
||||
var withArrayLimit = qs.parse('a[1]=b', { arrayLimit: 0 });
|
||||
assert.deepEqual(withArrayLimit, { a: { '1': 'b' } });
|
||||
```
|
||||
|
||||
To disable array parsing entirely, set `parseArrays` to `false`.
|
||||
|
||||
```javascript
|
||||
var noParsingArrays = qs.parse('a[]=b', { parseArrays: false });
|
||||
assert.deepEqual(noParsingArrays, { a: { '0': 'b' } });
|
||||
```
|
||||
|
||||
If you mix notations, **qs** will merge the two items into an object:
|
||||
|
||||
```javascript
|
||||
var mixedNotation = qs.parse('a[0]=b&a[b]=c');
|
||||
assert.deepEqual(mixedNotation, { a: { '0': 'b', b: 'c' } });
|
||||
```
|
||||
|
||||
You can also create arrays of objects:
|
||||
|
||||
```javascript
|
||||
var arraysOfObjects = qs.parse('a[][b]=c');
|
||||
assert.deepEqual(arraysOfObjects, { a: [{ b: 'c' }] });
|
||||
```
|
||||
|
||||
Some people use comma to join array, **qs** can parse it:
|
||||
```javascript
|
||||
var arraysOfObjects = qs.parse('a=b,c', { comma: true })
|
||||
assert.deepEqual(arraysOfObjects, { a: ['b', 'c'] })
|
||||
```
|
||||
(_this cannot convert nested objects, such as `a={b:1},{c:d}`_)
|
||||
|
||||
### Parsing primitive/scalar values (numbers, booleans, null, etc)
|
||||
|
||||
By default, all values are parsed as strings.
|
||||
This behavior will not change and is explained in [issue #91](https://github.com/ljharb/qs/issues/91).
|
||||
|
||||
```javascript
|
||||
var primitiveValues = qs.parse('a=15&b=true&c=null');
|
||||
assert.deepEqual(primitiveValues, { a: '15', b: 'true', c: 'null' });
|
||||
```
|
||||
|
||||
If you wish to auto-convert values which look like numbers, booleans, and other values into their primitive counterparts, you can use the [query-types Express JS middleware](https://github.com/xpepermint/query-types) which will auto-convert all request query parameters.
|
||||
|
||||
### Stringifying
|
||||
|
||||
[](#preventEval)
|
||||
```javascript
|
||||
qs.stringify(object, [options]);
|
||||
```
|
||||
|
||||
When stringifying, **qs** by default URI encodes output. Objects are stringified as you would expect:
|
||||
|
||||
```javascript
|
||||
assert.equal(qs.stringify({ a: 'b' }), 'a=b');
|
||||
assert.equal(qs.stringify({ a: { b: 'c' } }), 'a%5Bb%5D=c');
|
||||
```
|
||||
|
||||
This encoding can be disabled by setting the `encode` option to `false`:
|
||||
|
||||
```javascript
|
||||
var unencoded = qs.stringify({ a: { b: 'c' } }, { encode: false });
|
||||
assert.equal(unencoded, 'a[b]=c');
|
||||
```
|
||||
|
||||
Encoding can be disabled for keys by setting the `encodeValuesOnly` option to `true`:
|
||||
```javascript
|
||||
var encodedValues = qs.stringify(
|
||||
{ a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] },
|
||||
{ encodeValuesOnly: true }
|
||||
);
|
||||
assert.equal(encodedValues,'a=b&c[0]=d&c[1]=e%3Df&f[0][0]=g&f[1][0]=h');
|
||||
```
|
||||
|
||||
This encoding can also be replaced by a custom encoding method set as `encoder` option:
|
||||
|
||||
```javascript
|
||||
var encoded = qs.stringify({ a: { b: 'c' } }, { encoder: function (str) {
|
||||
// Passed in values `a`, `b`, `c`
|
||||
return // Return encoded string
|
||||
}})
|
||||
```
|
||||
|
||||
_(Note: the `encoder` option does not apply if `encode` is `false`)_
|
||||
|
||||
Analogue to the `encoder` there is a `decoder` option for `parse` to override decoding of properties and values:
|
||||
|
||||
```javascript
|
||||
var decoded = qs.parse('x=z', { decoder: function (str) {
|
||||
// Passed in values `x`, `z`
|
||||
return // Return decoded string
|
||||
}})
|
||||
```
|
||||
|
||||
You can encode keys and values using different logic by using the type argument provided to the encoder:
|
||||
|
||||
```javascript
|
||||
var encoded = qs.stringify({ a: { b: 'c' } }, { encoder: function (str, defaultEncoder, charset, type) {
|
||||
if (type === 'key') {
|
||||
return // Encoded key
|
||||
} else if (type === 'value') {
|
||||
return // Encoded value
|
||||
}
|
||||
}})
|
||||
```
|
||||
|
||||
The type argument is also provided to the decoder:
|
||||
|
||||
```javascript
|
||||
var decoded = qs.parse('x=z', { decoder: function (str, defaultDecoder, charset, type) {
|
||||
if (type === 'key') {
|
||||
return // Decoded key
|
||||
} else if (type === 'value') {
|
||||
return // Decoded value
|
||||
}
|
||||
}})
|
||||
```
|
||||
|
||||
Examples beyond this point will be shown as though the output is not URI encoded for clarity.
|
||||
Please note that the return values in these cases *will* be URI encoded during real usage.
|
||||
|
||||
When arrays are stringified, they follow the `arrayFormat` option, which defaults to `indices`:
|
||||
|
||||
```javascript
|
||||
qs.stringify({ a: ['b', 'c', 'd'] });
|
||||
// 'a[0]=b&a[1]=c&a[2]=d'
|
||||
```
|
||||
|
||||
You may override this by setting the `indices` option to `false`, or to be more explicit, the `arrayFormat` option to `repeat`:
|
||||
|
||||
```javascript
|
||||
qs.stringify({ a: ['b', 'c', 'd'] }, { indices: false });
|
||||
// 'a=b&a=c&a=d'
|
||||
```
|
||||
|
||||
You may use the `arrayFormat` option to specify the format of the output array:
|
||||
|
||||
```javascript
|
||||
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'indices' })
|
||||
// 'a[0]=b&a[1]=c'
|
||||
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'brackets' })
|
||||
// 'a[]=b&a[]=c'
|
||||
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'repeat' })
|
||||
// 'a=b&a=c'
|
||||
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'comma' })
|
||||
// 'a=b,c'
|
||||
```
|
||||
|
||||
Note: when using `arrayFormat` set to `'comma'`, you can also pass the `commaRoundTrip` option set to `true` or `false`, to append `[]` on single-item arrays, so that they can round trip through a parse.
|
||||
|
||||
When objects are stringified, by default they use bracket notation:
|
||||
|
||||
```javascript
|
||||
qs.stringify({ a: { b: { c: 'd', e: 'f' } } });
|
||||
// 'a[b][c]=d&a[b][e]=f'
|
||||
```
|
||||
|
||||
You may override this to use dot notation by setting the `allowDots` option to `true`:
|
||||
|
||||
```javascript
|
||||
qs.stringify({ a: { b: { c: 'd', e: 'f' } } }, { allowDots: true });
|
||||
// 'a.b.c=d&a.b.e=f'
|
||||
```
|
||||
|
||||
You may encode the dot notation in the keys of object with option `encodeDotInKeys` by setting it to `true`:
|
||||
Note: it implies `allowDots`, so `stringify` will error if you set `decodeDotInKeys` to `true`, and `allowDots` to `false`.
|
||||
Caveat: when `encodeValuesOnly` is `true` as well as `encodeDotInKeys`, only dots in keys and nothing else will be encoded.
|
||||
```javascript
|
||||
qs.stringify({ "name.obj": { "first": "John", "last": "Doe" } }, { allowDots: true, encodeDotInKeys: true })
|
||||
// 'name%252Eobj.first=John&name%252Eobj.last=Doe'
|
||||
```
|
||||
|
||||
You may allow empty array values by setting the `allowEmptyArrays` option to `true`:
|
||||
```javascript
|
||||
qs.stringify({ foo: [], bar: 'baz' }, { allowEmptyArrays: true });
|
||||
// 'foo[]&bar=baz'
|
||||
```
|
||||
|
||||
Empty strings and null values will omit the value, but the equals sign (=) remains in place:
|
||||
|
||||
```javascript
|
||||
assert.equal(qs.stringify({ a: '' }), 'a=');
|
||||
```
|
||||
|
||||
Key with no values (such as an empty object or array) will return nothing:
|
||||
|
||||
```javascript
|
||||
assert.equal(qs.stringify({ a: [] }), '');
|
||||
assert.equal(qs.stringify({ a: {} }), '');
|
||||
assert.equal(qs.stringify({ a: [{}] }), '');
|
||||
assert.equal(qs.stringify({ a: { b: []} }), '');
|
||||
assert.equal(qs.stringify({ a: { b: {}} }), '');
|
||||
```
|
||||
|
||||
Properties that are set to `undefined` will be omitted entirely:
|
||||
|
||||
```javascript
|
||||
assert.equal(qs.stringify({ a: null, b: undefined }), 'a=');
|
||||
```
|
||||
|
||||
The query string may optionally be prepended with a question mark:
|
||||
|
||||
```javascript
|
||||
assert.equal(qs.stringify({ a: 'b', c: 'd' }, { addQueryPrefix: true }), '?a=b&c=d');
|
||||
```
|
||||
|
||||
The delimiter may be overridden with stringify as well:
|
||||
|
||||
```javascript
|
||||
assert.equal(qs.stringify({ a: 'b', c: 'd' }, { delimiter: ';' }), 'a=b;c=d');
|
||||
```
|
||||
|
||||
If you only want to override the serialization of `Date` objects, you can provide a `serializeDate` option:
|
||||
|
||||
```javascript
|
||||
var date = new Date(7);
|
||||
assert.equal(qs.stringify({ a: date }), 'a=1970-01-01T00:00:00.007Z'.replace(/:/g, '%3A'));
|
||||
assert.equal(
|
||||
qs.stringify({ a: date }, { serializeDate: function (d) { return d.getTime(); } }),
|
||||
'a=7'
|
||||
);
|
||||
```
|
||||
|
||||
You may use the `sort` option to affect the order of parameter keys:
|
||||
|
||||
```javascript
|
||||
function alphabeticalSort(a, b) {
|
||||
return a.localeCompare(b);
|
||||
}
|
||||
assert.equal(qs.stringify({ a: 'c', z: 'y', b : 'f' }, { sort: alphabeticalSort }), 'a=c&b=f&z=y');
|
||||
```
|
||||
|
||||
Finally, you can use the `filter` option to restrict which keys will be included in the stringified output.
|
||||
If you pass a function, it will be called for each key to obtain the replacement value.
|
||||
Otherwise, if you pass an array, it will be used to select properties and array indices for stringification:
|
||||
|
||||
```javascript
|
||||
function filterFunc(prefix, value) {
|
||||
if (prefix == 'b') {
|
||||
// Return an `undefined` value to omit a property.
|
||||
return;
|
||||
}
|
||||
if (prefix == 'e[f]') {
|
||||
return value.getTime();
|
||||
}
|
||||
if (prefix == 'e[g][0]') {
|
||||
return value * 2;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
qs.stringify({ a: 'b', c: 'd', e: { f: new Date(123), g: [2] } }, { filter: filterFunc });
|
||||
// 'a=b&c=d&e[f]=123&e[g][0]=4'
|
||||
qs.stringify({ a: 'b', c: 'd', e: 'f' }, { filter: ['a', 'e'] });
|
||||
// 'a=b&e=f'
|
||||
qs.stringify({ a: ['b', 'c', 'd'], e: 'f' }, { filter: ['a', 0, 2] });
|
||||
// 'a[0]=b&a[2]=d'
|
||||
```
|
||||
|
||||
You could also use `filter` to inject custom serialization for user defined types.
|
||||
Consider you're working with some api that expects query strings of the format for ranges:
|
||||
|
||||
```
|
||||
https://domain.com/endpoint?range=30...70
|
||||
```
|
||||
|
||||
For which you model as:
|
||||
|
||||
```javascript
|
||||
class Range {
|
||||
constructor(from, to) {
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
You could _inject_ a custom serializer to handle values of this type:
|
||||
|
||||
```javascript
|
||||
qs.stringify(
|
||||
{
|
||||
range: new Range(30, 70),
|
||||
},
|
||||
{
|
||||
filter: (prefix, value) => {
|
||||
if (value instanceof Range) {
|
||||
return `${value.from}...${value.to}`;
|
||||
}
|
||||
// serialize the usual way
|
||||
return value;
|
||||
},
|
||||
}
|
||||
);
|
||||
// range=30...70
|
||||
```
|
||||
|
||||
### Handling of `null` values
|
||||
|
||||
By default, `null` values are treated like empty strings:
|
||||
|
||||
```javascript
|
||||
var withNull = qs.stringify({ a: null, b: '' });
|
||||
assert.equal(withNull, 'a=&b=');
|
||||
```
|
||||
|
||||
Parsing does not distinguish between parameters with and without equal signs.
|
||||
Both are converted to empty strings.
|
||||
|
||||
```javascript
|
||||
var equalsInsensitive = qs.parse('a&b=');
|
||||
assert.deepEqual(equalsInsensitive, { a: '', b: '' });
|
||||
```
|
||||
|
||||
To distinguish between `null` values and empty strings use the `strictNullHandling` flag. In the result string the `null`
|
||||
values have no `=` sign:
|
||||
|
||||
```javascript
|
||||
var strictNull = qs.stringify({ a: null, b: '' }, { strictNullHandling: true });
|
||||
assert.equal(strictNull, 'a&b=');
|
||||
```
|
||||
|
||||
To parse values without `=` back to `null` use the `strictNullHandling` flag:
|
||||
|
||||
```javascript
|
||||
var parsedStrictNull = qs.parse('a&b=', { strictNullHandling: true });
|
||||
assert.deepEqual(parsedStrictNull, { a: null, b: '' });
|
||||
```
|
||||
|
||||
To completely skip rendering keys with `null` values, use the `skipNulls` flag:
|
||||
|
||||
```javascript
|
||||
var nullsSkipped = qs.stringify({ a: 'b', c: null}, { skipNulls: true });
|
||||
assert.equal(nullsSkipped, 'a=b');
|
||||
```
|
||||
|
||||
If you're communicating with legacy systems, you can switch to `iso-8859-1` using the `charset` option:
|
||||
|
||||
```javascript
|
||||
var iso = qs.stringify({ æ: 'æ' }, { charset: 'iso-8859-1' });
|
||||
assert.equal(iso, '%E6=%E6');
|
||||
```
|
||||
|
||||
Characters that don't exist in `iso-8859-1` will be converted to numeric entities, similar to what browsers do:
|
||||
|
||||
```javascript
|
||||
var numeric = qs.stringify({ a: '☺' }, { charset: 'iso-8859-1' });
|
||||
assert.equal(numeric, 'a=%26%239786%3B');
|
||||
```
|
||||
|
||||
You can use the `charsetSentinel` option to announce the character by including an `utf8=✓` parameter with the proper encoding if the checkmark, similar to what Ruby on Rails and others do when submitting forms.
|
||||
|
||||
```javascript
|
||||
var sentinel = qs.stringify({ a: '☺' }, { charsetSentinel: true });
|
||||
assert.equal(sentinel, 'utf8=%E2%9C%93&a=%E2%98%BA');
|
||||
|
||||
var isoSentinel = qs.stringify({ a: 'æ' }, { charsetSentinel: true, charset: 'iso-8859-1' });
|
||||
assert.equal(isoSentinel, 'utf8=%26%2310003%3B&a=%E6');
|
||||
```
|
||||
|
||||
### Dealing with special character sets
|
||||
|
||||
By default the encoding and decoding of characters is done in `utf-8`, and `iso-8859-1` support is also built in via the `charset` parameter.
|
||||
|
||||
If you wish to encode querystrings to a different character set (i.e.
|
||||
[Shift JIS](https://en.wikipedia.org/wiki/Shift_JIS)) you can use the
|
||||
[`qs-iconv`](https://github.com/martinheidegger/qs-iconv) library:
|
||||
|
||||
```javascript
|
||||
var encoder = require('qs-iconv/encoder')('shift_jis');
|
||||
var shiftJISEncoded = qs.stringify({ a: 'こんにちは!' }, { encoder: encoder });
|
||||
assert.equal(shiftJISEncoded, 'a=%82%B1%82%F1%82%C9%82%BF%82%CD%81I');
|
||||
```
|
||||
|
||||
This also works for decoding of query strings:
|
||||
|
||||
```javascript
|
||||
var decoder = require('qs-iconv/decoder')('shift_jis');
|
||||
var obj = qs.parse('a=%82%B1%82%F1%82%C9%82%BF%82%CD%81I', { decoder: decoder });
|
||||
assert.deepEqual(obj, { a: 'こんにちは!' });
|
||||
```
|
||||
|
||||
### RFC 3986 and RFC 1738 space encoding
|
||||
|
||||
RFC3986 used as default option and encodes ' ' to *%20* which is backward compatible.
|
||||
In the same time, output can be stringified as per RFC1738 with ' ' equal to '+'.
|
||||
|
||||
```
|
||||
assert.equal(qs.stringify({ a: 'b c' }), 'a=b%20c');
|
||||
assert.equal(qs.stringify({ a: 'b c' }, { format : 'RFC3986' }), 'a=b%20c');
|
||||
assert.equal(qs.stringify({ a: 'b c' }, { format : 'RFC1738' }), 'a=b+c');
|
||||
```
|
||||
|
||||
## Security
|
||||
|
||||
Please email [@ljharb](https://github.com/ljharb) or see https://tidelift.com/security if you have a potential security vulnerability to report.
|
||||
|
||||
## qs for enterprise
|
||||
|
||||
Available as part of the Tidelift Subscription
|
||||
|
||||
The maintainers of qs and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications.
|
||||
Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use.
|
||||
[Learn more.](https://tidelift.com/subscription/pkg/npm-qs?utm_source=npm-qs&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
|
||||
|
||||
[package-url]: https://npmjs.org/package/qs
|
||||
[npm-version-svg]: https://versionbadg.es/ljharb/qs.svg
|
||||
[deps-svg]: https://david-dm.org/ljharb/qs.svg
|
||||
[deps-url]: https://david-dm.org/ljharb/qs
|
||||
[dev-deps-svg]: https://david-dm.org/ljharb/qs/dev-status.svg
|
||||
[dev-deps-url]: https://david-dm.org/ljharb/qs#info=devDependencies
|
||||
[npm-badge-png]: https://nodei.co/npm/qs.png?downloads=true&stars=true
|
||||
[license-image]: https://img.shields.io/npm/l/qs.svg
|
||||
[license-url]: LICENSE
|
||||
[downloads-image]: https://img.shields.io/npm/dm/qs.svg
|
||||
[downloads-url]: https://npm-stat.com/charts.html?package=qs
|
||||
[codecov-image]: https://codecov.io/gh/ljharb/qs/branch/main/graphs/badge.svg
|
||||
[codecov-url]: https://app.codecov.io/gh/ljharb/qs/
|
||||
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/qs
|
||||
[actions-url]: https://github.com/ljharb/qs/actions
|
||||
|
||||
## Acknowledgements
|
||||
|
||||
qs logo by [NUMI](https://github.com/numi-hq/open-design):
|
||||
|
||||
[<img src="https://raw.githubusercontent.com/numi-hq/open-design/main/assets/numi-lockup.png" alt="NUMI Logo" style="width: 200px;"/>](https://numi.tech/?ref=qs)
|
||||
90
ProjectSourceCode/node_modules/formidable/node_modules/qs/dist/qs.js
generated
vendored
Normal file
90
ProjectSourceCode/node_modules/formidable/node_modules/qs/dist/qs.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
23
ProjectSourceCode/node_modules/formidable/node_modules/qs/lib/formats.js
generated
vendored
Normal file
23
ProjectSourceCode/node_modules/formidable/node_modules/qs/lib/formats.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
var replace = String.prototype.replace;
|
||||
var percentTwenties = /%20/g;
|
||||
|
||||
var Format = {
|
||||
RFC1738: 'RFC1738',
|
||||
RFC3986: 'RFC3986'
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
'default': Format.RFC3986,
|
||||
formatters: {
|
||||
RFC1738: function (value) {
|
||||
return replace.call(value, percentTwenties, '+');
|
||||
},
|
||||
RFC3986: function (value) {
|
||||
return String(value);
|
||||
}
|
||||
},
|
||||
RFC1738: Format.RFC1738,
|
||||
RFC3986: Format.RFC3986
|
||||
};
|
||||
11
ProjectSourceCode/node_modules/formidable/node_modules/qs/lib/index.js
generated
vendored
Normal file
11
ProjectSourceCode/node_modules/formidable/node_modules/qs/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
var stringify = require('./stringify');
|
||||
var parse = require('./parse');
|
||||
var formats = require('./formats');
|
||||
|
||||
module.exports = {
|
||||
formats: formats,
|
||||
parse: parse,
|
||||
stringify: stringify
|
||||
};
|
||||
288
ProjectSourceCode/node_modules/formidable/node_modules/qs/lib/parse.js
generated
vendored
Normal file
288
ProjectSourceCode/node_modules/formidable/node_modules/qs/lib/parse.js
generated
vendored
Normal file
@@ -0,0 +1,288 @@
|
||||
'use strict';
|
||||
|
||||
var utils = require('./utils');
|
||||
|
||||
var has = Object.prototype.hasOwnProperty;
|
||||
var isArray = Array.isArray;
|
||||
|
||||
var defaults = {
|
||||
allowDots: false,
|
||||
allowEmptyArrays: false,
|
||||
allowPrototypes: false,
|
||||
allowSparse: false,
|
||||
arrayLimit: 20,
|
||||
charset: 'utf-8',
|
||||
charsetSentinel: false,
|
||||
comma: false,
|
||||
decodeDotInKeys: true,
|
||||
decoder: utils.decode,
|
||||
delimiter: '&',
|
||||
depth: 5,
|
||||
duplicates: 'combine',
|
||||
ignoreQueryPrefix: false,
|
||||
interpretNumericEntities: false,
|
||||
parameterLimit: 1000,
|
||||
parseArrays: true,
|
||||
plainObjects: false,
|
||||
strictNullHandling: false
|
||||
};
|
||||
|
||||
var interpretNumericEntities = function (str) {
|
||||
return str.replace(/&#(\d+);/g, function ($0, numberStr) {
|
||||
return String.fromCharCode(parseInt(numberStr, 10));
|
||||
});
|
||||
};
|
||||
|
||||
var parseArrayValue = function (val, options) {
|
||||
if (val && typeof val === 'string' && options.comma && val.indexOf(',') > -1) {
|
||||
return val.split(',');
|
||||
}
|
||||
|
||||
return val;
|
||||
};
|
||||
|
||||
// This is what browsers will submit when the ✓ character occurs in an
|
||||
// application/x-www-form-urlencoded body and the encoding of the page containing
|
||||
// the form is iso-8859-1, or when the submitted form has an accept-charset
|
||||
// attribute of iso-8859-1. Presumably also with other charsets that do not contain
|
||||
// the ✓ character, such as us-ascii.
|
||||
var isoSentinel = 'utf8=%26%2310003%3B'; // encodeURIComponent('✓')
|
||||
|
||||
// These are the percent-encoded utf-8 octets representing a checkmark, indicating that the request actually is utf-8 encoded.
|
||||
var charsetSentinel = 'utf8=%E2%9C%93'; // encodeURIComponent('✓')
|
||||
|
||||
var parseValues = function parseQueryStringValues(str, options) {
|
||||
var obj = { __proto__: null };
|
||||
|
||||
var cleanStr = options.ignoreQueryPrefix ? str.replace(/^\?/, '') : str;
|
||||
var limit = options.parameterLimit === Infinity ? undefined : options.parameterLimit;
|
||||
var parts = cleanStr.split(options.delimiter, limit);
|
||||
var skipIndex = -1; // Keep track of where the utf8 sentinel was found
|
||||
var i;
|
||||
|
||||
var charset = options.charset;
|
||||
if (options.charsetSentinel) {
|
||||
for (i = 0; i < parts.length; ++i) {
|
||||
if (parts[i].indexOf('utf8=') === 0) {
|
||||
if (parts[i] === charsetSentinel) {
|
||||
charset = 'utf-8';
|
||||
} else if (parts[i] === isoSentinel) {
|
||||
charset = 'iso-8859-1';
|
||||
}
|
||||
skipIndex = i;
|
||||
i = parts.length; // The eslint settings do not allow break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < parts.length; ++i) {
|
||||
if (i === skipIndex) {
|
||||
continue;
|
||||
}
|
||||
var part = parts[i];
|
||||
|
||||
var bracketEqualsPos = part.indexOf(']=');
|
||||
var pos = bracketEqualsPos === -1 ? part.indexOf('=') : bracketEqualsPos + 1;
|
||||
|
||||
var key, val;
|
||||
if (pos === -1) {
|
||||
key = options.decoder(part, defaults.decoder, charset, 'key');
|
||||
val = options.strictNullHandling ? null : '';
|
||||
} else {
|
||||
key = options.decoder(part.slice(0, pos), defaults.decoder, charset, 'key');
|
||||
val = utils.maybeMap(
|
||||
parseArrayValue(part.slice(pos + 1), options),
|
||||
function (encodedVal) {
|
||||
return options.decoder(encodedVal, defaults.decoder, charset, 'value');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (val && options.interpretNumericEntities && charset === 'iso-8859-1') {
|
||||
val = interpretNumericEntities(val);
|
||||
}
|
||||
|
||||
if (part.indexOf('[]=') > -1) {
|
||||
val = isArray(val) ? [val] : val;
|
||||
}
|
||||
|
||||
var existing = has.call(obj, key);
|
||||
if (existing && options.duplicates === 'combine') {
|
||||
obj[key] = utils.combine(obj[key], val);
|
||||
} else if (!existing || options.duplicates === 'last') {
|
||||
obj[key] = val;
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
var parseObject = function (chain, val, options, valuesParsed) {
|
||||
var leaf = valuesParsed ? val : parseArrayValue(val, options);
|
||||
|
||||
for (var i = chain.length - 1; i >= 0; --i) {
|
||||
var obj;
|
||||
var root = chain[i];
|
||||
|
||||
if (root === '[]' && options.parseArrays) {
|
||||
obj = options.allowEmptyArrays && leaf === '' ? [] : [].concat(leaf);
|
||||
} else {
|
||||
obj = options.plainObjects ? Object.create(null) : {};
|
||||
var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root;
|
||||
var decodedRoot = options.decodeDotInKeys ? cleanRoot.replace(/%2E/g, '.') : cleanRoot;
|
||||
var index = parseInt(decodedRoot, 10);
|
||||
if (!options.parseArrays && decodedRoot === '') {
|
||||
obj = { 0: leaf };
|
||||
} else if (
|
||||
!isNaN(index)
|
||||
&& root !== decodedRoot
|
||||
&& String(index) === decodedRoot
|
||||
&& index >= 0
|
||||
&& (options.parseArrays && index <= options.arrayLimit)
|
||||
) {
|
||||
obj = [];
|
||||
obj[index] = leaf;
|
||||
} else if (decodedRoot !== '__proto__') {
|
||||
obj[decodedRoot] = leaf;
|
||||
}
|
||||
}
|
||||
|
||||
leaf = obj;
|
||||
}
|
||||
|
||||
return leaf;
|
||||
};
|
||||
|
||||
var parseKeys = function parseQueryStringKeys(givenKey, val, options, valuesParsed) {
|
||||
if (!givenKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Transform dot notation to bracket notation
|
||||
var key = options.allowDots ? givenKey.replace(/\.([^.[]+)/g, '[$1]') : givenKey;
|
||||
|
||||
// The regex chunks
|
||||
|
||||
var brackets = /(\[[^[\]]*])/;
|
||||
var child = /(\[[^[\]]*])/g;
|
||||
|
||||
// Get the parent
|
||||
|
||||
var segment = options.depth > 0 && brackets.exec(key);
|
||||
var parent = segment ? key.slice(0, segment.index) : key;
|
||||
|
||||
// Stash the parent if it exists
|
||||
|
||||
var keys = [];
|
||||
if (parent) {
|
||||
// If we aren't using plain objects, optionally prefix keys that would overwrite object prototype properties
|
||||
if (!options.plainObjects && has.call(Object.prototype, parent)) {
|
||||
if (!options.allowPrototypes) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
keys.push(parent);
|
||||
}
|
||||
|
||||
// Loop through children appending to the array until we hit depth
|
||||
|
||||
var i = 0;
|
||||
while (options.depth > 0 && (segment = child.exec(key)) !== null && i < options.depth) {
|
||||
i += 1;
|
||||
if (!options.plainObjects && has.call(Object.prototype, segment[1].slice(1, -1))) {
|
||||
if (!options.allowPrototypes) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
keys.push(segment[1]);
|
||||
}
|
||||
|
||||
// If there's a remainder, just add whatever is left
|
||||
|
||||
if (segment) {
|
||||
keys.push('[' + key.slice(segment.index) + ']');
|
||||
}
|
||||
|
||||
return parseObject(keys, val, options, valuesParsed);
|
||||
};
|
||||
|
||||
var normalizeParseOptions = function normalizeParseOptions(opts) {
|
||||
if (!opts) {
|
||||
return defaults;
|
||||
}
|
||||
|
||||
if (typeof opts.allowEmptyArrays !== 'undefined' && typeof opts.allowEmptyArrays !== 'boolean') {
|
||||
throw new TypeError('`allowEmptyArrays` option can only be `true` or `false`, when provided');
|
||||
}
|
||||
|
||||
if (typeof opts.decodeDotInKeys !== 'undefined' && typeof opts.decodeDotInKeys !== 'boolean') {
|
||||
throw new TypeError('`decodeDotInKeys` option can only be `true` or `false`, when provided');
|
||||
}
|
||||
|
||||
if (opts.decoder !== null && typeof opts.decoder !== 'undefined' && typeof opts.decoder !== 'function') {
|
||||
throw new TypeError('Decoder has to be a function.');
|
||||
}
|
||||
|
||||
if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
|
||||
throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined');
|
||||
}
|
||||
var charset = typeof opts.charset === 'undefined' ? defaults.charset : opts.charset;
|
||||
|
||||
var duplicates = typeof opts.duplicates === 'undefined' ? defaults.duplicates : opts.duplicates;
|
||||
|
||||
if (duplicates !== 'combine' && duplicates !== 'first' && duplicates !== 'last') {
|
||||
throw new TypeError('The duplicates option must be either combine, first, or last');
|
||||
}
|
||||
|
||||
var allowDots = typeof opts.allowDots === 'undefined' ? opts.decodeDotInKeys === true ? true : defaults.allowDots : !!opts.allowDots;
|
||||
|
||||
return {
|
||||
allowDots: allowDots,
|
||||
allowEmptyArrays: typeof opts.allowEmptyArrays === 'boolean' ? !!opts.allowEmptyArrays : defaults.allowEmptyArrays,
|
||||
allowPrototypes: typeof opts.allowPrototypes === 'boolean' ? opts.allowPrototypes : defaults.allowPrototypes,
|
||||
allowSparse: typeof opts.allowSparse === 'boolean' ? opts.allowSparse : defaults.allowSparse,
|
||||
arrayLimit: typeof opts.arrayLimit === 'number' ? opts.arrayLimit : defaults.arrayLimit,
|
||||
charset: charset,
|
||||
charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,
|
||||
comma: typeof opts.comma === 'boolean' ? opts.comma : defaults.comma,
|
||||
decodeDotInKeys: typeof opts.decodeDotInKeys === 'boolean' ? opts.decodeDotInKeys : defaults.decodeDotInKeys,
|
||||
decoder: typeof opts.decoder === 'function' ? opts.decoder : defaults.decoder,
|
||||
delimiter: typeof opts.delimiter === 'string' || utils.isRegExp(opts.delimiter) ? opts.delimiter : defaults.delimiter,
|
||||
// eslint-disable-next-line no-implicit-coercion, no-extra-parens
|
||||
depth: (typeof opts.depth === 'number' || opts.depth === false) ? +opts.depth : defaults.depth,
|
||||
duplicates: duplicates,
|
||||
ignoreQueryPrefix: opts.ignoreQueryPrefix === true,
|
||||
interpretNumericEntities: typeof opts.interpretNumericEntities === 'boolean' ? opts.interpretNumericEntities : defaults.interpretNumericEntities,
|
||||
parameterLimit: typeof opts.parameterLimit === 'number' ? opts.parameterLimit : defaults.parameterLimit,
|
||||
parseArrays: opts.parseArrays !== false,
|
||||
plainObjects: typeof opts.plainObjects === 'boolean' ? opts.plainObjects : defaults.plainObjects,
|
||||
strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = function (str, opts) {
|
||||
var options = normalizeParseOptions(opts);
|
||||
|
||||
if (str === '' || str === null || typeof str === 'undefined') {
|
||||
return options.plainObjects ? Object.create(null) : {};
|
||||
}
|
||||
|
||||
var tempObj = typeof str === 'string' ? parseValues(str, options) : str;
|
||||
var obj = options.plainObjects ? Object.create(null) : {};
|
||||
|
||||
// Iterate over the keys and setup the new object
|
||||
|
||||
var keys = Object.keys(tempObj);
|
||||
for (var i = 0; i < keys.length; ++i) {
|
||||
var key = keys[i];
|
||||
var newObj = parseKeys(key, tempObj[key], options, typeof str === 'string');
|
||||
obj = utils.merge(obj, newObj, options);
|
||||
}
|
||||
|
||||
if (options.allowSparse === true) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
return utils.compact(obj);
|
||||
};
|
||||
351
ProjectSourceCode/node_modules/formidable/node_modules/qs/lib/stringify.js
generated
vendored
Normal file
351
ProjectSourceCode/node_modules/formidable/node_modules/qs/lib/stringify.js
generated
vendored
Normal file
@@ -0,0 +1,351 @@
|
||||
'use strict';
|
||||
|
||||
var getSideChannel = require('side-channel');
|
||||
var utils = require('./utils');
|
||||
var formats = require('./formats');
|
||||
var has = Object.prototype.hasOwnProperty;
|
||||
|
||||
var arrayPrefixGenerators = {
|
||||
brackets: function brackets(prefix) {
|
||||
return prefix + '[]';
|
||||
},
|
||||
comma: 'comma',
|
||||
indices: function indices(prefix, key) {
|
||||
return prefix + '[' + key + ']';
|
||||
},
|
||||
repeat: function repeat(prefix) {
|
||||
return prefix;
|
||||
}
|
||||
};
|
||||
|
||||
var isArray = Array.isArray;
|
||||
var push = Array.prototype.push;
|
||||
var pushToArray = function (arr, valueOrArray) {
|
||||
push.apply(arr, isArray(valueOrArray) ? valueOrArray : [valueOrArray]);
|
||||
};
|
||||
|
||||
var toISO = Date.prototype.toISOString;
|
||||
|
||||
var defaultFormat = formats['default'];
|
||||
var defaults = {
|
||||
addQueryPrefix: false,
|
||||
allowDots: false,
|
||||
allowEmptyArrays: false,
|
||||
arrayFormat: 'indices',
|
||||
charset: 'utf-8',
|
||||
charsetSentinel: false,
|
||||
delimiter: '&',
|
||||
encode: true,
|
||||
encodeDotInKeys: false,
|
||||
encoder: utils.encode,
|
||||
encodeValuesOnly: false,
|
||||
format: defaultFormat,
|
||||
formatter: formats.formatters[defaultFormat],
|
||||
// deprecated
|
||||
indices: false,
|
||||
serializeDate: function serializeDate(date) {
|
||||
return toISO.call(date);
|
||||
},
|
||||
skipNulls: false,
|
||||
strictNullHandling: false
|
||||
};
|
||||
|
||||
var isNonNullishPrimitive = function isNonNullishPrimitive(v) {
|
||||
return typeof v === 'string'
|
||||
|| typeof v === 'number'
|
||||
|| typeof v === 'boolean'
|
||||
|| typeof v === 'symbol'
|
||||
|| typeof v === 'bigint';
|
||||
};
|
||||
|
||||
var sentinel = {};
|
||||
|
||||
var stringify = function stringify(
|
||||
object,
|
||||
prefix,
|
||||
generateArrayPrefix,
|
||||
commaRoundTrip,
|
||||
allowEmptyArrays,
|
||||
strictNullHandling,
|
||||
skipNulls,
|
||||
encodeDotInKeys,
|
||||
encoder,
|
||||
filter,
|
||||
sort,
|
||||
allowDots,
|
||||
serializeDate,
|
||||
format,
|
||||
formatter,
|
||||
encodeValuesOnly,
|
||||
charset,
|
||||
sideChannel
|
||||
) {
|
||||
var obj = object;
|
||||
|
||||
var tmpSc = sideChannel;
|
||||
var step = 0;
|
||||
var findFlag = false;
|
||||
while ((tmpSc = tmpSc.get(sentinel)) !== void undefined && !findFlag) {
|
||||
// Where object last appeared in the ref tree
|
||||
var pos = tmpSc.get(object);
|
||||
step += 1;
|
||||
if (typeof pos !== 'undefined') {
|
||||
if (pos === step) {
|
||||
throw new RangeError('Cyclic object value');
|
||||
} else {
|
||||
findFlag = true; // Break while
|
||||
}
|
||||
}
|
||||
if (typeof tmpSc.get(sentinel) === 'undefined') {
|
||||
step = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof filter === 'function') {
|
||||
obj = filter(prefix, obj);
|
||||
} else if (obj instanceof Date) {
|
||||
obj = serializeDate(obj);
|
||||
} else if (generateArrayPrefix === 'comma' && isArray(obj)) {
|
||||
obj = utils.maybeMap(obj, function (value) {
|
||||
if (value instanceof Date) {
|
||||
return serializeDate(value);
|
||||
}
|
||||
return value;
|
||||
});
|
||||
}
|
||||
|
||||
if (obj === null) {
|
||||
if (strictNullHandling) {
|
||||
return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder, charset, 'key', format) : prefix;
|
||||
}
|
||||
|
||||
obj = '';
|
||||
}
|
||||
|
||||
if (isNonNullishPrimitive(obj) || utils.isBuffer(obj)) {
|
||||
if (encoder) {
|
||||
var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder, charset, 'key', format);
|
||||
return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder, charset, 'value', format))];
|
||||
}
|
||||
return [formatter(prefix) + '=' + formatter(String(obj))];
|
||||
}
|
||||
|
||||
var values = [];
|
||||
|
||||
if (typeof obj === 'undefined') {
|
||||
return values;
|
||||
}
|
||||
|
||||
var objKeys;
|
||||
if (generateArrayPrefix === 'comma' && isArray(obj)) {
|
||||
// we need to join elements in
|
||||
if (encodeValuesOnly && encoder) {
|
||||
obj = utils.maybeMap(obj, encoder);
|
||||
}
|
||||
objKeys = [{ value: obj.length > 0 ? obj.join(',') || null : void undefined }];
|
||||
} else if (isArray(filter)) {
|
||||
objKeys = filter;
|
||||
} else {
|
||||
var keys = Object.keys(obj);
|
||||
objKeys = sort ? keys.sort(sort) : keys;
|
||||
}
|
||||
|
||||
var encodedPrefix = encodeDotInKeys ? prefix.replace(/\./g, '%2E') : prefix;
|
||||
|
||||
var adjustedPrefix = commaRoundTrip && isArray(obj) && obj.length === 1 ? encodedPrefix + '[]' : encodedPrefix;
|
||||
|
||||
if (allowEmptyArrays && isArray(obj) && obj.length === 0) {
|
||||
return adjustedPrefix + '[]';
|
||||
}
|
||||
|
||||
for (var j = 0; j < objKeys.length; ++j) {
|
||||
var key = objKeys[j];
|
||||
var value = typeof key === 'object' && typeof key.value !== 'undefined' ? key.value : obj[key];
|
||||
|
||||
if (skipNulls && value === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var encodedKey = allowDots && encodeDotInKeys ? key.replace(/\./g, '%2E') : key;
|
||||
var keyPrefix = isArray(obj)
|
||||
? typeof generateArrayPrefix === 'function' ? generateArrayPrefix(adjustedPrefix, encodedKey) : adjustedPrefix
|
||||
: adjustedPrefix + (allowDots ? '.' + encodedKey : '[' + encodedKey + ']');
|
||||
|
||||
sideChannel.set(object, step);
|
||||
var valueSideChannel = getSideChannel();
|
||||
valueSideChannel.set(sentinel, sideChannel);
|
||||
pushToArray(values, stringify(
|
||||
value,
|
||||
keyPrefix,
|
||||
generateArrayPrefix,
|
||||
commaRoundTrip,
|
||||
allowEmptyArrays,
|
||||
strictNullHandling,
|
||||
skipNulls,
|
||||
encodeDotInKeys,
|
||||
generateArrayPrefix === 'comma' && encodeValuesOnly && isArray(obj) ? null : encoder,
|
||||
filter,
|
||||
sort,
|
||||
allowDots,
|
||||
serializeDate,
|
||||
format,
|
||||
formatter,
|
||||
encodeValuesOnly,
|
||||
charset,
|
||||
valueSideChannel
|
||||
));
|
||||
}
|
||||
|
||||
return values;
|
||||
};
|
||||
|
||||
var normalizeStringifyOptions = function normalizeStringifyOptions(opts) {
|
||||
if (!opts) {
|
||||
return defaults;
|
||||
}
|
||||
|
||||
if (typeof opts.allowEmptyArrays !== 'undefined' && typeof opts.allowEmptyArrays !== 'boolean') {
|
||||
throw new TypeError('`allowEmptyArrays` option can only be `true` or `false`, when provided');
|
||||
}
|
||||
|
||||
if (typeof opts.encodeDotInKeys !== 'undefined' && typeof opts.encodeDotInKeys !== 'boolean') {
|
||||
throw new TypeError('`encodeDotInKeys` option can only be `true` or `false`, when provided');
|
||||
}
|
||||
|
||||
if (opts.encoder !== null && typeof opts.encoder !== 'undefined' && typeof opts.encoder !== 'function') {
|
||||
throw new TypeError('Encoder has to be a function.');
|
||||
}
|
||||
|
||||
var charset = opts.charset || defaults.charset;
|
||||
if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
|
||||
throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined');
|
||||
}
|
||||
|
||||
var format = formats['default'];
|
||||
if (typeof opts.format !== 'undefined') {
|
||||
if (!has.call(formats.formatters, opts.format)) {
|
||||
throw new TypeError('Unknown format option provided.');
|
||||
}
|
||||
format = opts.format;
|
||||
}
|
||||
var formatter = formats.formatters[format];
|
||||
|
||||
var filter = defaults.filter;
|
||||
if (typeof opts.filter === 'function' || isArray(opts.filter)) {
|
||||
filter = opts.filter;
|
||||
}
|
||||
|
||||
var arrayFormat;
|
||||
if (opts.arrayFormat in arrayPrefixGenerators) {
|
||||
arrayFormat = opts.arrayFormat;
|
||||
} else if ('indices' in opts) {
|
||||
arrayFormat = opts.indices ? 'indices' : 'repeat';
|
||||
} else {
|
||||
arrayFormat = defaults.arrayFormat;
|
||||
}
|
||||
|
||||
if ('commaRoundTrip' in opts && typeof opts.commaRoundTrip !== 'boolean') {
|
||||
throw new TypeError('`commaRoundTrip` must be a boolean, or absent');
|
||||
}
|
||||
|
||||
var allowDots = typeof opts.allowDots === 'undefined' ? opts.encodeDotInKeys === true ? true : defaults.allowDots : !!opts.allowDots;
|
||||
|
||||
return {
|
||||
addQueryPrefix: typeof opts.addQueryPrefix === 'boolean' ? opts.addQueryPrefix : defaults.addQueryPrefix,
|
||||
allowDots: allowDots,
|
||||
allowEmptyArrays: typeof opts.allowEmptyArrays === 'boolean' ? !!opts.allowEmptyArrays : defaults.allowEmptyArrays,
|
||||
arrayFormat: arrayFormat,
|
||||
charset: charset,
|
||||
charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,
|
||||
commaRoundTrip: opts.commaRoundTrip,
|
||||
delimiter: typeof opts.delimiter === 'undefined' ? defaults.delimiter : opts.delimiter,
|
||||
encode: typeof opts.encode === 'boolean' ? opts.encode : defaults.encode,
|
||||
encodeDotInKeys: typeof opts.encodeDotInKeys === 'boolean' ? opts.encodeDotInKeys : defaults.encodeDotInKeys,
|
||||
encoder: typeof opts.encoder === 'function' ? opts.encoder : defaults.encoder,
|
||||
encodeValuesOnly: typeof opts.encodeValuesOnly === 'boolean' ? opts.encodeValuesOnly : defaults.encodeValuesOnly,
|
||||
filter: filter,
|
||||
format: format,
|
||||
formatter: formatter,
|
||||
serializeDate: typeof opts.serializeDate === 'function' ? opts.serializeDate : defaults.serializeDate,
|
||||
skipNulls: typeof opts.skipNulls === 'boolean' ? opts.skipNulls : defaults.skipNulls,
|
||||
sort: typeof opts.sort === 'function' ? opts.sort : null,
|
||||
strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = function (object, opts) {
|
||||
var obj = object;
|
||||
var options = normalizeStringifyOptions(opts);
|
||||
|
||||
var objKeys;
|
||||
var filter;
|
||||
|
||||
if (typeof options.filter === 'function') {
|
||||
filter = options.filter;
|
||||
obj = filter('', obj);
|
||||
} else if (isArray(options.filter)) {
|
||||
filter = options.filter;
|
||||
objKeys = filter;
|
||||
}
|
||||
|
||||
var keys = [];
|
||||
|
||||
if (typeof obj !== 'object' || obj === null) {
|
||||
return '';
|
||||
}
|
||||
|
||||
var generateArrayPrefix = arrayPrefixGenerators[options.arrayFormat];
|
||||
var commaRoundTrip = generateArrayPrefix === 'comma' && options.commaRoundTrip;
|
||||
|
||||
if (!objKeys) {
|
||||
objKeys = Object.keys(obj);
|
||||
}
|
||||
|
||||
if (options.sort) {
|
||||
objKeys.sort(options.sort);
|
||||
}
|
||||
|
||||
var sideChannel = getSideChannel();
|
||||
for (var i = 0; i < objKeys.length; ++i) {
|
||||
var key = objKeys[i];
|
||||
|
||||
if (options.skipNulls && obj[key] === null) {
|
||||
continue;
|
||||
}
|
||||
pushToArray(keys, stringify(
|
||||
obj[key],
|
||||
key,
|
||||
generateArrayPrefix,
|
||||
commaRoundTrip,
|
||||
options.allowEmptyArrays,
|
||||
options.strictNullHandling,
|
||||
options.skipNulls,
|
||||
options.encodeDotInKeys,
|
||||
options.encode ? options.encoder : null,
|
||||
options.filter,
|
||||
options.sort,
|
||||
options.allowDots,
|
||||
options.serializeDate,
|
||||
options.format,
|
||||
options.formatter,
|
||||
options.encodeValuesOnly,
|
||||
options.charset,
|
||||
sideChannel
|
||||
));
|
||||
}
|
||||
|
||||
var joined = keys.join(options.delimiter);
|
||||
var prefix = options.addQueryPrefix === true ? '?' : '';
|
||||
|
||||
if (options.charsetSentinel) {
|
||||
if (options.charset === 'iso-8859-1') {
|
||||
// encodeURIComponent('✓'), the "numeric entity" representation of a checkmark
|
||||
prefix += 'utf8=%26%2310003%3B&';
|
||||
} else {
|
||||
// encodeURIComponent('✓')
|
||||
prefix += 'utf8=%E2%9C%93&';
|
||||
}
|
||||
}
|
||||
|
||||
return joined.length > 0 ? prefix + joined : '';
|
||||
};
|
||||
252
ProjectSourceCode/node_modules/formidable/node_modules/qs/lib/utils.js
generated
vendored
Normal file
252
ProjectSourceCode/node_modules/formidable/node_modules/qs/lib/utils.js
generated
vendored
Normal file
@@ -0,0 +1,252 @@
|
||||
'use strict';
|
||||
|
||||
var formats = require('./formats');
|
||||
|
||||
var has = Object.prototype.hasOwnProperty;
|
||||
var isArray = Array.isArray;
|
||||
|
||||
var hexTable = (function () {
|
||||
var array = [];
|
||||
for (var i = 0; i < 256; ++i) {
|
||||
array.push('%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase());
|
||||
}
|
||||
|
||||
return array;
|
||||
}());
|
||||
|
||||
var compactQueue = function compactQueue(queue) {
|
||||
while (queue.length > 1) {
|
||||
var item = queue.pop();
|
||||
var obj = item.obj[item.prop];
|
||||
|
||||
if (isArray(obj)) {
|
||||
var compacted = [];
|
||||
|
||||
for (var j = 0; j < obj.length; ++j) {
|
||||
if (typeof obj[j] !== 'undefined') {
|
||||
compacted.push(obj[j]);
|
||||
}
|
||||
}
|
||||
|
||||
item.obj[item.prop] = compacted;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var arrayToObject = function arrayToObject(source, options) {
|
||||
var obj = options && options.plainObjects ? Object.create(null) : {};
|
||||
for (var i = 0; i < source.length; ++i) {
|
||||
if (typeof source[i] !== 'undefined') {
|
||||
obj[i] = source[i];
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
var merge = function merge(target, source, options) {
|
||||
/* eslint no-param-reassign: 0 */
|
||||
if (!source) {
|
||||
return target;
|
||||
}
|
||||
|
||||
if (typeof source !== 'object') {
|
||||
if (isArray(target)) {
|
||||
target.push(source);
|
||||
} else if (target && typeof target === 'object') {
|
||||
if ((options && (options.plainObjects || options.allowPrototypes)) || !has.call(Object.prototype, source)) {
|
||||
target[source] = true;
|
||||
}
|
||||
} else {
|
||||
return [target, source];
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
if (!target || typeof target !== 'object') {
|
||||
return [target].concat(source);
|
||||
}
|
||||
|
||||
var mergeTarget = target;
|
||||
if (isArray(target) && !isArray(source)) {
|
||||
mergeTarget = arrayToObject(target, options);
|
||||
}
|
||||
|
||||
if (isArray(target) && isArray(source)) {
|
||||
source.forEach(function (item, i) {
|
||||
if (has.call(target, i)) {
|
||||
var targetItem = target[i];
|
||||
if (targetItem && typeof targetItem === 'object' && item && typeof item === 'object') {
|
||||
target[i] = merge(targetItem, item, options);
|
||||
} else {
|
||||
target.push(item);
|
||||
}
|
||||
} else {
|
||||
target[i] = item;
|
||||
}
|
||||
});
|
||||
return target;
|
||||
}
|
||||
|
||||
return Object.keys(source).reduce(function (acc, key) {
|
||||
var value = source[key];
|
||||
|
||||
if (has.call(acc, key)) {
|
||||
acc[key] = merge(acc[key], value, options);
|
||||
} else {
|
||||
acc[key] = value;
|
||||
}
|
||||
return acc;
|
||||
}, mergeTarget);
|
||||
};
|
||||
|
||||
var assign = function assignSingleSource(target, source) {
|
||||
return Object.keys(source).reduce(function (acc, key) {
|
||||
acc[key] = source[key];
|
||||
return acc;
|
||||
}, target);
|
||||
};
|
||||
|
||||
var decode = function (str, decoder, charset) {
|
||||
var strWithoutPlus = str.replace(/\+/g, ' ');
|
||||
if (charset === 'iso-8859-1') {
|
||||
// unescape never throws, no try...catch needed:
|
||||
return strWithoutPlus.replace(/%[0-9a-f]{2}/gi, unescape);
|
||||
}
|
||||
// utf-8
|
||||
try {
|
||||
return decodeURIComponent(strWithoutPlus);
|
||||
} catch (e) {
|
||||
return strWithoutPlus;
|
||||
}
|
||||
};
|
||||
|
||||
var encode = function encode(str, defaultEncoder, charset, kind, format) {
|
||||
// This code was originally written by Brian White (mscdex) for the io.js core querystring library.
|
||||
// It has been adapted here for stricter adherence to RFC 3986
|
||||
if (str.length === 0) {
|
||||
return str;
|
||||
}
|
||||
|
||||
var string = str;
|
||||
if (typeof str === 'symbol') {
|
||||
string = Symbol.prototype.toString.call(str);
|
||||
} else if (typeof str !== 'string') {
|
||||
string = String(str);
|
||||
}
|
||||
|
||||
if (charset === 'iso-8859-1') {
|
||||
return escape(string).replace(/%u[0-9a-f]{4}/gi, function ($0) {
|
||||
return '%26%23' + parseInt($0.slice(2), 16) + '%3B';
|
||||
});
|
||||
}
|
||||
|
||||
var out = '';
|
||||
for (var i = 0; i < string.length; ++i) {
|
||||
var c = string.charCodeAt(i);
|
||||
|
||||
if (
|
||||
c === 0x2D // -
|
||||
|| c === 0x2E // .
|
||||
|| c === 0x5F // _
|
||||
|| c === 0x7E // ~
|
||||
|| (c >= 0x30 && c <= 0x39) // 0-9
|
||||
|| (c >= 0x41 && c <= 0x5A) // a-z
|
||||
|| (c >= 0x61 && c <= 0x7A) // A-Z
|
||||
|| (format === formats.RFC1738 && (c === 0x28 || c === 0x29)) // ( )
|
||||
) {
|
||||
out += string.charAt(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c < 0x80) {
|
||||
out = out + hexTable[c];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c < 0x800) {
|
||||
out = out + (hexTable[0xC0 | (c >> 6)] + hexTable[0x80 | (c & 0x3F)]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c < 0xD800 || c >= 0xE000) {
|
||||
out = out + (hexTable[0xE0 | (c >> 12)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)]);
|
||||
continue;
|
||||
}
|
||||
|
||||
i += 1;
|
||||
c = 0x10000 + (((c & 0x3FF) << 10) | (string.charCodeAt(i) & 0x3FF));
|
||||
/* eslint operator-linebreak: [2, "before"] */
|
||||
out += hexTable[0xF0 | (c >> 18)]
|
||||
+ hexTable[0x80 | ((c >> 12) & 0x3F)]
|
||||
+ hexTable[0x80 | ((c >> 6) & 0x3F)]
|
||||
+ hexTable[0x80 | (c & 0x3F)];
|
||||
}
|
||||
|
||||
return out;
|
||||
};
|
||||
|
||||
var compact = function compact(value) {
|
||||
var queue = [{ obj: { o: value }, prop: 'o' }];
|
||||
var refs = [];
|
||||
|
||||
for (var i = 0; i < queue.length; ++i) {
|
||||
var item = queue[i];
|
||||
var obj = item.obj[item.prop];
|
||||
|
||||
var keys = Object.keys(obj);
|
||||
for (var j = 0; j < keys.length; ++j) {
|
||||
var key = keys[j];
|
||||
var val = obj[key];
|
||||
if (typeof val === 'object' && val !== null && refs.indexOf(val) === -1) {
|
||||
queue.push({ obj: obj, prop: key });
|
||||
refs.push(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
compactQueue(queue);
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
var isRegExp = function isRegExp(obj) {
|
||||
return Object.prototype.toString.call(obj) === '[object RegExp]';
|
||||
};
|
||||
|
||||
var isBuffer = function isBuffer(obj) {
|
||||
if (!obj || typeof obj !== 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj));
|
||||
};
|
||||
|
||||
var combine = function combine(a, b) {
|
||||
return [].concat(a, b);
|
||||
};
|
||||
|
||||
var maybeMap = function maybeMap(val, fn) {
|
||||
if (isArray(val)) {
|
||||
var mapped = [];
|
||||
for (var i = 0; i < val.length; i += 1) {
|
||||
mapped.push(fn(val[i]));
|
||||
}
|
||||
return mapped;
|
||||
}
|
||||
return fn(val);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
arrayToObject: arrayToObject,
|
||||
assign: assign,
|
||||
combine: combine,
|
||||
compact: compact,
|
||||
decode: decode,
|
||||
encode: encode,
|
||||
isBuffer: isBuffer,
|
||||
isRegExp: isRegExp,
|
||||
maybeMap: maybeMap,
|
||||
merge: merge
|
||||
};
|
||||
91
ProjectSourceCode/node_modules/formidable/node_modules/qs/package.json
generated
vendored
Normal file
91
ProjectSourceCode/node_modules/formidable/node_modules/qs/package.json
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
{
|
||||
"name": "qs",
|
||||
"description": "A querystring parser that supports nesting and arrays, with a depth limit",
|
||||
"homepage": "https://github.com/ljharb/qs",
|
||||
"version": "6.12.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/ljharb/qs.git"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
},
|
||||
"main": "lib/index.js",
|
||||
"sideEffects": false,
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Jordan Harband",
|
||||
"email": "ljharb@gmail.com",
|
||||
"url": "http://ljharb.codes"
|
||||
}
|
||||
],
|
||||
"keywords": [
|
||||
"querystring",
|
||||
"qs",
|
||||
"query",
|
||||
"url",
|
||||
"parse",
|
||||
"stringify"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=0.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"side-channel": "^1.0.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@browserify/envify": "^6.0.0",
|
||||
"@browserify/uglifyify": "^6.0.0",
|
||||
"@ljharb/eslint-config": "^21.1.0",
|
||||
"aud": "^2.0.4",
|
||||
"browserify": "^16.5.2",
|
||||
"bundle-collapser": "^1.4.0",
|
||||
"common-shakeify": "~1.0.0",
|
||||
"eclint": "^2.8.1",
|
||||
"es-value-fixtures": "^1.4.2",
|
||||
"eslint": "=8.8.0",
|
||||
"evalmd": "^0.0.19",
|
||||
"for-each": "^0.3.3",
|
||||
"glob": "=10.3.7",
|
||||
"has-override-mistake": "^1.0.1",
|
||||
"has-property-descriptors": "^1.0.2",
|
||||
"has-symbols": "^1.0.3",
|
||||
"iconv-lite": "^0.5.1",
|
||||
"in-publish": "^2.0.1",
|
||||
"jackspeak": "=2.1.1",
|
||||
"mkdirp": "^0.5.5",
|
||||
"mock-property": "^1.0.3",
|
||||
"module-deps": "^6.2.3",
|
||||
"npmignore": "^0.3.1",
|
||||
"nyc": "^10.3.2",
|
||||
"object-inspect": "^1.13.1",
|
||||
"qs-iconv": "^1.0.4",
|
||||
"safe-publish-latest": "^2.0.0",
|
||||
"safer-buffer": "^2.1.2",
|
||||
"tape": "^5.7.5",
|
||||
"unassertify": "^3.0.1"
|
||||
},
|
||||
"scripts": {
|
||||
"prepack": "npmignore --auto --commentLines=autogenerated && npm run dist",
|
||||
"prepublishOnly": "safe-publish-latest",
|
||||
"prepublish": "not-in-publish || npm run prepublishOnly",
|
||||
"pretest": "npm run --silent readme && npm run --silent lint",
|
||||
"test": "npm run tests-only",
|
||||
"tests-only": "nyc tape 'test/**/*.js'",
|
||||
"posttest": "aud --production",
|
||||
"readme": "evalmd README.md",
|
||||
"postlint": "eclint check $(git ls-files | xargs find 2> /dev/null | grep -vE 'node_modules|\\.git' | grep -v dist/)",
|
||||
"lint": "eslint --ext=js,mjs .",
|
||||
"dist": "mkdirp dist && browserify --standalone Qs -g unassertify -g @browserify/envify -g [@browserify/uglifyify --mangle.keep_fnames --compress.keep_fnames --format.indent_level=1 --compress.arrows=false --compress.passes=4 --compress.typeofs=false] -p common-shakeify -p bundle-collapser/plugin lib/index.js > dist/qs.js"
|
||||
},
|
||||
"license": "BSD-3-Clause",
|
||||
"publishConfig": {
|
||||
"ignore": [
|
||||
"!dist/*",
|
||||
"bower.json",
|
||||
"component.json",
|
||||
".github/workflows",
|
||||
"logos"
|
||||
]
|
||||
}
|
||||
}
|
||||
267
ProjectSourceCode/node_modules/formidable/node_modules/qs/test/empty-keys-cases.js
generated
vendored
Normal file
267
ProjectSourceCode/node_modules/formidable/node_modules/qs/test/empty-keys-cases.js
generated
vendored
Normal file
@@ -0,0 +1,267 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
emptyTestCases: [
|
||||
{
|
||||
input: '&',
|
||||
withEmptyKeys: {},
|
||||
stringifyOutput: {
|
||||
brackets: '',
|
||||
indices: '',
|
||||
repeat: ''
|
||||
},
|
||||
noEmptyKeys: {}
|
||||
},
|
||||
{
|
||||
input: '&&',
|
||||
withEmptyKeys: {},
|
||||
stringifyOutput: {
|
||||
brackets: '',
|
||||
indices: '',
|
||||
repeat: ''
|
||||
},
|
||||
noEmptyKeys: {}
|
||||
},
|
||||
{
|
||||
input: '&=',
|
||||
withEmptyKeys: { '': '' },
|
||||
stringifyOutput: {
|
||||
brackets: '=',
|
||||
indices: '=',
|
||||
repeat: '='
|
||||
},
|
||||
noEmptyKeys: {}
|
||||
},
|
||||
{
|
||||
input: '&=&',
|
||||
withEmptyKeys: { '': '' },
|
||||
stringifyOutput: {
|
||||
brackets: '=',
|
||||
indices: '=',
|
||||
repeat: '='
|
||||
},
|
||||
noEmptyKeys: {}
|
||||
},
|
||||
{
|
||||
input: '&=&=',
|
||||
withEmptyKeys: { '': ['', ''] },
|
||||
stringifyOutput: {
|
||||
brackets: '[]=&[]=',
|
||||
indices: '[0]=&[1]=',
|
||||
repeat: '=&='
|
||||
},
|
||||
noEmptyKeys: {}
|
||||
},
|
||||
{
|
||||
input: '&=&=&',
|
||||
withEmptyKeys: { '': ['', ''] },
|
||||
stringifyOutput: {
|
||||
brackets: '[]=&[]=',
|
||||
indices: '[0]=&[1]=',
|
||||
repeat: '=&='
|
||||
},
|
||||
noEmptyKeys: {}
|
||||
},
|
||||
{
|
||||
input: '=',
|
||||
withEmptyKeys: { '': '' },
|
||||
noEmptyKeys: {},
|
||||
stringifyOutput: {
|
||||
brackets: '=',
|
||||
indices: '=',
|
||||
repeat: '='
|
||||
}
|
||||
},
|
||||
{
|
||||
input: '=&',
|
||||
withEmptyKeys: { '': '' },
|
||||
stringifyOutput: {
|
||||
brackets: '=',
|
||||
indices: '=',
|
||||
repeat: '='
|
||||
},
|
||||
noEmptyKeys: {}
|
||||
},
|
||||
{
|
||||
input: '=&&&',
|
||||
withEmptyKeys: { '': '' },
|
||||
stringifyOutput: {
|
||||
brackets: '=',
|
||||
indices: '=',
|
||||
repeat: '='
|
||||
},
|
||||
noEmptyKeys: {}
|
||||
},
|
||||
{
|
||||
input: '=&=&=&',
|
||||
withEmptyKeys: { '': ['', '', ''] },
|
||||
stringifyOutput: {
|
||||
brackets: '[]=&[]=&[]=',
|
||||
indices: '[0]=&[1]=&[2]=',
|
||||
repeat: '=&=&='
|
||||
},
|
||||
noEmptyKeys: {}
|
||||
},
|
||||
{
|
||||
input: '=&a[]=b&a[1]=c',
|
||||
withEmptyKeys: { '': '', a: ['b', 'c'] },
|
||||
stringifyOutput: {
|
||||
brackets: '=&a[]=b&a[]=c',
|
||||
indices: '=&a[0]=b&a[1]=c',
|
||||
repeat: '=&a=b&a=c'
|
||||
},
|
||||
noEmptyKeys: { a: ['b', 'c'] }
|
||||
},
|
||||
{
|
||||
input: '=a',
|
||||
withEmptyKeys: { '': 'a' },
|
||||
noEmptyKeys: {},
|
||||
stringifyOutput: {
|
||||
brackets: '=a',
|
||||
indices: '=a',
|
||||
repeat: '=a'
|
||||
}
|
||||
},
|
||||
{
|
||||
input: 'a==a',
|
||||
withEmptyKeys: { a: '=a' },
|
||||
noEmptyKeys: { a: '=a' },
|
||||
stringifyOutput: {
|
||||
brackets: 'a==a',
|
||||
indices: 'a==a',
|
||||
repeat: 'a==a'
|
||||
}
|
||||
},
|
||||
{
|
||||
input: '=&a[]=b',
|
||||
withEmptyKeys: { '': '', a: ['b'] },
|
||||
stringifyOutput: {
|
||||
brackets: '=&a[]=b',
|
||||
indices: '=&a[0]=b',
|
||||
repeat: '=&a=b'
|
||||
},
|
||||
noEmptyKeys: { a: ['b'] }
|
||||
},
|
||||
{
|
||||
input: '=&a[]=b&a[]=c&a[2]=d',
|
||||
withEmptyKeys: { '': '', a: ['b', 'c', 'd'] },
|
||||
stringifyOutput: {
|
||||
brackets: '=&a[]=b&a[]=c&a[]=d',
|
||||
indices: '=&a[0]=b&a[1]=c&a[2]=d',
|
||||
repeat: '=&a=b&a=c&a=d'
|
||||
},
|
||||
noEmptyKeys: { a: ['b', 'c', 'd'] }
|
||||
},
|
||||
{
|
||||
input: '=a&=b',
|
||||
withEmptyKeys: { '': ['a', 'b'] },
|
||||
stringifyOutput: {
|
||||
brackets: '[]=a&[]=b',
|
||||
indices: '[0]=a&[1]=b',
|
||||
repeat: '=a&=b'
|
||||
},
|
||||
noEmptyKeys: {}
|
||||
},
|
||||
{
|
||||
input: '=a&foo=b',
|
||||
withEmptyKeys: { '': 'a', foo: 'b' },
|
||||
noEmptyKeys: { foo: 'b' },
|
||||
stringifyOutput: {
|
||||
brackets: '=a&foo=b',
|
||||
indices: '=a&foo=b',
|
||||
repeat: '=a&foo=b'
|
||||
}
|
||||
},
|
||||
{
|
||||
input: 'a[]=b&a=c&=',
|
||||
withEmptyKeys: { '': '', a: ['b', 'c'] },
|
||||
stringifyOutput: {
|
||||
brackets: '=&a[]=b&a[]=c',
|
||||
indices: '=&a[0]=b&a[1]=c',
|
||||
repeat: '=&a=b&a=c'
|
||||
},
|
||||
noEmptyKeys: { a: ['b', 'c'] }
|
||||
},
|
||||
{
|
||||
input: 'a[]=b&a=c&=',
|
||||
withEmptyKeys: { '': '', a: ['b', 'c'] },
|
||||
stringifyOutput: {
|
||||
brackets: '=&a[]=b&a[]=c',
|
||||
indices: '=&a[0]=b&a[1]=c',
|
||||
repeat: '=&a=b&a=c'
|
||||
},
|
||||
noEmptyKeys: { a: ['b', 'c'] }
|
||||
},
|
||||
{
|
||||
input: 'a[0]=b&a=c&=',
|
||||
withEmptyKeys: { '': '', a: ['b', 'c'] },
|
||||
stringifyOutput: {
|
||||
brackets: '=&a[]=b&a[]=c',
|
||||
indices: '=&a[0]=b&a[1]=c',
|
||||
repeat: '=&a=b&a=c'
|
||||
},
|
||||
noEmptyKeys: { a: ['b', 'c'] }
|
||||
},
|
||||
{
|
||||
input: 'a=b&a[]=c&=',
|
||||
withEmptyKeys: { '': '', a: ['b', 'c'] },
|
||||
stringifyOutput: {
|
||||
brackets: '=&a[]=b&a[]=c',
|
||||
indices: '=&a[0]=b&a[1]=c',
|
||||
repeat: '=&a=b&a=c'
|
||||
},
|
||||
noEmptyKeys: { a: ['b', 'c'] }
|
||||
},
|
||||
{
|
||||
input: 'a=b&a[0]=c&=',
|
||||
withEmptyKeys: { '': '', a: ['b', 'c'] },
|
||||
stringifyOutput: {
|
||||
brackets: '=&a[]=b&a[]=c',
|
||||
indices: '=&a[0]=b&a[1]=c',
|
||||
repeat: '=&a=b&a=c'
|
||||
},
|
||||
noEmptyKeys: { a: ['b', 'c'] }
|
||||
},
|
||||
{
|
||||
input: '[]=a&[]=b& []=1',
|
||||
withEmptyKeys: { '': ['a', 'b'], ' ': ['1'] },
|
||||
stringifyOutput: {
|
||||
brackets: '[]=a&[]=b& []=1',
|
||||
indices: '[0]=a&[1]=b& [0]=1',
|
||||
repeat: '=a&=b& =1'
|
||||
},
|
||||
noEmptyKeys: { 0: 'a', 1: 'b', ' ': ['1'] }
|
||||
},
|
||||
{
|
||||
input: '[0]=a&[1]=b&a[0]=1&a[1]=2',
|
||||
withEmptyKeys: { '': ['a', 'b'], a: ['1', '2'] },
|
||||
noEmptyKeys: { 0: 'a', 1: 'b', a: ['1', '2'] },
|
||||
stringifyOutput: {
|
||||
brackets: '[]=a&[]=b&a[]=1&a[]=2',
|
||||
indices: '[0]=a&[1]=b&a[0]=1&a[1]=2',
|
||||
repeat: '=a&=b&a=1&a=2'
|
||||
}
|
||||
},
|
||||
{
|
||||
input: '[deep]=a&[deep]=2',
|
||||
withEmptyKeys: { '': { deep: ['a', '2'] }
|
||||
},
|
||||
stringifyOutput: {
|
||||
brackets: '[deep][]=a&[deep][]=2',
|
||||
indices: '[deep][0]=a&[deep][1]=2',
|
||||
repeat: '[deep]=a&[deep]=2'
|
||||
},
|
||||
noEmptyKeys: { deep: ['a', '2'] }
|
||||
},
|
||||
{
|
||||
input: '%5B0%5D=a&%5B1%5D=b',
|
||||
withEmptyKeys: { '': ['a', 'b'] },
|
||||
stringifyOutput: {
|
||||
brackets: '[]=a&[]=b',
|
||||
indices: '[0]=a&[1]=b',
|
||||
repeat: '=a&=b'
|
||||
},
|
||||
noEmptyKeys: { 0: 'a', 1: 'b' }
|
||||
}
|
||||
]
|
||||
};
|
||||
1047
ProjectSourceCode/node_modules/formidable/node_modules/qs/test/parse.js
generated
vendored
Normal file
1047
ProjectSourceCode/node_modules/formidable/node_modules/qs/test/parse.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1255
ProjectSourceCode/node_modules/formidable/node_modules/qs/test/stringify.js
generated
vendored
Normal file
1255
ProjectSourceCode/node_modules/formidable/node_modules/qs/test/stringify.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
136
ProjectSourceCode/node_modules/formidable/node_modules/qs/test/utils.js
generated
vendored
Normal file
136
ProjectSourceCode/node_modules/formidable/node_modules/qs/test/utils.js
generated
vendored
Normal file
@@ -0,0 +1,136 @@
|
||||
'use strict';
|
||||
|
||||
var test = require('tape');
|
||||
var inspect = require('object-inspect');
|
||||
var SaferBuffer = require('safer-buffer').Buffer;
|
||||
var forEach = require('for-each');
|
||||
var utils = require('../lib/utils');
|
||||
|
||||
test('merge()', function (t) {
|
||||
t.deepEqual(utils.merge(null, true), [null, true], 'merges true into null');
|
||||
|
||||
t.deepEqual(utils.merge(null, [42]), [null, 42], 'merges null into an array');
|
||||
|
||||
t.deepEqual(utils.merge({ a: 'b' }, { a: 'c' }), { a: ['b', 'c'] }, 'merges two objects with the same key');
|
||||
|
||||
var oneMerged = utils.merge({ foo: 'bar' }, { foo: { first: '123' } });
|
||||
t.deepEqual(oneMerged, { foo: ['bar', { first: '123' }] }, 'merges a standalone and an object into an array');
|
||||
|
||||
var twoMerged = utils.merge({ foo: ['bar', { first: '123' }] }, { foo: { second: '456' } });
|
||||
t.deepEqual(twoMerged, { foo: { 0: 'bar', 1: { first: '123' }, second: '456' } }, 'merges a standalone and two objects into an array');
|
||||
|
||||
var sandwiched = utils.merge({ foo: ['bar', { first: '123', second: '456' }] }, { foo: 'baz' });
|
||||
t.deepEqual(sandwiched, { foo: ['bar', { first: '123', second: '456' }, 'baz'] }, 'merges an object sandwiched by two standalones into an array');
|
||||
|
||||
var nestedArrays = utils.merge({ foo: ['baz'] }, { foo: ['bar', 'xyzzy'] });
|
||||
t.deepEqual(nestedArrays, { foo: ['baz', 'bar', 'xyzzy'] });
|
||||
|
||||
var noOptionsNonObjectSource = utils.merge({ foo: 'baz' }, 'bar');
|
||||
t.deepEqual(noOptionsNonObjectSource, { foo: 'baz', bar: true });
|
||||
|
||||
t.test(
|
||||
'avoids invoking array setters unnecessarily',
|
||||
{ skip: typeof Object.defineProperty !== 'function' },
|
||||
function (st) {
|
||||
var setCount = 0;
|
||||
var getCount = 0;
|
||||
var observed = [];
|
||||
Object.defineProperty(observed, 0, {
|
||||
get: function () {
|
||||
getCount += 1;
|
||||
return { bar: 'baz' };
|
||||
},
|
||||
set: function () { setCount += 1; }
|
||||
});
|
||||
utils.merge(observed, [null]);
|
||||
st.equal(setCount, 0);
|
||||
st.equal(getCount, 1);
|
||||
observed[0] = observed[0]; // eslint-disable-line no-self-assign
|
||||
st.equal(setCount, 1);
|
||||
st.equal(getCount, 2);
|
||||
st.end();
|
||||
}
|
||||
);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('assign()', function (t) {
|
||||
var target = { a: 1, b: 2 };
|
||||
var source = { b: 3, c: 4 };
|
||||
var result = utils.assign(target, source);
|
||||
|
||||
t.equal(result, target, 'returns the target');
|
||||
t.deepEqual(target, { a: 1, b: 3, c: 4 }, 'target and source are merged');
|
||||
t.deepEqual(source, { b: 3, c: 4 }, 'source is untouched');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('combine()', function (t) {
|
||||
t.test('both arrays', function (st) {
|
||||
var a = [1];
|
||||
var b = [2];
|
||||
var combined = utils.combine(a, b);
|
||||
|
||||
st.deepEqual(a, [1], 'a is not mutated');
|
||||
st.deepEqual(b, [2], 'b is not mutated');
|
||||
st.notEqual(a, combined, 'a !== combined');
|
||||
st.notEqual(b, combined, 'b !== combined');
|
||||
st.deepEqual(combined, [1, 2], 'combined is a + b');
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('one array, one non-array', function (st) {
|
||||
var aN = 1;
|
||||
var a = [aN];
|
||||
var bN = 2;
|
||||
var b = [bN];
|
||||
|
||||
var combinedAnB = utils.combine(aN, b);
|
||||
st.deepEqual(b, [bN], 'b is not mutated');
|
||||
st.notEqual(aN, combinedAnB, 'aN + b !== aN');
|
||||
st.notEqual(a, combinedAnB, 'aN + b !== a');
|
||||
st.notEqual(bN, combinedAnB, 'aN + b !== bN');
|
||||
st.notEqual(b, combinedAnB, 'aN + b !== b');
|
||||
st.deepEqual([1, 2], combinedAnB, 'first argument is array-wrapped when not an array');
|
||||
|
||||
var combinedABn = utils.combine(a, bN);
|
||||
st.deepEqual(a, [aN], 'a is not mutated');
|
||||
st.notEqual(aN, combinedABn, 'a + bN !== aN');
|
||||
st.notEqual(a, combinedABn, 'a + bN !== a');
|
||||
st.notEqual(bN, combinedABn, 'a + bN !== bN');
|
||||
st.notEqual(b, combinedABn, 'a + bN !== b');
|
||||
st.deepEqual([1, 2], combinedABn, 'second argument is array-wrapped when not an array');
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('neither is an array', function (st) {
|
||||
var combined = utils.combine(1, 2);
|
||||
st.notEqual(1, combined, '1 + 2 !== 1');
|
||||
st.notEqual(2, combined, '1 + 2 !== 2');
|
||||
st.deepEqual([1, 2], combined, 'both arguments are array-wrapped when not an array');
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('isBuffer()', function (t) {
|
||||
forEach([null, undefined, true, false, '', 'abc', 42, 0, NaN, {}, [], function () {}, /a/g], function (x) {
|
||||
t.equal(utils.isBuffer(x), false, inspect(x) + ' is not a buffer');
|
||||
});
|
||||
|
||||
var fakeBuffer = { constructor: Buffer };
|
||||
t.equal(utils.isBuffer(fakeBuffer), false, 'fake buffer is not a buffer');
|
||||
|
||||
var saferBuffer = SaferBuffer.from('abc');
|
||||
t.equal(utils.isBuffer(saferBuffer), true, 'SaferBuffer instance is a buffer');
|
||||
|
||||
var buffer = Buffer.from && Buffer.alloc ? Buffer.from('abc') : new Buffer('abc');
|
||||
t.equal(utils.isBuffer(buffer), true, 'real Buffer instance is a buffer');
|
||||
t.end();
|
||||
});
|
||||
98
ProjectSourceCode/node_modules/formidable/package.json
generated
vendored
Normal file
98
ProjectSourceCode/node_modules/formidable/package.json
generated
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
{
|
||||
"name": "formidable",
|
||||
"version": "2.1.2",
|
||||
"license": "MIT",
|
||||
"description": "A node.js module for parsing form data, especially file uploads.",
|
||||
"homepage": "https://github.com/node-formidable/formidable",
|
||||
"funding": "https://ko-fi.com/tunnckoCore/commissions",
|
||||
"repository": "node-formidable/formidable",
|
||||
"main": "./src/index.js",
|
||||
"files": [
|
||||
"src"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"tag": "v2-latest"
|
||||
},
|
||||
"scripts": {
|
||||
"bench": "node benchmark",
|
||||
"fmt": "yarn run fmt:prepare '**/*'",
|
||||
"fmt:prepare": "prettier --write",
|
||||
"lint": "yarn run lint:prepare .",
|
||||
"lint:prepare": "eslint --cache --fix --quiet --format codeframe",
|
||||
"reinstall": "del-cli ./node_modules ./yarn.lock",
|
||||
"postreinstall": "yarn setup",
|
||||
"setup": "yarn",
|
||||
"pretest": "del-cli ./test/tmp && make-dir ./test/tmp",
|
||||
"test": "jest --coverage",
|
||||
"pretest:ci": "yarn run pretest",
|
||||
"test:ci": "nyc jest --coverage",
|
||||
"test:jest": "jest --coverage"
|
||||
},
|
||||
"dependencies": {
|
||||
"dezalgo": "^1.0.4",
|
||||
"hexoid": "^1.0.0",
|
||||
"once": "^1.4.0",
|
||||
"qs": "^6.11.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "8.3.5",
|
||||
"@commitlint/config-conventional": "8.3.4",
|
||||
"@tunnckocore/prettier-config": "1.3.8",
|
||||
"del-cli": "3.0.0",
|
||||
"eslint": "6.8.0",
|
||||
"eslint-config-airbnb-base": "14.1.0",
|
||||
"eslint-config-prettier": "6.11.0",
|
||||
"eslint-plugin-import": "2.20.2",
|
||||
"eslint-plugin-prettier": "3.1.3",
|
||||
"express": "4.17.1",
|
||||
"husky": "4.2.5",
|
||||
"jest": "25.4.0",
|
||||
"koa": "2.11.0",
|
||||
"lint-staged": "10.2.7",
|
||||
"make-dir-cli": "2.0.0",
|
||||
"nyc": "15.0.1",
|
||||
"prettier": "2.0.5",
|
||||
"prettier-plugin-pkgjson": "0.2.8",
|
||||
"request": "2.88.2",
|
||||
"supertest": "4.0.2"
|
||||
},
|
||||
"jest": {
|
||||
"verbose": true
|
||||
},
|
||||
"keywords": [
|
||||
"multipart",
|
||||
"form",
|
||||
"data",
|
||||
"querystring",
|
||||
"www",
|
||||
"json",
|
||||
"ulpoad",
|
||||
"file"
|
||||
],
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"pre-commit": "git status --porcelain && yarn lint-staged",
|
||||
"commit-msg": "yarn commitlint -E HUSKY_GIT_PARAMS"
|
||||
}
|
||||
},
|
||||
"commitlint": {
|
||||
"extends": [
|
||||
"@commitlint/config-conventional"
|
||||
]
|
||||
},
|
||||
"lint-staged": {
|
||||
"!*.{js,jsx,ts,tsx}": [
|
||||
"yarn run fmt:prepare"
|
||||
],
|
||||
"*.{js,jsx,ts,tsx}": [
|
||||
"yarn run lint"
|
||||
]
|
||||
},
|
||||
"renovate": {
|
||||
"extends": [
|
||||
"@tunnckocore",
|
||||
":pinAllExceptPeerDependencies"
|
||||
]
|
||||
}
|
||||
}
|
||||
617
ProjectSourceCode/node_modules/formidable/src/Formidable.js
generated
vendored
Normal file
617
ProjectSourceCode/node_modules/formidable/src/Formidable.js
generated
vendored
Normal file
@@ -0,0 +1,617 @@
|
||||
/* eslint-disable class-methods-use-this */
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
|
||||
'use strict';
|
||||
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const hexoid = require('hexoid');
|
||||
const once = require('once');
|
||||
const dezalgo = require('dezalgo');
|
||||
const { EventEmitter } = require('events');
|
||||
const { StringDecoder } = require('string_decoder');
|
||||
const qs = require('qs');
|
||||
|
||||
const toHexoId = hexoid(25);
|
||||
const DEFAULT_OPTIONS = {
|
||||
maxFields: 1000,
|
||||
maxFieldsSize: 20 * 1024 * 1024,
|
||||
maxFileSize: 200 * 1024 * 1024,
|
||||
minFileSize: 1,
|
||||
allowEmptyFiles: true,
|
||||
keepExtensions: false,
|
||||
encoding: 'utf-8',
|
||||
hashAlgorithm: false,
|
||||
uploadDir: os.tmpdir(),
|
||||
multiples: false,
|
||||
enabledPlugins: ['octetstream', 'querystring', 'multipart', 'json'],
|
||||
fileWriteStreamHandler: null,
|
||||
defaultInvalidName: 'invalid-name',
|
||||
filter: function () {
|
||||
return true;
|
||||
},
|
||||
};
|
||||
|
||||
const PersistentFile = require('./PersistentFile');
|
||||
const VolatileFile = require('./VolatileFile');
|
||||
const DummyParser = require('./parsers/Dummy');
|
||||
const MultipartParser = require('./parsers/Multipart');
|
||||
const errors = require('./FormidableError.js');
|
||||
|
||||
const { FormidableError } = errors;
|
||||
|
||||
function hasOwnProp(obj, key) {
|
||||
return Object.prototype.hasOwnProperty.call(obj, key);
|
||||
}
|
||||
|
||||
class IncomingForm extends EventEmitter {
|
||||
constructor(options = {}) {
|
||||
super();
|
||||
|
||||
this.options = { ...DEFAULT_OPTIONS, ...options };
|
||||
|
||||
const dir = path.resolve(
|
||||
this.options.uploadDir || this.options.uploaddir || os.tmpdir(),
|
||||
);
|
||||
|
||||
this.uploaddir = dir;
|
||||
this.uploadDir = dir;
|
||||
|
||||
// initialize with null
|
||||
[
|
||||
'error',
|
||||
'headers',
|
||||
'type',
|
||||
'bytesExpected',
|
||||
'bytesReceived',
|
||||
'_parser',
|
||||
].forEach((key) => {
|
||||
this[key] = null;
|
||||
});
|
||||
|
||||
this._setUpRename();
|
||||
|
||||
this._flushing = 0;
|
||||
this._fieldsSize = 0;
|
||||
this._fileSize = 0;
|
||||
this._plugins = [];
|
||||
this.openedFiles = [];
|
||||
|
||||
this.options.enabledPlugins = []
|
||||
.concat(this.options.enabledPlugins)
|
||||
.filter(Boolean);
|
||||
|
||||
if (this.options.enabledPlugins.length === 0) {
|
||||
throw new FormidableError(
|
||||
'expect at least 1 enabled builtin plugin, see options.enabledPlugins',
|
||||
errors.missingPlugin,
|
||||
);
|
||||
}
|
||||
|
||||
this.options.enabledPlugins.forEach((pluginName) => {
|
||||
const plgName = pluginName.toLowerCase();
|
||||
// eslint-disable-next-line import/no-dynamic-require, global-require
|
||||
this.use(require(path.join(__dirname, 'plugins', `${plgName}.js`)));
|
||||
});
|
||||
|
||||
this._setUpMaxFields();
|
||||
}
|
||||
|
||||
use(plugin) {
|
||||
if (typeof plugin !== 'function') {
|
||||
throw new FormidableError(
|
||||
'.use: expect `plugin` to be a function',
|
||||
errors.pluginFunction,
|
||||
);
|
||||
}
|
||||
this._plugins.push(plugin.bind(this));
|
||||
return this;
|
||||
}
|
||||
|
||||
parse(req, cb) {
|
||||
this.pause = () => {
|
||||
try {
|
||||
req.pause();
|
||||
} catch (err) {
|
||||
// the stream was destroyed
|
||||
if (!this.ended) {
|
||||
// before it was completed, crash & burn
|
||||
this._error(err);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
this.resume = () => {
|
||||
try {
|
||||
req.resume();
|
||||
} catch (err) {
|
||||
// the stream was destroyed
|
||||
if (!this.ended) {
|
||||
// before it was completed, crash & burn
|
||||
this._error(err);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
// Setup callback first, so we don't miss anything from data events emitted immediately.
|
||||
if (cb) {
|
||||
const callback = once(dezalgo(cb));
|
||||
const fields = {};
|
||||
let mockFields = '';
|
||||
const files = {};
|
||||
|
||||
this.on('field', (name, value) => {
|
||||
if (
|
||||
this.options.multiples &&
|
||||
(this.type === 'multipart' || this.type === 'urlencoded')
|
||||
) {
|
||||
const mObj = { [name]: value };
|
||||
mockFields = mockFields
|
||||
? `${mockFields}&${qs.stringify(mObj)}`
|
||||
: `${qs.stringify(mObj)}`;
|
||||
} else {
|
||||
fields[name] = value;
|
||||
}
|
||||
});
|
||||
this.on('file', (name, file) => {
|
||||
// TODO: too much nesting
|
||||
if (this.options.multiples) {
|
||||
if (hasOwnProp(files, name)) {
|
||||
if (!Array.isArray(files[name])) {
|
||||
files[name] = [files[name]];
|
||||
}
|
||||
files[name].push(file);
|
||||
} else {
|
||||
files[name] = file;
|
||||
}
|
||||
} else {
|
||||
files[name] = file;
|
||||
}
|
||||
});
|
||||
this.on('error', (err) => {
|
||||
callback(err, fields, files);
|
||||
});
|
||||
this.on('end', () => {
|
||||
if (this.options.multiples) {
|
||||
Object.assign(fields, qs.parse(mockFields));
|
||||
}
|
||||
callback(null, fields, files);
|
||||
});
|
||||
}
|
||||
|
||||
// Parse headers and setup the parser, ready to start listening for data.
|
||||
this.writeHeaders(req.headers);
|
||||
|
||||
// Start listening for data.
|
||||
req
|
||||
.on('error', (err) => {
|
||||
this._error(err);
|
||||
})
|
||||
.on('aborted', () => {
|
||||
this.emit('aborted');
|
||||
this._error(new FormidableError('Request aborted', errors.aborted));
|
||||
})
|
||||
.on('data', (buffer) => {
|
||||
try {
|
||||
this.write(buffer);
|
||||
} catch (err) {
|
||||
this._error(err);
|
||||
}
|
||||
})
|
||||
.on('end', () => {
|
||||
if (this.error) {
|
||||
return;
|
||||
}
|
||||
if (this._parser) {
|
||||
this._parser.end();
|
||||
}
|
||||
this._maybeEnd();
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
writeHeaders(headers) {
|
||||
this.headers = headers;
|
||||
this._parseContentLength();
|
||||
this._parseContentType();
|
||||
|
||||
if (!this._parser) {
|
||||
this._error(
|
||||
new FormidableError(
|
||||
'no parser found',
|
||||
errors.noParser,
|
||||
415, // Unsupported Media Type
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
this._parser.once('error', (error) => {
|
||||
this._error(error);
|
||||
});
|
||||
}
|
||||
|
||||
write(buffer) {
|
||||
if (this.error) {
|
||||
return null;
|
||||
}
|
||||
if (!this._parser) {
|
||||
this._error(
|
||||
new FormidableError('uninitialized parser', errors.uninitializedParser),
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
this.bytesReceived += buffer.length;
|
||||
this.emit('progress', this.bytesReceived, this.bytesExpected);
|
||||
|
||||
this._parser.write(buffer);
|
||||
|
||||
return this.bytesReceived;
|
||||
}
|
||||
|
||||
pause() {
|
||||
// this does nothing, unless overwritten in IncomingForm.parse
|
||||
return false;
|
||||
}
|
||||
|
||||
resume() {
|
||||
// this does nothing, unless overwritten in IncomingForm.parse
|
||||
return false;
|
||||
}
|
||||
|
||||
onPart(part) {
|
||||
// this method can be overwritten by the user
|
||||
this._handlePart(part);
|
||||
}
|
||||
|
||||
_handlePart(part) {
|
||||
if (part.originalFilename && typeof part.originalFilename !== 'string') {
|
||||
this._error(
|
||||
new FormidableError(
|
||||
`the part.originalFilename should be string when it exists`,
|
||||
errors.filenameNotString,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// This MUST check exactly for undefined. You can not change it to !part.originalFilename.
|
||||
|
||||
// todo: uncomment when switch tests to Jest
|
||||
// console.log(part);
|
||||
|
||||
// ? NOTE(@tunnckocore): no it can be any falsey value, it most probably depends on what's returned
|
||||
// from somewhere else. Where recently I changed the return statements
|
||||
// and such thing because code style
|
||||
// ? NOTE(@tunnckocore): or even better, if there is no mimetype, then it's for sure a field
|
||||
// ? NOTE(@tunnckocore): originalFilename is an empty string when a field?
|
||||
if (!part.mimetype) {
|
||||
let value = '';
|
||||
const decoder = new StringDecoder(
|
||||
part.transferEncoding || this.options.encoding,
|
||||
);
|
||||
|
||||
part.on('data', (buffer) => {
|
||||
this._fieldsSize += buffer.length;
|
||||
if (this._fieldsSize > this.options.maxFieldsSize) {
|
||||
this._error(
|
||||
new FormidableError(
|
||||
`options.maxFieldsSize (${this.options.maxFieldsSize} bytes) exceeded, received ${this._fieldsSize} bytes of field data`,
|
||||
errors.maxFieldsSizeExceeded,
|
||||
413, // Payload Too Large
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
value += decoder.write(buffer);
|
||||
});
|
||||
|
||||
part.on('end', () => {
|
||||
this.emit('field', part.name, value);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.options.filter(part)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._flushing += 1;
|
||||
|
||||
const newFilename = this._getNewName(part);
|
||||
const filepath = this._joinDirectoryName(newFilename);
|
||||
const file = this._newFile({
|
||||
newFilename,
|
||||
filepath,
|
||||
originalFilename: part.originalFilename,
|
||||
mimetype: part.mimetype,
|
||||
});
|
||||
file.on('error', (err) => {
|
||||
this._error(err);
|
||||
});
|
||||
this.emit('fileBegin', part.name, file);
|
||||
|
||||
file.open();
|
||||
this.openedFiles.push(file);
|
||||
|
||||
part.on('data', (buffer) => {
|
||||
this._fileSize += buffer.length;
|
||||
if (this._fileSize < this.options.minFileSize) {
|
||||
this._error(
|
||||
new FormidableError(
|
||||
`options.minFileSize (${this.options.minFileSize} bytes) inferior, received ${this._fileSize} bytes of file data`,
|
||||
errors.smallerThanMinFileSize,
|
||||
400,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (this._fileSize > this.options.maxFileSize) {
|
||||
this._error(
|
||||
new FormidableError(
|
||||
`options.maxFileSize (${this.options.maxFileSize} bytes) exceeded, received ${this._fileSize} bytes of file data`,
|
||||
errors.biggerThanMaxFileSize,
|
||||
413,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (buffer.length === 0) {
|
||||
return;
|
||||
}
|
||||
this.pause();
|
||||
file.write(buffer, () => {
|
||||
this.resume();
|
||||
});
|
||||
});
|
||||
|
||||
part.on('end', () => {
|
||||
if (!this.options.allowEmptyFiles && this._fileSize === 0) {
|
||||
this._error(
|
||||
new FormidableError(
|
||||
`options.allowEmptyFiles is false, file size should be greather than 0`,
|
||||
errors.noEmptyFiles,
|
||||
400,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
file.end(() => {
|
||||
this._flushing -= 1;
|
||||
this.emit('file', part.name, file);
|
||||
this._maybeEnd();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// eslint-disable-next-line max-statements
|
||||
_parseContentType() {
|
||||
if (this.bytesExpected === 0) {
|
||||
this._parser = new DummyParser(this, this.options);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.headers['content-type']) {
|
||||
this._error(
|
||||
new FormidableError(
|
||||
'bad content-type header, no content-type',
|
||||
errors.missingContentType,
|
||||
400,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const results = [];
|
||||
const _dummyParser = new DummyParser(this, this.options);
|
||||
|
||||
// eslint-disable-next-line no-plusplus
|
||||
for (let idx = 0; idx < this._plugins.length; idx++) {
|
||||
const plugin = this._plugins[idx];
|
||||
|
||||
let pluginReturn = null;
|
||||
|
||||
try {
|
||||
pluginReturn = plugin(this, this.options) || this;
|
||||
} catch (err) {
|
||||
// directly throw from the `form.parse` method;
|
||||
// there is no other better way, except a handle through options
|
||||
const error = new FormidableError(
|
||||
`plugin on index ${idx} failed with: ${err.message}`,
|
||||
errors.pluginFailed,
|
||||
500,
|
||||
);
|
||||
error.idx = idx;
|
||||
throw error;
|
||||
}
|
||||
|
||||
Object.assign(this, pluginReturn);
|
||||
|
||||
// todo: use Set/Map and pass plugin name instead of the `idx` index
|
||||
this.emit('plugin', idx, pluginReturn);
|
||||
results.push(pluginReturn);
|
||||
}
|
||||
|
||||
this.emit('pluginsResults', results);
|
||||
|
||||
// NOTE: probably not needed, because we check options.enabledPlugins in the constructor
|
||||
// if (results.length === 0 /* && results.length !== this._plugins.length */) {
|
||||
// this._error(
|
||||
// new Error(
|
||||
// `bad content-type header, unknown content-type: ${this.headers['content-type']}`,
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
}
|
||||
|
||||
_error(err, eventName = 'error') {
|
||||
// if (!err && this.error) {
|
||||
// this.emit('error', this.error);
|
||||
// return;
|
||||
// }
|
||||
if (this.error || this.ended) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.error = err;
|
||||
this.emit(eventName, err);
|
||||
|
||||
if (Array.isArray(this.openedFiles)) {
|
||||
this.openedFiles.forEach((file) => {
|
||||
file.destroy();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_parseContentLength() {
|
||||
this.bytesReceived = 0;
|
||||
if (this.headers['content-length']) {
|
||||
this.bytesExpected = parseInt(this.headers['content-length'], 10);
|
||||
} else if (this.headers['transfer-encoding'] === undefined) {
|
||||
this.bytesExpected = 0;
|
||||
}
|
||||
|
||||
if (this.bytesExpected !== null) {
|
||||
this.emit('progress', this.bytesReceived, this.bytesExpected);
|
||||
}
|
||||
}
|
||||
|
||||
_newParser() {
|
||||
return new MultipartParser(this.options);
|
||||
}
|
||||
|
||||
_newFile({ filepath, originalFilename, mimetype, newFilename }) {
|
||||
return this.options.fileWriteStreamHandler
|
||||
? new VolatileFile({
|
||||
newFilename,
|
||||
filepath,
|
||||
originalFilename,
|
||||
mimetype,
|
||||
createFileWriteStream: this.options.fileWriteStreamHandler,
|
||||
hashAlgorithm: this.options.hashAlgorithm,
|
||||
})
|
||||
: new PersistentFile({
|
||||
newFilename,
|
||||
filepath,
|
||||
originalFilename,
|
||||
mimetype,
|
||||
hashAlgorithm: this.options.hashAlgorithm,
|
||||
});
|
||||
}
|
||||
|
||||
_getFileName(headerValue) {
|
||||
// matches either a quoted-string or a token (RFC 2616 section 19.5.1)
|
||||
const m = headerValue.match(
|
||||
/\bfilename=("(.*?)"|([^()<>{}[\]@,;:"?=\s/\t]+))($|;\s)/i,
|
||||
);
|
||||
if (!m) return null;
|
||||
|
||||
const match = m[2] || m[3] || '';
|
||||
let originalFilename = match.substr(match.lastIndexOf('\\') + 1);
|
||||
originalFilename = originalFilename.replace(/%22/g, '"');
|
||||
originalFilename = originalFilename.replace(/&#([\d]{4});/g, (_, code) =>
|
||||
String.fromCharCode(code),
|
||||
);
|
||||
|
||||
return originalFilename;
|
||||
}
|
||||
|
||||
_getExtension(str) {
|
||||
if (!str) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const basename = path.basename(str);
|
||||
const firstDot = basename.indexOf('.');
|
||||
const lastDot = basename.lastIndexOf('.');
|
||||
const extname = path.extname(basename).replace(/(\.[a-z0-9]+).*/i, '$1');
|
||||
|
||||
if (firstDot === lastDot) {
|
||||
return extname;
|
||||
}
|
||||
|
||||
return basename.slice(firstDot, lastDot) + extname;
|
||||
}
|
||||
|
||||
|
||||
|
||||
_joinDirectoryName(name) {
|
||||
const newPath = path.join(this.uploadDir, name);
|
||||
|
||||
// prevent directory traversal attacks
|
||||
if (!newPath.startsWith(this.uploadDir)) {
|
||||
return path.join(this.uploadDir, this.options.defaultInvalidName);
|
||||
}
|
||||
|
||||
return newPath;
|
||||
}
|
||||
|
||||
_setUpRename() {
|
||||
const hasRename = typeof this.options.filename === 'function';
|
||||
if (hasRename) {
|
||||
this._getNewName = (part) => {
|
||||
let ext = '';
|
||||
let name = this.options.defaultInvalidName;
|
||||
if (part.originalFilename) {
|
||||
// can be null
|
||||
({ ext, name } = path.parse(part.originalFilename));
|
||||
if (this.options.keepExtensions !== true) {
|
||||
ext = '';
|
||||
}
|
||||
}
|
||||
return this.options.filename.call(this, name, ext, part, this);
|
||||
};
|
||||
} else {
|
||||
this._getNewName = (part) => {
|
||||
const name = toHexoId();
|
||||
|
||||
if (part && this.options.keepExtensions) {
|
||||
const originalFilename = typeof part === 'string' ? part : part.originalFilename;
|
||||
return `${name}${this._getExtension(originalFilename)}`;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_setUpMaxFields() {
|
||||
if (this.options.maxFields !== 0) {
|
||||
let fieldsCount = 0;
|
||||
this.on('field', () => {
|
||||
fieldsCount += 1;
|
||||
if (fieldsCount > this.options.maxFields) {
|
||||
this._error(
|
||||
new FormidableError(
|
||||
`options.maxFields (${this.options.maxFields}) exceeded`,
|
||||
errors.maxFieldsExceeded,
|
||||
413,
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_maybeEnd() {
|
||||
// console.log('ended', this.ended);
|
||||
// console.log('_flushing', this._flushing);
|
||||
// console.log('error', this.error);
|
||||
if (!this.ended || this._flushing || this.error) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.emit('end');
|
||||
}
|
||||
}
|
||||
|
||||
IncomingForm.DEFAULT_OPTIONS = DEFAULT_OPTIONS;
|
||||
module.exports = IncomingForm;
|
||||
45
ProjectSourceCode/node_modules/formidable/src/FormidableError.js
generated
vendored
Normal file
45
ProjectSourceCode/node_modules/formidable/src/FormidableError.js
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
/* eslint-disable no-plusplus */
|
||||
|
||||
const missingPlugin = 1000;
|
||||
const pluginFunction = 1001;
|
||||
const aborted = 1002;
|
||||
const noParser = 1003;
|
||||
const uninitializedParser = 1004;
|
||||
const filenameNotString = 1005;
|
||||
const maxFieldsSizeExceeded = 1006;
|
||||
const maxFieldsExceeded = 1007;
|
||||
const smallerThanMinFileSize = 1008;
|
||||
const biggerThanMaxFileSize = 1009;
|
||||
const noEmptyFiles = 1010;
|
||||
const missingContentType = 1011;
|
||||
const malformedMultipart = 1012;
|
||||
const missingMultipartBoundary = 1013;
|
||||
const unknownTransferEncoding = 1014;
|
||||
|
||||
const FormidableError = class extends Error {
|
||||
constructor(message, internalCode, httpCode = 500) {
|
||||
super(message);
|
||||
this.code = internalCode;
|
||||
this.httpCode = httpCode;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
missingPlugin,
|
||||
pluginFunction,
|
||||
aborted,
|
||||
noParser,
|
||||
uninitializedParser,
|
||||
filenameNotString,
|
||||
maxFieldsSizeExceeded,
|
||||
maxFieldsExceeded,
|
||||
smallerThanMinFileSize,
|
||||
biggerThanMaxFileSize,
|
||||
noEmptyFiles,
|
||||
missingContentType,
|
||||
malformedMultipart,
|
||||
missingMultipartBoundary,
|
||||
unknownTransferEncoding,
|
||||
|
||||
FormidableError,
|
||||
};
|
||||
87
ProjectSourceCode/node_modules/formidable/src/PersistentFile.js
generated
vendored
Normal file
87
ProjectSourceCode/node_modules/formidable/src/PersistentFile.js
generated
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const crypto = require('crypto');
|
||||
const { EventEmitter } = require('events');
|
||||
|
||||
class PersistentFile extends EventEmitter {
|
||||
constructor({ filepath, newFilename, originalFilename, mimetype, hashAlgorithm }) {
|
||||
super();
|
||||
|
||||
this.lastModifiedDate = null;
|
||||
Object.assign(this, { filepath, newFilename, originalFilename, mimetype, hashAlgorithm });
|
||||
|
||||
this.size = 0;
|
||||
this._writeStream = null;
|
||||
|
||||
if (typeof this.hashAlgorithm === 'string') {
|
||||
this.hash = crypto.createHash(this.hashAlgorithm);
|
||||
} else {
|
||||
this.hash = null;
|
||||
}
|
||||
}
|
||||
|
||||
open() {
|
||||
this._writeStream = new fs.WriteStream(this.filepath);
|
||||
this._writeStream.on('error', (err) => {
|
||||
this.emit('error', err);
|
||||
});
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
const json = {
|
||||
size: this.size,
|
||||
filepath: this.filepath,
|
||||
newFilename: this.newFilename,
|
||||
mimetype: this.mimetype,
|
||||
mtime: this.lastModifiedDate,
|
||||
length: this.length,
|
||||
originalFilename: this.originalFilename,
|
||||
};
|
||||
if (this.hash && this.hash !== '') {
|
||||
json.hash = this.hash;
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
toString() {
|
||||
return `PersistentFile: ${this.newFilename}, Original: ${this.originalFilename}, Path: ${this.filepath}`;
|
||||
}
|
||||
|
||||
write(buffer, cb) {
|
||||
if (this.hash) {
|
||||
this.hash.update(buffer);
|
||||
}
|
||||
|
||||
if (this._writeStream.closed) {
|
||||
cb();
|
||||
return;
|
||||
}
|
||||
|
||||
this._writeStream.write(buffer, () => {
|
||||
this.lastModifiedDate = new Date();
|
||||
this.size += buffer.length;
|
||||
this.emit('progress', this.size);
|
||||
cb();
|
||||
});
|
||||
}
|
||||
|
||||
end(cb) {
|
||||
if (this.hash) {
|
||||
this.hash = this.hash.digest('hex');
|
||||
}
|
||||
this._writeStream.end(() => {
|
||||
this.emit('end');
|
||||
cb();
|
||||
});
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this._writeStream.destroy();
|
||||
fs.unlink(this.filepath, () => {});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PersistentFile;
|
||||
82
ProjectSourceCode/node_modules/formidable/src/VolatileFile.js
generated
vendored
Normal file
82
ProjectSourceCode/node_modules/formidable/src/VolatileFile.js
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
|
||||
'use strict';
|
||||
|
||||
const crypto = require('crypto');
|
||||
const { EventEmitter } = require('events');
|
||||
|
||||
class VolatileFile extends EventEmitter {
|
||||
constructor({ filepath, newFilename, originalFilename, mimetype, hashAlgorithm, createFileWriteStream }) {
|
||||
super();
|
||||
|
||||
this.lastModifiedDate = null;
|
||||
Object.assign(this, { filepath, newFilename, originalFilename, mimetype, hashAlgorithm, createFileWriteStream });
|
||||
|
||||
this.size = 0;
|
||||
this._writeStream = null;
|
||||
|
||||
if (typeof this.hashAlgorithm === 'string') {
|
||||
this.hash = crypto.createHash(this.hashAlgorithm);
|
||||
} else {
|
||||
this.hash = null;
|
||||
}
|
||||
}
|
||||
|
||||
open() {
|
||||
this._writeStream = this.createFileWriteStream(this);
|
||||
this._writeStream.on('error', (err) => {
|
||||
this.emit('error', err);
|
||||
});
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this._writeStream.destroy();
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
const json = {
|
||||
size: this.size,
|
||||
newFilename: this.newFilename,
|
||||
length: this.length,
|
||||
originalFilename: this.originalFilename,
|
||||
mimetype: this.mimetype,
|
||||
};
|
||||
if (this.hash && this.hash !== '') {
|
||||
json.hash = this.hash;
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
toString() {
|
||||
return `VolatileFile: ${this.originalFilename}`;
|
||||
}
|
||||
|
||||
write(buffer, cb) {
|
||||
if (this.hash) {
|
||||
this.hash.update(buffer);
|
||||
}
|
||||
|
||||
if (this._writeStream.closed || this._writeStream.destroyed) {
|
||||
cb();
|
||||
return;
|
||||
}
|
||||
|
||||
this._writeStream.write(buffer, () => {
|
||||
this.size += buffer.length;
|
||||
this.emit('progress', this.size);
|
||||
cb();
|
||||
});
|
||||
}
|
||||
|
||||
end(cb) {
|
||||
if (this.hash) {
|
||||
this.hash = this.hash.digest('hex');
|
||||
}
|
||||
this._writeStream.end(() => {
|
||||
this.emit('end');
|
||||
cb();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = VolatileFile;
|
||||
38
ProjectSourceCode/node_modules/formidable/src/index.js
generated
vendored
Normal file
38
ProjectSourceCode/node_modules/formidable/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
const PersistentFile = require('./PersistentFile');
|
||||
const VolatileFile = require('./VolatileFile');
|
||||
const Formidable = require('./Formidable');
|
||||
const FormidableError = require('./FormidableError');
|
||||
|
||||
const plugins = require('./plugins/index');
|
||||
const parsers = require('./parsers/index');
|
||||
|
||||
// make it available without requiring the `new` keyword
|
||||
// if you want it access `const formidable.IncomingForm` as v1
|
||||
const formidable = (...args) => new Formidable(...args);
|
||||
|
||||
module.exports = Object.assign(formidable, {
|
||||
errors: FormidableError,
|
||||
File: PersistentFile,
|
||||
PersistentFile,
|
||||
VolatileFile,
|
||||
Formidable,
|
||||
formidable,
|
||||
|
||||
// alias
|
||||
IncomingForm: Formidable,
|
||||
|
||||
// parsers
|
||||
...parsers,
|
||||
parsers,
|
||||
|
||||
// misc
|
||||
defaultOptions: Formidable.DEFAULT_OPTIONS,
|
||||
enabledPlugins: Formidable.DEFAULT_OPTIONS.enabledPlugins,
|
||||
|
||||
// plugins
|
||||
plugins: {
|
||||
...plugins,
|
||||
},
|
||||
});
|
||||
21
ProjectSourceCode/node_modules/formidable/src/parsers/Dummy.js
generated
vendored
Normal file
21
ProjectSourceCode/node_modules/formidable/src/parsers/Dummy.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
|
||||
'use strict';
|
||||
|
||||
const { Transform } = require('stream');
|
||||
|
||||
class DummyParser extends Transform {
|
||||
constructor(incomingForm, options = {}) {
|
||||
super();
|
||||
this.globalOptions = { ...options };
|
||||
this.incomingForm = incomingForm;
|
||||
}
|
||||
|
||||
_flush(callback) {
|
||||
this.incomingForm.ended = true;
|
||||
this.incomingForm._maybeEnd();
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DummyParser;
|
||||
35
ProjectSourceCode/node_modules/formidable/src/parsers/JSON.js
generated
vendored
Normal file
35
ProjectSourceCode/node_modules/formidable/src/parsers/JSON.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
|
||||
'use strict';
|
||||
|
||||
const { Transform } = require('stream');
|
||||
|
||||
class JSONParser extends Transform {
|
||||
constructor(options = {}) {
|
||||
super({ readableObjectMode: true });
|
||||
this.chunks = [];
|
||||
this.globalOptions = { ...options };
|
||||
}
|
||||
|
||||
_transform(chunk, encoding, callback) {
|
||||
this.chunks.push(String(chunk)); // todo consider using a string decoder
|
||||
callback();
|
||||
}
|
||||
|
||||
_flush(callback) {
|
||||
try {
|
||||
const fields = JSON.parse(this.chunks.join(''));
|
||||
Object.keys(fields).forEach((key) => {
|
||||
const value = fields[key];
|
||||
this.push({ key, value });
|
||||
});
|
||||
} catch (e) {
|
||||
callback(e);
|
||||
return;
|
||||
}
|
||||
this.chunks = null;
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = JSONParser;
|
||||
347
ProjectSourceCode/node_modules/formidable/src/parsers/Multipart.js
generated
vendored
Normal file
347
ProjectSourceCode/node_modules/formidable/src/parsers/Multipart.js
generated
vendored
Normal file
@@ -0,0 +1,347 @@
|
||||
/* eslint-disable no-fallthrough */
|
||||
/* eslint-disable no-bitwise */
|
||||
/* eslint-disable no-plusplus */
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
|
||||
'use strict';
|
||||
|
||||
const { Transform } = require('stream');
|
||||
const errors = require('../FormidableError.js');
|
||||
|
||||
const { FormidableError } = errors;
|
||||
|
||||
let s = 0;
|
||||
const STATE = {
|
||||
PARSER_UNINITIALIZED: s++,
|
||||
START: s++,
|
||||
START_BOUNDARY: s++,
|
||||
HEADER_FIELD_START: s++,
|
||||
HEADER_FIELD: s++,
|
||||
HEADER_VALUE_START: s++,
|
||||
HEADER_VALUE: s++,
|
||||
HEADER_VALUE_ALMOST_DONE: s++,
|
||||
HEADERS_ALMOST_DONE: s++,
|
||||
PART_DATA_START: s++,
|
||||
PART_DATA: s++,
|
||||
PART_END: s++,
|
||||
END: s++,
|
||||
};
|
||||
|
||||
let f = 1;
|
||||
const FBOUNDARY = { PART_BOUNDARY: f, LAST_BOUNDARY: (f *= 2) };
|
||||
|
||||
const LF = 10;
|
||||
const CR = 13;
|
||||
const SPACE = 32;
|
||||
const HYPHEN = 45;
|
||||
const COLON = 58;
|
||||
const A = 97;
|
||||
const Z = 122;
|
||||
|
||||
function lower(c) {
|
||||
return c | 0x20;
|
||||
}
|
||||
|
||||
exports.STATES = {};
|
||||
|
||||
Object.keys(STATE).forEach((stateName) => {
|
||||
exports.STATES[stateName] = STATE[stateName];
|
||||
});
|
||||
|
||||
class MultipartParser extends Transform {
|
||||
constructor(options = {}) {
|
||||
super({ readableObjectMode: true });
|
||||
this.boundary = null;
|
||||
this.boundaryChars = null;
|
||||
this.lookbehind = null;
|
||||
this.bufferLength = 0;
|
||||
this.state = STATE.PARSER_UNINITIALIZED;
|
||||
|
||||
this.globalOptions = { ...options };
|
||||
this.index = null;
|
||||
this.flags = 0;
|
||||
}
|
||||
|
||||
_flush(done) {
|
||||
if (
|
||||
(this.state === STATE.HEADER_FIELD_START && this.index === 0) ||
|
||||
(this.state === STATE.PART_DATA && this.index === this.boundary.length)
|
||||
) {
|
||||
this._handleCallback('partEnd');
|
||||
this._handleCallback('end');
|
||||
done();
|
||||
} else if (this.state !== STATE.END) {
|
||||
done(
|
||||
new FormidableError(
|
||||
`MultipartParser.end(): stream ended unexpectedly: ${this.explain()}`,
|
||||
errors.malformedMultipart,
|
||||
400,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
initWithBoundary(str) {
|
||||
this.boundary = Buffer.from(`\r\n--${str}`);
|
||||
this.lookbehind = Buffer.alloc(this.boundary.length + 8);
|
||||
this.state = STATE.START;
|
||||
this.boundaryChars = {};
|
||||
|
||||
for (let i = 0; i < this.boundary.length; i++) {
|
||||
this.boundaryChars[this.boundary[i]] = true;
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line max-params
|
||||
_handleCallback(name, buf, start, end) {
|
||||
if (start !== undefined && start === end) {
|
||||
return;
|
||||
}
|
||||
this.push({ name, buffer: buf, start, end });
|
||||
}
|
||||
|
||||
// eslint-disable-next-line max-statements
|
||||
_transform(buffer, _, done) {
|
||||
let i = 0;
|
||||
let prevIndex = this.index;
|
||||
let { index, state, flags } = this;
|
||||
const { lookbehind, boundary, boundaryChars } = this;
|
||||
const boundaryLength = boundary.length;
|
||||
const boundaryEnd = boundaryLength - 1;
|
||||
this.bufferLength = buffer.length;
|
||||
let c = null;
|
||||
let cl = null;
|
||||
|
||||
const setMark = (name, idx) => {
|
||||
this[`${name}Mark`] = typeof idx === 'number' ? idx : i;
|
||||
};
|
||||
|
||||
const clearMarkSymbol = (name) => {
|
||||
delete this[`${name}Mark`];
|
||||
};
|
||||
|
||||
const dataCallback = (name, shouldClear) => {
|
||||
const markSymbol = `${name}Mark`;
|
||||
if (!(markSymbol in this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!shouldClear) {
|
||||
this._handleCallback(name, buffer, this[markSymbol], buffer.length);
|
||||
setMark(name, 0);
|
||||
} else {
|
||||
this._handleCallback(name, buffer, this[markSymbol], i);
|
||||
clearMarkSymbol(name);
|
||||
}
|
||||
};
|
||||
|
||||
for (i = 0; i < this.bufferLength; i++) {
|
||||
c = buffer[i];
|
||||
switch (state) {
|
||||
case STATE.PARSER_UNINITIALIZED:
|
||||
return i;
|
||||
case STATE.START:
|
||||
index = 0;
|
||||
state = STATE.START_BOUNDARY;
|
||||
case STATE.START_BOUNDARY:
|
||||
if (index === boundary.length - 2) {
|
||||
if (c === HYPHEN) {
|
||||
flags |= FBOUNDARY.LAST_BOUNDARY;
|
||||
} else if (c !== CR) {
|
||||
return i;
|
||||
}
|
||||
index++;
|
||||
break;
|
||||
} else if (index - 1 === boundary.length - 2) {
|
||||
if (flags & FBOUNDARY.LAST_BOUNDARY && c === HYPHEN) {
|
||||
this._handleCallback('end');
|
||||
state = STATE.END;
|
||||
flags = 0;
|
||||
} else if (!(flags & FBOUNDARY.LAST_BOUNDARY) && c === LF) {
|
||||
index = 0;
|
||||
this._handleCallback('partBegin');
|
||||
state = STATE.HEADER_FIELD_START;
|
||||
} else {
|
||||
return i;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (c !== boundary[index + 2]) {
|
||||
index = -2;
|
||||
}
|
||||
if (c === boundary[index + 2]) {
|
||||
index++;
|
||||
}
|
||||
break;
|
||||
case STATE.HEADER_FIELD_START:
|
||||
state = STATE.HEADER_FIELD;
|
||||
setMark('headerField');
|
||||
index = 0;
|
||||
case STATE.HEADER_FIELD:
|
||||
if (c === CR) {
|
||||
clearMarkSymbol('headerField');
|
||||
state = STATE.HEADERS_ALMOST_DONE;
|
||||
break;
|
||||
}
|
||||
|
||||
index++;
|
||||
if (c === HYPHEN) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (c === COLON) {
|
||||
if (index === 1) {
|
||||
// empty header field
|
||||
return i;
|
||||
}
|
||||
dataCallback('headerField', true);
|
||||
state = STATE.HEADER_VALUE_START;
|
||||
break;
|
||||
}
|
||||
|
||||
cl = lower(c);
|
||||
if (cl < A || cl > Z) {
|
||||
return i;
|
||||
}
|
||||
break;
|
||||
case STATE.HEADER_VALUE_START:
|
||||
if (c === SPACE) {
|
||||
break;
|
||||
}
|
||||
|
||||
setMark('headerValue');
|
||||
state = STATE.HEADER_VALUE;
|
||||
case STATE.HEADER_VALUE:
|
||||
if (c === CR) {
|
||||
dataCallback('headerValue', true);
|
||||
this._handleCallback('headerEnd');
|
||||
state = STATE.HEADER_VALUE_ALMOST_DONE;
|
||||
}
|
||||
break;
|
||||
case STATE.HEADER_VALUE_ALMOST_DONE:
|
||||
if (c !== LF) {
|
||||
return i;
|
||||
}
|
||||
state = STATE.HEADER_FIELD_START;
|
||||
break;
|
||||
case STATE.HEADERS_ALMOST_DONE:
|
||||
if (c !== LF) {
|
||||
return i;
|
||||
}
|
||||
|
||||
this._handleCallback('headersEnd');
|
||||
state = STATE.PART_DATA_START;
|
||||
break;
|
||||
case STATE.PART_DATA_START:
|
||||
state = STATE.PART_DATA;
|
||||
setMark('partData');
|
||||
case STATE.PART_DATA:
|
||||
prevIndex = index;
|
||||
|
||||
if (index === 0) {
|
||||
// boyer-moore derrived algorithm to safely skip non-boundary data
|
||||
i += boundaryEnd;
|
||||
while (i < this.bufferLength && !(buffer[i] in boundaryChars)) {
|
||||
i += boundaryLength;
|
||||
}
|
||||
i -= boundaryEnd;
|
||||
c = buffer[i];
|
||||
}
|
||||
|
||||
if (index < boundary.length) {
|
||||
if (boundary[index] === c) {
|
||||
if (index === 0) {
|
||||
dataCallback('partData', true);
|
||||
}
|
||||
index++;
|
||||
} else {
|
||||
index = 0;
|
||||
}
|
||||
} else if (index === boundary.length) {
|
||||
index++;
|
||||
if (c === CR) {
|
||||
// CR = part boundary
|
||||
flags |= FBOUNDARY.PART_BOUNDARY;
|
||||
} else if (c === HYPHEN) {
|
||||
// HYPHEN = end boundary
|
||||
flags |= FBOUNDARY.LAST_BOUNDARY;
|
||||
} else {
|
||||
index = 0;
|
||||
}
|
||||
} else if (index - 1 === boundary.length) {
|
||||
if (flags & FBOUNDARY.PART_BOUNDARY) {
|
||||
index = 0;
|
||||
if (c === LF) {
|
||||
// unset the PART_BOUNDARY flag
|
||||
flags &= ~FBOUNDARY.PART_BOUNDARY;
|
||||
this._handleCallback('partEnd');
|
||||
this._handleCallback('partBegin');
|
||||
state = STATE.HEADER_FIELD_START;
|
||||
break;
|
||||
}
|
||||
} else if (flags & FBOUNDARY.LAST_BOUNDARY) {
|
||||
if (c === HYPHEN) {
|
||||
this._handleCallback('partEnd');
|
||||
this._handleCallback('end');
|
||||
state = STATE.END;
|
||||
flags = 0;
|
||||
} else {
|
||||
index = 0;
|
||||
}
|
||||
} else {
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (index > 0) {
|
||||
// when matching a possible boundary, keep a lookbehind reference
|
||||
// in case it turns out to be a false lead
|
||||
lookbehind[index - 1] = c;
|
||||
} else if (prevIndex > 0) {
|
||||
// if our boundary turned out to be rubbish, the captured lookbehind
|
||||
// belongs to partData
|
||||
this._handleCallback('partData', lookbehind, 0, prevIndex);
|
||||
prevIndex = 0;
|
||||
setMark('partData');
|
||||
|
||||
// reconsider the current character even so it interrupted the sequence
|
||||
// it could be the beginning of a new sequence
|
||||
i--;
|
||||
}
|
||||
|
||||
break;
|
||||
case STATE.END:
|
||||
break;
|
||||
default:
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
dataCallback('headerField');
|
||||
dataCallback('headerValue');
|
||||
dataCallback('partData');
|
||||
|
||||
this.index = index;
|
||||
this.state = state;
|
||||
this.flags = flags;
|
||||
|
||||
done();
|
||||
return this.bufferLength;
|
||||
}
|
||||
|
||||
explain() {
|
||||
return `state = ${MultipartParser.stateToString(this.state)}`;
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line consistent-return
|
||||
MultipartParser.stateToString = (stateNumber) => {
|
||||
// eslint-disable-next-line no-restricted-syntax, guard-for-in
|
||||
for (const stateName in STATE) {
|
||||
const number = STATE[stateName];
|
||||
if (number === stateNumber) return stateName;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Object.assign(MultipartParser, { STATES: exports.STATES });
|
||||
12
ProjectSourceCode/node_modules/formidable/src/parsers/OctetStream.js
generated
vendored
Normal file
12
ProjectSourceCode/node_modules/formidable/src/parsers/OctetStream.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
const { PassThrough } = require('stream');
|
||||
|
||||
class OctetStreamParser extends PassThrough {
|
||||
constructor(options = {}) {
|
||||
super();
|
||||
this.globalOptions = { ...options };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = OctetStreamParser;
|
||||
38
ProjectSourceCode/node_modules/formidable/src/parsers/Querystring.js
generated
vendored
Normal file
38
ProjectSourceCode/node_modules/formidable/src/parsers/Querystring.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
|
||||
'use strict';
|
||||
|
||||
const { Transform } = require('stream');
|
||||
const querystring = require('querystring');
|
||||
|
||||
// This is a buffering parser, not quite as nice as the multipart one.
|
||||
// If I find time I'll rewrite this to be fully streaming as well
|
||||
class QuerystringParser extends Transform {
|
||||
constructor(options = {}) {
|
||||
super({ readableObjectMode: true });
|
||||
this.globalOptions = { ...options };
|
||||
this.buffer = '';
|
||||
this.bufferLength = 0;
|
||||
}
|
||||
|
||||
_transform(buffer, encoding, callback) {
|
||||
this.buffer += buffer.toString('ascii');
|
||||
this.bufferLength = this.buffer.length;
|
||||
callback();
|
||||
}
|
||||
|
||||
_flush(callback) {
|
||||
const fields = querystring.parse(this.buffer, '&', '=');
|
||||
// eslint-disable-next-line no-restricted-syntax, guard-for-in
|
||||
for (const key in fields) {
|
||||
this.push({
|
||||
key,
|
||||
value: fields[key],
|
||||
});
|
||||
}
|
||||
this.buffer = '';
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = QuerystringParser;
|
||||
121
ProjectSourceCode/node_modules/formidable/src/parsers/StreamingQuerystring.js
generated
vendored
Normal file
121
ProjectSourceCode/node_modules/formidable/src/parsers/StreamingQuerystring.js
generated
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
// not used
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
|
||||
'use strict';
|
||||
|
||||
const { Transform } = require('stream');
|
||||
const errors = require('../FormidableError.js');
|
||||
|
||||
const { FormidableError } = errors;
|
||||
|
||||
const AMPERSAND = 38;
|
||||
const EQUALS = 61;
|
||||
|
||||
class QuerystringParser extends Transform {
|
||||
constructor(options = {}) {
|
||||
super({ readableObjectMode: true });
|
||||
|
||||
const { maxFieldSize } = options;
|
||||
this.maxFieldLength = maxFieldSize;
|
||||
this.buffer = Buffer.from('');
|
||||
this.fieldCount = 0;
|
||||
this.sectionStart = 0;
|
||||
this.key = '';
|
||||
this.readingKey = true;
|
||||
}
|
||||
|
||||
_transform(buffer, encoding, callback) {
|
||||
let len = buffer.length;
|
||||
if (this.buffer && this.buffer.length) {
|
||||
// we have some data left over from the last write which we are in the middle of processing
|
||||
len += this.buffer.length;
|
||||
buffer = Buffer.concat([this.buffer, buffer], len);
|
||||
}
|
||||
|
||||
for (let i = this.buffer.length || 0; i < len; i += 1) {
|
||||
const c = buffer[i];
|
||||
if (this.readingKey) {
|
||||
// KEY, check for =
|
||||
if (c === EQUALS) {
|
||||
this.key = this.getSection(buffer, i);
|
||||
this.readingKey = false;
|
||||
this.sectionStart = i + 1;
|
||||
} else if (c === AMPERSAND) {
|
||||
// just key, no value. Prepare to read another key
|
||||
this.emitField(this.getSection(buffer, i));
|
||||
this.sectionStart = i + 1;
|
||||
}
|
||||
// VALUE, check for &
|
||||
} else if (c === AMPERSAND) {
|
||||
this.emitField(this.key, this.getSection(buffer, i));
|
||||
this.sectionStart = i + 1;
|
||||
}
|
||||
|
||||
if (
|
||||
this.maxFieldLength &&
|
||||
i - this.sectionStart === this.maxFieldLength
|
||||
) {
|
||||
callback(
|
||||
new FormidableError(
|
||||
`${
|
||||
this.readingKey ? 'Key' : `Value for ${this.key}`
|
||||
} longer than maxFieldLength`,
|
||||
),
|
||||
errors.maxFieldsSizeExceeded,
|
||||
413,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare the remaining key or value (from sectionStart to the end) for the next write() or for end()
|
||||
len -= this.sectionStart;
|
||||
if (len) {
|
||||
// i.e. Unless the last character was a & or =
|
||||
this.buffer = Buffer.from(this.buffer, 0, this.sectionStart);
|
||||
} else this.buffer = null;
|
||||
|
||||
this.sectionStart = 0;
|
||||
callback();
|
||||
}
|
||||
|
||||
_flush(callback) {
|
||||
// Emit the last field
|
||||
if (this.readingKey) {
|
||||
// we only have a key if there's something in the buffer. We definitely have no value
|
||||
if (this.buffer && this.buffer.length){
|
||||
this.emitField(this.buffer.toString('ascii'));
|
||||
}
|
||||
} else {
|
||||
// We have a key, we may or may not have a value
|
||||
this.emitField(
|
||||
this.key,
|
||||
this.buffer && this.buffer.length && this.buffer.toString('ascii'),
|
||||
);
|
||||
}
|
||||
this.buffer = '';
|
||||
callback();
|
||||
}
|
||||
|
||||
getSection(buffer, i) {
|
||||
if (i === this.sectionStart) return '';
|
||||
|
||||
return buffer.toString('ascii', this.sectionStart, i);
|
||||
}
|
||||
|
||||
emitField(key, val) {
|
||||
this.key = '';
|
||||
this.readingKey = true;
|
||||
this.push({ key, value: val || '' });
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = QuerystringParser;
|
||||
|
||||
// const q = new QuerystringParser({maxFieldSize: 100});
|
||||
// (async function() {
|
||||
// for await (const chunk of q) {
|
||||
// console.log(chunk);
|
||||
// }
|
||||
// })();
|
||||
// q.write("a=b&c=d")
|
||||
// q.end()
|
||||
17
ProjectSourceCode/node_modules/formidable/src/parsers/index.js
generated
vendored
Normal file
17
ProjectSourceCode/node_modules/formidable/src/parsers/index.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
const JSONParser = require('./JSON');
|
||||
const DummyParser = require('./Dummy');
|
||||
const MultipartParser = require('./Multipart');
|
||||
const OctetStreamParser = require('./OctetStream');
|
||||
const QueryStringParser = require('./Querystring');
|
||||
|
||||
Object.assign(exports, {
|
||||
JSONParser,
|
||||
DummyParser,
|
||||
MultipartParser,
|
||||
OctetStreamParser,
|
||||
OctetstreamParser: OctetStreamParser,
|
||||
QueryStringParser,
|
||||
QuerystringParser: QueryStringParser,
|
||||
});
|
||||
13
ProjectSourceCode/node_modules/formidable/src/plugins/index.js
generated
vendored
Normal file
13
ProjectSourceCode/node_modules/formidable/src/plugins/index.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
const octetstream = require('./octetstream');
|
||||
const querystring = require('./querystring');
|
||||
const multipart = require('./multipart');
|
||||
const json = require('./json');
|
||||
|
||||
Object.assign(exports, {
|
||||
octetstream,
|
||||
querystring,
|
||||
multipart,
|
||||
json,
|
||||
});
|
||||
38
ProjectSourceCode/node_modules/formidable/src/plugins/json.js
generated
vendored
Normal file
38
ProjectSourceCode/node_modules/formidable/src/plugins/json.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
|
||||
'use strict';
|
||||
|
||||
const JSONParser = require('../parsers/JSON');
|
||||
|
||||
// the `options` is also available through the `this.options` / `formidable.options`
|
||||
module.exports = function plugin(formidable, options) {
|
||||
// the `this` context is always formidable, as the first argument of a plugin
|
||||
// but this allows us to customize/test each plugin
|
||||
|
||||
/* istanbul ignore next */
|
||||
const self = this || formidable;
|
||||
|
||||
if (/json/i.test(self.headers['content-type'])) {
|
||||
init.call(self, self, options);
|
||||
}
|
||||
};
|
||||
|
||||
// Note that it's a good practice (but it's up to you) to use the `this.options` instead
|
||||
// of the passed `options` (second) param, because when you decide
|
||||
// to test the plugin you can pass custom `this` context to it (and so `this.options`)
|
||||
function init(_self, _opts) {
|
||||
this.type = 'json';
|
||||
|
||||
const parser = new JSONParser(this.options);
|
||||
|
||||
parser.on('data', ({ key, value }) => {
|
||||
this.emit('field', key, value);
|
||||
});
|
||||
|
||||
parser.once('end', () => {
|
||||
this.ended = true;
|
||||
this._maybeEnd();
|
||||
});
|
||||
|
||||
this._parser = parser;
|
||||
}
|
||||
173
ProjectSourceCode/node_modules/formidable/src/plugins/multipart.js
generated
vendored
Normal file
173
ProjectSourceCode/node_modules/formidable/src/plugins/multipart.js
generated
vendored
Normal file
@@ -0,0 +1,173 @@
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
|
||||
'use strict';
|
||||
|
||||
const { Stream } = require('stream');
|
||||
const MultipartParser = require('../parsers/Multipart');
|
||||
const errors = require('../FormidableError.js');
|
||||
|
||||
const { FormidableError } = errors;
|
||||
|
||||
// the `options` is also available through the `options` / `formidable.options`
|
||||
module.exports = function plugin(formidable, options) {
|
||||
// the `this` context is always formidable, as the first argument of a plugin
|
||||
// but this allows us to customize/test each plugin
|
||||
|
||||
/* istanbul ignore next */
|
||||
const self = this || formidable;
|
||||
|
||||
// NOTE: we (currently) support both multipart/form-data and multipart/related
|
||||
const multipart = /multipart/i.test(self.headers['content-type']);
|
||||
|
||||
if (multipart) {
|
||||
const m = self.headers['content-type'].match(
|
||||
/boundary=(?:"([^"]+)"|([^;]+))/i,
|
||||
);
|
||||
if (m) {
|
||||
const initMultipart = createInitMultipart(m[1] || m[2]);
|
||||
initMultipart.call(self, self, options); // lgtm [js/superfluous-trailing-arguments]
|
||||
} else {
|
||||
const err = new FormidableError(
|
||||
'bad content-type header, no multipart boundary',
|
||||
errors.missingMultipartBoundary,
|
||||
400,
|
||||
);
|
||||
self._error(err);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Note that it's a good practice (but it's up to you) to use the `this.options` instead
|
||||
// of the passed `options` (second) param, because when you decide
|
||||
// to test the plugin you can pass custom `this` context to it (and so `this.options`)
|
||||
function createInitMultipart(boundary) {
|
||||
return function initMultipart() {
|
||||
this.type = 'multipart';
|
||||
|
||||
const parser = new MultipartParser(this.options);
|
||||
let headerField;
|
||||
let headerValue;
|
||||
let part;
|
||||
|
||||
parser.initWithBoundary(boundary);
|
||||
|
||||
// eslint-disable-next-line max-statements, consistent-return
|
||||
parser.on('data', ({ name, buffer, start, end }) => {
|
||||
if (name === 'partBegin') {
|
||||
part = new Stream();
|
||||
part.readable = true;
|
||||
part.headers = {};
|
||||
part.name = null;
|
||||
part.originalFilename = null;
|
||||
part.mimetype = null;
|
||||
|
||||
part.transferEncoding = this.options.encoding;
|
||||
part.transferBuffer = '';
|
||||
|
||||
headerField = '';
|
||||
headerValue = '';
|
||||
} else if (name === 'headerField') {
|
||||
headerField += buffer.toString(this.options.encoding, start, end);
|
||||
} else if (name === 'headerValue') {
|
||||
headerValue += buffer.toString(this.options.encoding, start, end);
|
||||
} else if (name === 'headerEnd') {
|
||||
headerField = headerField.toLowerCase();
|
||||
part.headers[headerField] = headerValue;
|
||||
|
||||
// matches either a quoted-string or a token (RFC 2616 section 19.5.1)
|
||||
const m = headerValue.match(
|
||||
// eslint-disable-next-line no-useless-escape
|
||||
/\bname=("([^"]*)"|([^\(\)<>@,;:\\"\/\[\]\?=\{\}\s\t/]+))/i,
|
||||
);
|
||||
if (headerField === 'content-disposition') {
|
||||
if (m) {
|
||||
part.name = m[2] || m[3] || '';
|
||||
}
|
||||
|
||||
part.originalFilename = this._getFileName(headerValue);
|
||||
} else if (headerField === 'content-type') {
|
||||
part.mimetype = headerValue;
|
||||
} else if (headerField === 'content-transfer-encoding') {
|
||||
part.transferEncoding = headerValue.toLowerCase();
|
||||
}
|
||||
|
||||
headerField = '';
|
||||
headerValue = '';
|
||||
} else if (name === 'headersEnd') {
|
||||
switch (part.transferEncoding) {
|
||||
case 'binary':
|
||||
case '7bit':
|
||||
case '8bit':
|
||||
case 'utf-8': {
|
||||
const dataPropagation = (ctx) => {
|
||||
if (ctx.name === 'partData') {
|
||||
part.emit('data', ctx.buffer.slice(ctx.start, ctx.end));
|
||||
}
|
||||
};
|
||||
const dataStopPropagation = (ctx) => {
|
||||
if (ctx.name === 'partEnd') {
|
||||
part.emit('end');
|
||||
parser.off('data', dataPropagation);
|
||||
parser.off('data', dataStopPropagation);
|
||||
}
|
||||
};
|
||||
parser.on('data', dataPropagation);
|
||||
parser.on('data', dataStopPropagation);
|
||||
break;
|
||||
}
|
||||
case 'base64': {
|
||||
const dataPropagation = (ctx) => {
|
||||
if (ctx.name === 'partData') {
|
||||
part.transferBuffer += ctx.buffer
|
||||
.slice(ctx.start, ctx.end)
|
||||
.toString('ascii');
|
||||
|
||||
/*
|
||||
four bytes (chars) in base64 converts to three bytes in binary
|
||||
encoding. So we should always work with a number of bytes that
|
||||
can be divided by 4, it will result in a number of buytes that
|
||||
can be divided vy 3.
|
||||
*/
|
||||
const offset = parseInt(part.transferBuffer.length / 4, 10) * 4;
|
||||
part.emit(
|
||||
'data',
|
||||
Buffer.from(
|
||||
part.transferBuffer.substring(0, offset),
|
||||
'base64',
|
||||
),
|
||||
);
|
||||
part.transferBuffer = part.transferBuffer.substring(offset);
|
||||
}
|
||||
};
|
||||
const dataStopPropagation = (ctx) => {
|
||||
if (ctx.name === 'partEnd') {
|
||||
part.emit('data', Buffer.from(part.transferBuffer, 'base64'));
|
||||
part.emit('end');
|
||||
parser.off('data', dataPropagation);
|
||||
parser.off('data', dataStopPropagation);
|
||||
}
|
||||
};
|
||||
parser.on('data', dataPropagation);
|
||||
parser.on('data', dataStopPropagation);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return this._error(
|
||||
new FormidableError(
|
||||
'unknown transfer-encoding',
|
||||
errors.unknownTransferEncoding,
|
||||
501,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
this.onPart(part);
|
||||
} else if (name === 'end') {
|
||||
this.ended = true;
|
||||
this._maybeEnd();
|
||||
}
|
||||
});
|
||||
|
||||
this._parser = parser;
|
||||
};
|
||||
}
|
||||
86
ProjectSourceCode/node_modules/formidable/src/plugins/octetstream.js
generated
vendored
Normal file
86
ProjectSourceCode/node_modules/formidable/src/plugins/octetstream.js
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
|
||||
'use strict';
|
||||
|
||||
const OctetStreamParser = require('../parsers/OctetStream');
|
||||
|
||||
// the `options` is also available through the `options` / `formidable.options`
|
||||
module.exports = function plugin(formidable, options) {
|
||||
// the `this` context is always formidable, as the first argument of a plugin
|
||||
// but this allows us to customize/test each plugin
|
||||
|
||||
/* istanbul ignore next */
|
||||
const self = this || formidable;
|
||||
|
||||
if (/octet-stream/i.test(self.headers['content-type'])) {
|
||||
init.call(self, self, options);
|
||||
}
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
// Note that it's a good practice (but it's up to you) to use the `this.options` instead
|
||||
// of the passed `options` (second) param, because when you decide
|
||||
// to test the plugin you can pass custom `this` context to it (and so `this.options`)
|
||||
function init(_self, _opts) {
|
||||
this.type = 'octet-stream';
|
||||
const originalFilename = this.headers['x-file-name'];
|
||||
const mimetype = this.headers['content-type'];
|
||||
|
||||
const thisPart = {
|
||||
originalFilename,
|
||||
mimetype,
|
||||
};
|
||||
const newFilename = this._getNewName(thisPart);
|
||||
const filepath = this._joinDirectoryName(newFilename);
|
||||
const file = this._newFile({
|
||||
newFilename,
|
||||
filepath,
|
||||
originalFilename,
|
||||
mimetype,
|
||||
});
|
||||
|
||||
this.emit('fileBegin', originalFilename, file);
|
||||
file.open();
|
||||
this.openedFiles.push(file);
|
||||
this._flushing += 1;
|
||||
|
||||
this._parser = new OctetStreamParser(this.options);
|
||||
|
||||
// Keep track of writes that haven't finished so we don't emit the file before it's done being written
|
||||
let outstandingWrites = 0;
|
||||
|
||||
this._parser.on('data', (buffer) => {
|
||||
this.pause();
|
||||
outstandingWrites += 1;
|
||||
|
||||
file.write(buffer, () => {
|
||||
outstandingWrites -= 1;
|
||||
this.resume();
|
||||
|
||||
if (this.ended) {
|
||||
this._parser.emit('doneWritingFile');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
this._parser.on('end', () => {
|
||||
this._flushing -= 1;
|
||||
this.ended = true;
|
||||
|
||||
const done = () => {
|
||||
file.end(() => {
|
||||
this.emit('file', 'file', file);
|
||||
this._maybeEnd();
|
||||
});
|
||||
};
|
||||
|
||||
if (outstandingWrites === 0) {
|
||||
done();
|
||||
} else {
|
||||
this._parser.once('doneWritingFile', done);
|
||||
}
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
42
ProjectSourceCode/node_modules/formidable/src/plugins/querystring.js
generated
vendored
Normal file
42
ProjectSourceCode/node_modules/formidable/src/plugins/querystring.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
|
||||
'use strict';
|
||||
|
||||
const QuerystringParser = require('../parsers/Querystring');
|
||||
|
||||
// the `options` is also available through the `this.options` / `formidable.options`
|
||||
module.exports = function plugin(formidable, options) {
|
||||
// the `this` context is always formidable, as the first argument of a plugin
|
||||
// but this allows us to customize/test each plugin
|
||||
|
||||
/* istanbul ignore next */
|
||||
const self = this || formidable;
|
||||
|
||||
if (/urlencoded/i.test(self.headers['content-type'])) {
|
||||
init.call(self, self, options);
|
||||
}
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
// Note that it's a good practice (but it's up to you) to use the `this.options` instead
|
||||
// of the passed `options` (second) param, because when you decide
|
||||
// to test the plugin you can pass custom `this` context to it (and so `this.options`)
|
||||
function init(_self, _opts) {
|
||||
this.type = 'urlencoded';
|
||||
|
||||
const parser = new QuerystringParser(this.options);
|
||||
|
||||
parser.on('data', ({ key, value }) => {
|
||||
this.emit('field', key, value);
|
||||
});
|
||||
|
||||
parser.once('end', () => {
|
||||
this.ended = true;
|
||||
this._maybeEnd();
|
||||
});
|
||||
|
||||
this._parser = parser;
|
||||
|
||||
return this;
|
||||
}
|
||||
Reference in New Issue
Block a user