Skip to content

Commit 70bbaa0

Browse files
Mallikarjun-0ljharb
authored andcommitted
[Fix] validate boundary type in setBoundary() method
1 parent b22a64e commit 70bbaa0

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

lib/form_data.js

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

317317
FormData.prototype.setBoundary = function (boundary) {
318+
if (typeof boundary !== 'string') {
319+
throw new TypeError('FormData boundary must be a string');
320+
}
318321
this._boundary = boundary;
319322
};
320323

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)