formidable
Advanced tools
Comparing version 2.0.0-canary.20200226.1 to 2.0.0-canary.20200402.1
{ | ||
"name": "formidable", | ||
"version": "2.0.0-canary.20200226.1", | ||
"version": "2.0.0-canary.20200402.1", | ||
"license": "MIT", | ||
@@ -24,9 +24,8 @@ "description": "A node.js module for parsing form data, especially file uploads.", | ||
"lint:prepare": "eslint --cache --fix --quiet --format codeframe", | ||
"pretest": "yarn del ./test/tmp", | ||
"postpretest": "yarn make-dir ./test/tmp", | ||
"reinstall": "yarn del ./node_modules ./yarn.lock", | ||
"reinstall": "del-cli ./node_modules ./yarn.lock", | ||
"postreinstall": "yarn setup", | ||
"setup": "yarn", | ||
"test": "yarn node test/run.js", | ||
"pretest:ci": "yarn pretest", | ||
"pretest": "del-cli ./test/tmp && make-dir ./test/tmp", | ||
"test": "node test/run.js", | ||
"pretest:ci": "yarn run pretest", | ||
"test:ci": "nyc node test/run.js", | ||
@@ -37,2 +36,3 @@ "test:jest": "jest --coverage" | ||
"dezalgo": "^1.0.3", | ||
"hexoid": "^1.0.0", | ||
"once": "^1.4.0" | ||
@@ -43,18 +43,18 @@ }, | ||
"@commitlint/config-conventional": "^8.3.4", | ||
"@tunnckocore/prettier-config": "^1.3.3", | ||
"@tunnckocore/prettier-config": "^1.3.8", | ||
"del-cli": "^3.0.0", | ||
"eslint": "^6.8.0", | ||
"eslint-config-airbnb-base": "^14.0.0", | ||
"eslint-config-prettier": "^6.10.0", | ||
"eslint-plugin-import": "^2.20.1", | ||
"eslint-config-airbnb-base": "^14.1.0", | ||
"eslint-config-prettier": "^6.10.1", | ||
"eslint-plugin-import": "^2.20.2", | ||
"eslint-plugin-prettier": "^3.1.2", | ||
"express": "^4.17.1", | ||
"husky": "^4.2.2", | ||
"jest": "^25.1.0", | ||
"husky": "^4.2.3", | ||
"jest": "^25.2.6", | ||
"koa": "^2.11.0", | ||
"lint-staged": "^10.0.7", | ||
"lint-staged": "^10.1.1", | ||
"make-dir-cli": "^2.0.0", | ||
"nyc": "^15.0.0", | ||
"prettier": "^1.19.1", | ||
"prettier-plugin-pkgjson": "^0.2.3", | ||
"prettier": "^2.0.2", | ||
"prettier-plugin-pkgjson": "^0.2.8", | ||
"request": "^2.88.2", | ||
@@ -61,0 +61,0 @@ "supertest": "^4.0.2", |
@@ -146,3 +146,3 @@ <p align="center"> | ||
Or try the | ||
[examples/with-express.js](https://github.com/node-formidable/node-formidable/blob/master/examples/with-express.js) | ||
[examples/with-express.js](https://github.com/node-formidable/formidable/blob/master/examples/with-express.js) | ||
@@ -685,4 +685,4 @@ ```js | ||
[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/node-formidable | ||
[codecov-img]: https://badgen.net/codecov/c/github/node-formidable/node-formidable/master?icon=codecov | ||
[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 | ||
@@ -693,3 +693,3 @@ [npmv-dev-img]: https://badgen.net/npm/v/formidable/dev?icon=npm | ||
[license-img]: https://badgen.net/npm/license/formidable | ||
[license-url]: https://github.com/node-formidable/node-formidable/blob/master/LICENSE | ||
[license-url]: https://github.com/node-formidable/formidable/blob/master/LICENSE | ||
[chat-img]: https://badgen.net/badge/chat/on%20gitter/46BC99?icon=gitter | ||
@@ -716,6 +716,6 @@ [chat-url]: https://gitter.im/node-formidable/Lobby | ||
[contributing-url]: https://github.com/node-formidable/node-formidable/blob/master/CONTRIBUTING.md | ||
[code_of_conduct-url]: https://github.com/node-formidable/node-formidable/blob/master/CODE_OF_CONDUCT.md | ||
[contributing-url]: https://github.com/node-formidable/formidable/blob/master/CONTRIBUTING.md | ||
[code_of_conduct-url]: https://github.com/node-formidable/formidable/blob/master/CODE_OF_CONDUCT.md | ||
[open-issue-url]: https://github.com/node-formidable/node-formidable/issues/new | ||
[open-issue-url]: https://github.com/node-formidable/formidable/issues/new | ||
@@ -728,6 +728,6 @@ [tidelift-url]: https://tidelift.com/subscription/pkg/npm-formidable?utm_source=npm-formidable&utm_medium=referral&utm_campaign=enterprise | ||
[linux-build-img]: https://badgen-net.charlike.now.sh/github/checks/node-formidable/node-formidable?label=linux%20build&icon=github | ||
[macos-build-img]: https://badgen-net.charlike.now.sh/github/checks/node-formidable/node-formidable?label=macos%20build&icon=github | ||
[windows-build-img]: https://badgen-net.charlike.now.sh/github/checks/node-formidable/node-formidable?label=windows%20build&icon=github | ||
[build-url]: https://github.com/node-formidable/node-formidable/actions?query=workflow%3Anodejs | ||
[linux-build-img]: https://badgen-net.charlike.now.sh/github/checks/node-formidable/formidable/master/ubuntu?cache=300&label=linux%20build&icon=github | ||
[macos-build-img]: https://badgen-net.charlike.now.sh/github/checks/node-formidable/formidable/master/macos?cache=300&label=macos%20build&icon=github | ||
[windows-build-img]: https://badgen-net.charlike.now.sh/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 --> |
@@ -9,3 +9,3 @@ /* eslint-disable class-methods-use-this */ | ||
const path = require('path'); | ||
const crypto = require('crypto'); | ||
const hexoid = require('hexoid'); | ||
const once = require('once'); | ||
@@ -16,2 +16,3 @@ const dezalgo = require('dezalgo'); | ||
const toHexoId = hexoid(25); | ||
const DEFAULT_OPTIONS = { | ||
@@ -24,2 +25,3 @@ maxFields: 1000, | ||
hash: false, | ||
uploadDir: os.tmpdir(), | ||
multiples: false, | ||
@@ -40,15 +42,27 @@ enabledPlugins: ['octetstream', 'querystring', 'multipart', 'json'], | ||
super(); | ||
this.error = null; | ||
this.ended = false; | ||
this.options = { ...DEFAULT_OPTIONS, ...options }; | ||
this.uploadDir = this.uploadDir || os.tmpdir(); | ||
this.headers = null; | ||
this.type = null; | ||
const dir = this.options.uploadDir || this.options.uploaddir || os.tmpdir(); | ||
this.bytesReceived = null; | ||
this.bytesExpected = null; | ||
this.uploaddir = dir; | ||
this.uploadDir = dir; | ||
this._parser = null; | ||
this.options.filename = | ||
typeof this.options.filename === 'function' | ||
? this.options.filename.bind(this) | ||
: this._uploadPath.bind(this); | ||
// initialize with null | ||
[ | ||
'error', | ||
'headers', | ||
'type', | ||
'bytesExpected', | ||
'bytesReceived', | ||
'_parser', | ||
].forEach((key) => { | ||
this[key] = null; | ||
}); | ||
this._flushing = 0; | ||
@@ -283,3 +297,3 @@ this._fieldsSize = 0; | ||
const file = new File({ | ||
path: this._uploadPath(part.filename), | ||
path: this.options.filename(part, this), | ||
name: part.filename, | ||
@@ -430,14 +444,13 @@ type: part.mime, | ||
_uploadPath(filename) { | ||
const buf = crypto.randomBytes(16); | ||
let name = `upload_${buf.toString('hex')}`; | ||
_uploadPath(part) { | ||
const name = `${this.uploadDir}${path.sep}${toHexoId()}`; | ||
if (this.options.keepExtensions) { | ||
let ext = path.extname(filename); | ||
if (part && this.options.keepExtensions) { | ||
let ext = path.extname(typeof part === 'string' ? part : part.filename); | ||
ext = ext.replace(/(\.[a-z0-9]+).*/i, '$1'); | ||
name += ext; | ||
return `${name}${ext}`; | ||
} | ||
return path.join(this.uploadDir, name); | ||
return name; | ||
} | ||
@@ -444,0 +457,0 @@ |
@@ -0,1 +1,2 @@ | ||
/* eslint-disable max-statements */ | ||
/* eslint-disable no-underscore-dangle */ | ||
@@ -66,16 +67,33 @@ | ||
let ext = path.extname(form._uploadPath('fine.jpg?foo=bar')); | ||
const getBasename = (part) => path.basename(form._uploadPath(part)); | ||
let basename = getBasename('fine.jpg?foo=bar'); | ||
expect(basename).toHaveLength(29); | ||
let ext = path.extname(basename); | ||
expect(ext).toBe('.jpg'); | ||
ext = path.extname(form._uploadPath('fine?foo=bar')); | ||
basename = getBasename('fine-no-ext?foo=qux'); | ||
expect(basename).toHaveLength(25); | ||
ext = path.extname(basename); | ||
expect(ext).toBe(''); | ||
ext = path.extname(form._uploadPath('super.cr2+dsad')); | ||
basename = getBasename({ filename: 'super.cr2+dsad' }); | ||
expect(basename).toHaveLength(29); | ||
ext = path.extname(basename); | ||
expect(ext).toBe('.cr2'); | ||
ext = path.extname(form._uploadPath('super.bar')); | ||
expect(ext).toBe('.bar'); | ||
basename = getBasename({ filename: 'super.gz' }); | ||
expect(basename).toHaveLength(28); | ||
ext = path.extname(basename); | ||
expect(ext).toBe('.gz'); | ||
ext = path.extname(form._uploadPath('file.aAa')); | ||
basename = getBasename('file.aAa'); | ||
expect(basename).toHaveLength(29); | ||
ext = path.extname(basename); | ||
expect(ext).toBe('.aAa'); | ||
basename = getBasename('file#!@#koh.QxZs?sa=1'); | ||
expect(basename).toHaveLength(30); | ||
ext = path.extname(basename); | ||
expect(ext).toBe('.QxZs'); | ||
}); | ||
@@ -97,2 +115,8 @@ | ||
}); | ||
// test(`${name}: use custom options.filename instead of form._uploadPath`, () => { | ||
// const form = getForm(name, { | ||
// filename: (_) => path.join(__dirname, 'sasa'), | ||
// }); | ||
// }); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
2086008
96
2155
11
3
+ Addedhexoid@^1.0.0
+ Addedhexoid@1.0.0(transitive)