Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
gurgunday committed Aug 24, 2023
1 parent 573d4cb commit c04fe5b
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/types/multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,20 @@ function Multipart (boy, cfg) {
}).on('error', function (err) {
boy.emit('error', err)
}).on('finish', function () {
if (self._nparts === 0 && self._boundaryNotFound) {
boy.emit('error', new Error('Unexpected end of multipart data'))
}
finished = true
checkFinished()
})
}

Multipart.prototype.write = function (chunk, cb) {
let r
if ((r = this.parser.write(chunk)) && !this._pause) {
if (this._boundaryNotFound && (this._nparts !== 0 || this._checkBoundary(chunk))) {
this._boundaryNotFound = false
}
if (this._boundaryNotFound && (this._nparts !== 0 || this._checkBoundary(chunk))) {
this._boundaryNotFound = false
}
const r = this.parser.write(chunk)
if (r && !this._pause) {
cb()
} else {
this._needDrain = !r
Expand All @@ -285,9 +288,6 @@ Multipart.prototype.write = function (chunk, cb) {

Multipart.prototype.end = function () {
const self = this
if (self._boundaryNotFound) {
self._boy.emit('error', new Error('Unexpected end of multipart data'))
}
if (self._nparts === 0 && !self._boy._done) {
process.nextTick(function () {
self._boy._done = true
Expand All @@ -304,8 +304,8 @@ Multipart.prototype._checkBoundary = function (chunk) {
if (
chunk[0] !== DASH /* - */ ||
chunk[1] !== DASH /* - */ ||
chunk[boundaryLen] !== DASH /* - */ ||
chunk[boundaryLen + 1] !== DASH /* - */
chunk[2 + boundaryLen] !== DASH /* - */ ||
chunk[2 + boundaryLen + 1] !== DASH /* - */
) {
return false
}
Expand Down

0 comments on commit c04fe5b

Please sign in to comment.