]> zoso.dev Git - buffer.git/commitdiff
Fix: buffer should only be as long as the valid part of a hex string
authorFeross Aboukhadijeh <feross@feross.org>
Mon, 8 Aug 2016 05:08:39 +0000 (22:08 -0700)
committerFeross Aboukhadijeh <feross@feross.org>
Mon, 8 Aug 2016 05:08:39 +0000 (22:08 -0700)
Caught by the new node.js tests

index.js

index 3b2682228cf6d904cfbb36a0ae57c13d1013ac88..8aa809126d81c1f27f395ce51f13229867d88798 100644 (file)
--- 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
 }