formstream 1.5.1 → 1.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -92,6 +92,12 @@ fs.stat(filepath, function (err, stat) {
92
92
 
93
93
  ## API Doc
94
94
 
95
+ Field names and filenames use percent encoding for carriage returns (`%0D`),
96
+ line feeds (`%0A`), and double quotes (`%22`) in multipart headers.
97
+ Other characters and field contents remain unchanged.
98
+ The `field()`, `buffer()`, and `stream()` methods throw a `TypeError` synchronously
99
+ if a supplied MIME type contains a carriage return or line feed.
100
+
95
101
  ### formstream([options])
96
102
 
97
103
  Create a form instance.
@@ -104,7 +110,7 @@ Create a form instance.
104
110
 
105
111
  Form - form instance
106
112
 
107
- ### FormStream#field(name, value)
113
+ ### FormStream#field(name, value[, mimeType])
108
114
 
109
115
  Add a normal field to the form.
110
116
 
@@ -112,6 +118,7 @@ Add a normal field to the form.
112
118
 
113
119
  - **name** String - Name of field
114
120
  - **value** String - Value of field
121
+ - ***mimeType*** String - Optional. Content-Type of the field
115
122
 
116
123
  #### Returns
117
124
 
@@ -200,18 +207,45 @@ Emitted when the stream has received no more 'data' events will happen.
200
207
 
201
208
  See [Node.js Documentation](http://nodejs.org/api/stream.html#stream_event_end) for more.
202
209
 
210
+ ## Releasing
211
+
212
+ Maintainers prepare releases through a pull request that updates the version in
213
+ `package.json` and describes the changes in `CHANGELOG.md`. To update the version
214
+ without creating a commit or tag, run `npm version patch --no-git-tag-version`
215
+ (or use `minor`, `major`, or an explicit version).
216
+
217
+ After the PR merges into `master`, `release.yml` compares the package versions
218
+ before and after the push. It publishes only when the version changes. The
219
+ workflow skips versions already on npm, runs the project checks, and publishes
220
+ with npm trusted publishing and provenance. Stable versions use the `latest`
221
+ dist-tag; prerelease versions use `next`.
222
+
223
+ After npm publishing succeeds, the workflow creates a GitHub release with a
224
+ `v<version>` tag at the commit that triggered the workflow and automatically
225
+ generated release notes. Prerelease versions are marked as GitHub prereleases.
226
+ To retry a failed release, rerun the failed workflow in GitHub Actions. If the
227
+ version is already on npm, the workflow still creates the missing GitHub release.
228
+ Existing GitHub releases remain unchanged.
229
+
230
+ Configure the `formstream` package's trusted publisher on npm with these values:
231
+
232
+ - Provider: GitHub Actions
233
+ - Organization: `node-modules`
234
+ - Repository: `formstream`
235
+ - Workflow filename: `release.yml`
236
+ - Environment: leave empty
237
+ - Allow direct publishing with `npm publish`
238
+
239
+ The workflow uses OIDC and does not require an `NPM_TOKEN` or `GIT_TOKEN` secret.
240
+ See the [npm trusted publishing documentation](https://docs.npmjs.com/trusted-publishers/)
241
+ for package configuration instructions.
242
+
203
243
  ## License
204
244
 
205
245
  [MIT](LICENSE)
206
246
 
207
- <!-- GITCONTRIBUTOR_START -->
208
-
209
247
  ## Contributors
210
248
 
211
- |[<img src="https://avatars.githubusercontent.com/u/156269?v=4" width="100px;"/><br/><sub><b>fengmk2</b></sub>](https://github.com/fengmk2)<br/>|[<img src="https://avatars.githubusercontent.com/u/288288?v=4" width="100px;"/><br/><sub><b>xingrz</b></sub>](https://github.com/xingrz)<br/>|[<img src="https://avatars.githubusercontent.com/u/32174276?v=4" width="100px;"/><br/><sub><b>semantic-release-bot</b></sub>](https://github.com/semantic-release-bot)<br/>|[<img src="https://avatars.githubusercontent.com/u/13151189?v=4" width="100px;"/><br/><sub><b>fjc0k</b></sub>](https://github.com/fjc0k)<br/>|[<img src="https://avatars.githubusercontent.com/u/18096247?v=4" width="100px;"/><br/><sub><b>mrspeiser</b></sub>](https://github.com/mrspeiser)<br/>|[<img src="https://avatars.githubusercontent.com/u/985607?v=4" width="100px;"/><br/><sub><b>dead-horse</b></sub>](https://github.com/dead-horse)<br/>|
212
- | :---: | :---: | :---: | :---: | :---: | :---: |
213
- [<img src="https://avatars.githubusercontent.com/u/7326406?v=4" width="100px;"/><br/><sub><b>shaozj</b></sub>](https://github.com/shaozj)<br/>
214
-
215
- This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Wed May 15 2024 00:34:12 GMT+0800`.
249
+ [![Contributors](https://contrib.rocks/image?repo=node-modules/formstream)](https://github.com/node-modules/formstream/graphs/contributors)
216
250
 
217
- <!-- GITCONTRIBUTOR_END -->
251
+ Made with [contributors-img](https://contrib.rocks).
package/lib/formstream.js CHANGED
@@ -35,6 +35,7 @@ Content-Type: image/png\r\n
35
35
 
36
36
  var debug = require('util').debuglog('formstream');
37
37
  var Stream = require('stream');
38
+ var crypto = require('crypto');
38
39
  var parseStream = require('pause-stream');
39
40
  var util = require('util');
40
41
  var mime = require('mime');
@@ -71,15 +72,8 @@ util.inherits(FormStream, Stream);
71
72
  module.exports = FormStream;
72
73
 
73
74
  FormStream.prototype._generateBoundary = function() {
74
- // https://github.com/felixge/node-form-data/blob/master/lib/form_data.js#L162
75
- // This generates a 50 character boundary similar to those used by Firefox.
76
- // They are optimized for boyer-moore parsing.
77
- var boundary = '--------------------------';
78
- for (var i = 0; i < 24; i++) {
79
- boundary += Math.floor(Math.random() * 10).toString(16);
80
- }
81
-
82
- return boundary;
75
+ // https://github.com/form-data/form-data/blob/16e00765342106876f98a1c9703314006c9e937a/lib/form_data.js#L345
76
+ return '--------------------------' + crypto.randomBytes(12).toString('hex');
83
77
  };
84
78
 
85
79
  FormStream.prototype.setTotalStreamSize = function (size) {
@@ -167,14 +161,14 @@ FormStream.prototype.stream = function (name, stream, filename, mimeType, size)
167
161
  mimeType = mime.getType(filename);
168
162
  }
169
163
 
164
+ var leading = this._leading({ name: name, filename: filename }, mimeType);
165
+
170
166
  stream.once('error', this.emit.bind(this, 'error'));
171
167
  // if form stream destroy, also destroy the source stream
172
168
  this.once('destroy', function () {
173
169
  destroy(stream);
174
170
  });
175
171
 
176
- var leading = this._leading({ name: name, filename: filename }, mimeType);
177
-
178
172
  var ps = parseStream().pause();
179
173
  stream.pipe(ps);
180
174
 
@@ -232,12 +226,18 @@ FormStream.prototype._leading = function (disposition, type) {
232
226
 
233
227
  if (disposition) {
234
228
  for (var k in disposition) {
235
- dispositions.push(k + '="' + disposition[k] + '"');
229
+ // Escape multipart names and filenames as in HTML form submissions.
230
+ var value = String(disposition[k]).replace(/\r/g, '%0D').replace(/\n/g, '%0A').replace(/"/g, '%22');
231
+ dispositions.push(k + '="' + value + '"');
236
232
  }
237
233
  }
238
234
 
239
235
  leading.push('Content-Disposition: form-data; ' + dispositions.join('; '));
240
236
  if (type) {
237
+ type = String(type);
238
+ if (/[\r\n]/.test(type)) {
239
+ throw new TypeError('MIME type must not contain CR or LF');
240
+ }
241
241
  leading.push('Content-Type: ' + type);
242
242
  }
243
243
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "formstream",
3
- "version": "1.5.1",
3
+ "version": "1.5.3",
4
4
  "description": "A multipart/form-data encoded stream, helper for file upload.",
5
5
  "main": "lib/formstream.js",
6
6
  "types": "types/formstream.d.ts",
@@ -13,8 +13,7 @@
13
13
  "cov": "egg-bin cov",
14
14
  "ci": "npm run lint && npm run tsd && npm run cov && NODE_DEBUG=formstream npm run cov",
15
15
  "lint": "jshint .",
16
- "tsd": "tsd",
17
- "contributor": "git-contributor"
16
+ "tsd": "tsd"
18
17
  },
19
18
  "repository": {
20
19
  "type": "git",
@@ -40,7 +39,6 @@
40
39
  "connect-multiparty": "1",
41
40
  "egg-bin": "^5.6.1",
42
41
  "express": "^4.16.4",
43
- "git-contributor": "^2.1.5",
44
42
  "jshint": "^2.13.6",
45
43
  "pedding": "1",
46
44
  "should": "4",