From: Feross Aboukhadijeh Date: Mon, 8 Aug 2016 05:08:39 +0000 (-0700) Subject: Fix: buffer should only be as long as the valid part of a hex string X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=102b5e34ad52d067e150913c68898eddd20a4e2d;p=buffer.git Fix: buffer should only be as long as the valid part of a hex string Caught by the new node.js tests --- diff --git a/index.js b/index.js index 3b26822..8aa8091 100644 --- a/index.js +++ b/index.js @@ -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 }