Skip to content

Commit

Permalink
fix cases, additionally found by tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gyzerok committed Jun 22, 2020
1 parent 912a513 commit 5175856
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions encodings/utf16.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ Utf16Decoder.prototype.write = function(buf) {
if (this.initialBytesLen < 16) // We need more bytes to use space heuristic (see below)
return '';

if (!Buffer.isBuffer(buf)) {
this.initialBytes = this.initialBytes.map(Buffer.from);
}

// We have enough bytes -> detect endianness.
var buf = Buffer.concat(this.initialBytes),
encoding = detectEncoding(buf, this.options.defaultEncoding);
Expand Down
8 changes: 8 additions & 0 deletions encodings/utf32.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ Utf32Decoder.prototype.write = function(src) {
if (src.length === 0)
return '';

if (!Buffer.isBuffer(src)) {
src = Buffer.from(src);
}

if (this.overflow)
src = Buffer.concat([this.overflow, src]);

Expand Down Expand Up @@ -211,6 +215,10 @@ Utf32AutoDecoder.prototype.write = function(buf) {
if (this.initialBytesLen < 32) // We need more bytes to use space heuristic (see below)
return '';

if (!Buffer.isBuffer(buf)) {
this.initialBytes = this.initialBytes.map(Buffer.from);
}

// We have enough bytes -> detect endianness.
var buf2 = Buffer.concat(this.initialBytes),
encoding = detectEncoding(buf2, this.options.defaultEncoding);
Expand Down

0 comments on commit 5175856

Please sign in to comment.