From: Andrew Kelley Date: Thu, 8 Aug 2013 18:01:59 +0000 (-0400) Subject: ignore whitespace. more compatible with node.js Buffer X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=e07475b60ceaebaede6e90687600423be9541d91;p=buffer.git ignore whitespace. more compatible with node.js Buffer --- diff --git a/index.js b/index.js index 7d95278..ad42d41 100644 --- a/index.js +++ b/index.js @@ -470,7 +470,7 @@ function asciiToBytes(str) { } function base64ToBytes(str) { - return require("base64-js").toByteArray(str); + return require("base64-js").toByteArray(str.trim()); } function blitBuffer(src, dst, offset, length) { diff --git a/test/buffer.js b/test/buffer.js index f431cc3..b539bc3 100644 --- a/test/buffer.js +++ b/test/buffer.js @@ -232,3 +232,11 @@ test('copy() empty buffer with sourceEnd=0', function (t) { t.equal(destination.readUInt8(0), 43); t.end(); }); + +test('base64 ignore whitespace', function(t) { + t.plan(1); + var text = "\n YW9ldQ== "; + var buf = new B(text, 'base64'); + t.equal(buf.toString(), 'aoeu'); + t.end(); +});