Skip to content

Commit 8d8e469

Browse files
Mallikarjun-0ljharb
authored andcommitted
[Fix] validate boundary type in setBoundary() method
1 parent 837b8a1 commit 8d8e469

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

lib/form_data.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,9 @@ FormData.prototype.getHeaders = function (userHeaders) {
302302
};
303303

304304
FormData.prototype.setBoundary = function (boundary) {
305+
if (typeof boundary !== 'string') {
306+
throw new TypeError('FormData boundary must be a string');
307+
}
305308
this._boundary = boundary;
306309
};
307310

test/integration/test-set-boundary.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ var FormData = require(common.dir.lib + '/form_data');
2424
assert.notEqual(formA.getBoundary(), formB.getBoundary());
2525
}());
2626

27-
(function testsetBoundaryWithNonString_preExistingBehavior() {
27+
(function testSetBoundaryWithNonString() {
2828
var form = new FormData();
2929

30-
var nonStringValues = [123, { value: 123 }, ['---something']];
31-
nonStringValues.forEach(function (value) {
32-
form.setBoundary(value);
33-
assert.equal(form.getBoundary(), value);
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);
3436
});
3537
}());

0 commit comments

Comments
 (0)