]> zoso.dev Git - buffer.git/commitdiff
Add failing test for base64 newlines issue (#33)
authorFeross Aboukhadijeh <feross@feross.org>
Sun, 29 Jun 2014 15:28:35 +0000 (08:28 -0700)
committerFeross Aboukhadijeh <feross@feross.org>
Sun, 29 Jun 2014 15:28:35 +0000 (08:28 -0700)
test/base64-newline.js [new file with mode: 0644]

diff --git a/test/base64-newline.js b/test/base64-newline.js
new file mode 100644 (file)
index 0000000..4722aec
--- /dev/null
@@ -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()
+})