Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

base64.js 1.6KB

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