From 4e5c4526f4c29201fa833a89d8fe2bf15ebb18e5 Mon Sep 17 00:00:00 2001 From: Emil Bay Date: Mon, 7 Nov 2016 17:55:57 +1030 Subject: [PATCH] Fix bug with .fill bytes > 127 from other encoding --- index.js | 2 +- test/base64.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 7baf22a..5cbf37f 100644 --- a/index.js +++ b/index.js @@ -1544,7 +1544,7 @@ Buffer.prototype.fill = function fill (val, start, end, encoding) { } else { var bytes = Buffer.isBuffer(val) ? val - : utf8ToBytes(new Buffer(val, encoding).toString()) + : new Buffer(val, encoding) var len = bytes.length for (i = 0; i < end - start; ++i) { this[i + start] = bytes[i % len] diff --git a/test/base64.js b/test/base64.js index 9513b25..bb1bf6a 100644 --- a/test/base64.js +++ b/test/base64.js @@ -44,3 +44,12 @@ test('base64: invalid non-alphanumeric characters -- should be stripped', functi ) t.end() }) + +test('base64: high byte', function (t) { + var highByte = Buffer.from([128]) + t.deepEqual( + B.alloc(1, highByte.toString('base64'), 'base64'), + highByte + ) + t.end() +}) -- 2.34.1