1 |
3a515b92
|
cagy
|
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
|
2 |
|
|
var B = require('../').Buffer
|
3 |
|
|
var test = require('tape')
|
4 |
|
|
|
5 |
|
|
test('base64: ignore whitespace', function (t) {
|
6 |
|
|
var text = '\n YW9ldQ== '
|
7 |
|
|
var buf = new B(text, 'base64')
|
8 |
|
|
t.equal(buf.toString(), 'aoeu')
|
9 |
|
|
t.end()
|
10 |
|
|
})
|
11 |
|
|
|
12 |
|
|
test('base64: strings without padding', function (t) {
|
13 |
|
|
t.equal((new B('YW9ldQ', 'base64').toString()), 'aoeu')
|
14 |
|
|
t.end()
|
15 |
|
|
})
|
16 |
|
|
|
17 |
|
|
test('base64: newline in utf8 -- should not be an issue', function (t) {
|
18 |
|
|
t.equal(
|
19 |
|
|
new B('LS0tCnRpdGxlOiBUaHJlZSBkYXNoZXMgbWFya3MgdGhlIHNwb3QKdGFnczoK', 'base64').toString('utf8'),
|
20 |
|
|
'---\ntitle: Three dashes marks the spot\ntags:\n'
|
21 |
|
|
)
|
22 |
|
|
t.end()
|
23 |
|
|
})
|
24 |
|
|
|
25 |
|
|
test('base64: newline in base64 -- should get stripped', function (t) {
|
26 |
|
|
t.equal(
|
27 |
|
|
new B('LS0tCnRpdGxlOiBUaHJlZSBkYXNoZXMgbWFya3MgdGhlIHNwb3QKdGFnczoK\nICAtIHlhbWwKICAtIGZyb250LW1hdHRlcgogIC0gZGFzaGVzCmV4cGFuZWQt', 'base64').toString('utf8'),
|
28 |
|
|
'---\ntitle: Three dashes marks the spot\ntags:\n - yaml\n - front-matter\n - dashes\nexpaned-'
|
29 |
|
|
)
|
30 |
|
|
t.end()
|
31 |
|
|
})
|
32 |
|
|
|
33 |
|
|
test('base64: tab characters in base64 - should get stripped', function (t) {
|
34 |
|
|
t.equal(
|
35 |
|
|
new B('LS0tCnRpdGxlOiBUaHJlZSBkYXNoZXMgbWFya3MgdGhlIHNwb3QKdGFnczoK\t\t\t\tICAtIHlhbWwKICAtIGZyb250LW1hdHRlcgogIC0gZGFzaGVzCmV4cGFuZWQt', 'base64').toString('utf8'),
|
36 |
|
|
'---\ntitle: Three dashes marks the spot\ntags:\n - yaml\n - front-matter\n - dashes\nexpaned-'
|
37 |
|
|
)
|
38 |
|
|
t.end()
|
39 |
|
|
})
|
40 |
|
|
|
41 |
|
|
test('base64: invalid non-alphanumeric characters -- should be stripped', function (t) {
|
42 |
|
|
t.equal(
|
43 |
|
|
new B('!"#$%&\'()*,.:;<=>?@[\\]^`{|}~', 'base64').toString('utf8'),
|
44 |
|
|
''
|
45 |
|
|
)
|
46 |
|
|
t.end()
|
47 |
|
|
})
|