From 209cc1bd7233157d9d7061e3f3a95a01ef820316 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sun, 29 Jun 2014 08:28:35 -0700 Subject: [PATCH] Add failing test for base64 newlines issue (#33) --- test/base64-newline.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 test/base64-newline.js diff --git a/test/base64-newline.js b/test/base64-newline.js new file mode 100644 index 0000000..4722aec --- /dev/null +++ b/test/base64-newline.js @@ -0,0 +1,28 @@ +var B = require('../').Buffer +var test = require('tape') + +var data = [ + '', + '' +] + +test('base64 strings with newlines / invalid charaters', function (t) { + // newline in utf8 -- should not be an issue + t.equal( + new B('LS0tCnRpdGxlOiBUaHJlZSBkYXNoZXMgbWFya3MgdGhlIHNwb3QKdGFnczoK', 'base64').toString('utf8'), + '---\ntitle: Three dashes marks the spot\ntags:\n' + ) + + // newline in base64 -- should get stripped + t.equal( + new B('LS0tCnRpdGxlOiBUaHJlZSBkYXNoZXMgbWFya3MgdGhlIHNwb3QKdGFnczoK\nICAtIHlhbWwKICAtIGZyb250LW1hdHRlcgogIC0gZGFzaGVzCmV4cGFuZWQt', 'base64').toString('utf8'), + '---\ntitle: Three dashes marks the spot\ntags:\n - yaml\n - front-matter\n - dashes\nexpaned-' + ) + + // tab characters in base64 - should get stripped + t.equal( + new B('LS0tCnRpdGxlOiBUaHJlZSBkYXNoZXMgbWFya3MgdGhlIHNwb3QKdGFnczoK\t\t\t\tICAtIHlhbWwKICAtIGZyb250LW1hdHRlcgogIC0gZGFzaGVzCmV4cGFuZWQt', 'base64').toString('utf8'), + '---\ntitle: Three dashes marks the spot\ntags:\n - yaml\n - front-matter\n - dashes\nexpaned-' + ) + t.end() +}) -- 2.34.1