From 102b5e34ad52d067e150913c68898eddd20a4e2d Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sun, 7 Aug 2016 22:08:39 -0700 Subject: [PATCH] Fix: buffer should only be as long as the valid part of a hex string Caught by the new node.js tests --- index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 3b268222..8aa80912 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 }