Skip to content

Commit 131ae5e

Browse files
Mallikarjun-0ljharb
authored andcommitted
[Fix] validate boundary type in setBoundary() method
1 parent 8bf2492 commit 131ae5e

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

lib/form_data.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,13 @@ FormData.prototype.getHeaders = function (userHeaders) {
315315
return formHeaders;
316316
};
317317

318+
FormData.prototype.setBoundary = function (boundary) {
319+
if (typeof boundary !== 'string') {
320+
throw new TypeError('FormData boundary must be a string');
321+
}
322+
this._boundary = boundary;
323+
};
324+
318325
FormData.prototype.getBoundary = function () {
319326
if (!this._boundary) {
320327
this._generateBoundary();
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
3+
var common = require('../common');
4+
var assert = common.assert;
5+
6+
var FormData = require(common.dir.lib + '/form_data');
7+
8+
(function testSetBoundary() {
9+
var userBoundary = '---something';
10+
var form = new FormData();
11+
form.setBoundary(userBoundary);
12+
13+
assert.equal(form.getBoundary(), userBoundary);
14+
}());
15+
16+
(function testUniqueBoundaryPerFormAfterSet() {
17+
var userBoundary = '---something';
18+
var formA = new FormData();
19+
formA.setBoundary(userBoundary);
20+
21+
var formB = new FormData();
22+
23+
assert.equal(formA.getBoundary(), userBoundary);
24+
assert.notEqual(formA.getBoundary(), formB.getBoundary());
25+
}());
26+
27+
(function testSetBoundaryWithNonString() {
28+
var form = new FormData();
29+
30+
var invalidValues = [123, null, undefined, { value: 123 }, ['---something']];
31+
32+
invalidValues.forEach(function (value) {
33+
assert.throws(function () {
34+
form.setBoundary(value);
35+
}, TypeError);
36+
});
37+
}());

0 commit comments

Comments
 (0)