Skip to content

Commit

Permalink
Fix: buffer should only be as long as the valid part of a hex string
Browse files Browse the repository at this point in the history
Caught by the new node.js tests
  • Loading branch information
feross committed Aug 8, 2016
1 parent 2dae873 commit 102b5e3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,12 @@ function fromString (that, string, encoding) {
var length = byteLength(string, encoding) | 0
that = createBuffer(that, length)

that.write(string, encoding)
var actual = that.write(string, encoding)

if (actual !== length) {
that = that.slice(0, actual)
}

return that
}

Expand Down

0 comments on commit 102b5e3

Please sign in to comment.