Skip to content

Commit

Permalink
Fix bug with .fill bytes > 127 from other encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
emilbayes committed Nov 7, 2016
1 parent bb6ff63 commit 4e5c452
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
9 changes: 9 additions & 0 deletions test/base64.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

0 comments on commit 4e5c452

Please sign in to comment.