From e07475b60ceaebaede6e90687600423be9541d91 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 8 Aug 2013 14:01:59 -0400 Subject: [PATCH] ignore whitespace. more compatible with node.js Buffer --- index.js | 2 +- test/buffer.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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(); +}); -- 2.34.1