data-uri-to-buffer
Advanced tools
Comparing version 0.0.1 to 0.0.2
0.0.2 / 2014-01-08 | ||
================== | ||
* index: use unescape() instead of decodeURIComponent() | ||
* test: add more tests from Mozilla | ||
0.0.1 / 2014-01-02 | ||
@@ -3,0 +9,0 @@ ================== |
@@ -42,3 +42,3 @@ | ||
// get the encoded data portion and decode URI-encoded chars | ||
var data = decodeURIComponent(parts[1]); | ||
var data = unescape(parts[1]); | ||
@@ -45,0 +45,0 @@ var encoding = base64 ? 'base64' : 'ascii'; |
{ | ||
"name": "data-uri-to-buffer", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Generate a Buffer instance from a Data URI string", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -43,2 +43,53 @@ | ||
// the next 4 tests are from: | ||
// https://bug161965.bugzilla.mozilla.org/attachment.cgi?id=94670&action=view | ||
it('should decode "ISO-8859-8 in Base64" URIs', function () { | ||
var uri = 'data:text/plain;charset=iso-8859-8-i;base64,+ezl7Q=='; | ||
var buf = dataUriToBuffer(uri); | ||
assert.equal('text/plain', buf.type); | ||
assert.equal('iso-8859-8-i', buf.charset); | ||
assert.equal(4, buf.length); | ||
assert.equal(0xf9, buf[0]); | ||
assert.equal(0xec, buf[1]); | ||
assert.equal(0xe5, buf[2]); | ||
assert.equal(0xed, buf[3]); | ||
}); | ||
it('should decode "ISO-8859-8 in URL-encoding" URIs', function () { | ||
var uri = 'data:text/plain;charset=iso-8859-8-i,%f9%ec%e5%ed'; | ||
var buf = dataUriToBuffer(uri); | ||
assert.equal('text/plain', buf.type); | ||
assert.equal('iso-8859-8-i', buf.charset); | ||
assert.equal(4, buf.length); | ||
assert.equal(0xf9, buf[0]); | ||
assert.equal(0xec, buf[1]); | ||
assert.equal(0xe5, buf[2]); | ||
assert.equal(0xed, buf[3]); | ||
}); | ||
it('should decode "UTF-8 in Base64" URIs', function () { | ||
var uri = 'data:text/plain;charset=UTF-8;base64,16nXnNeV150='; | ||
var buf = dataUriToBuffer(uri); | ||
assert.equal('text/plain', buf.type); | ||
assert.equal('UTF-8', buf.charset); | ||
assert.equal(8, buf.length); | ||
assert.equal('שלום', buf.toString('utf8')); | ||
}); | ||
it('should decode "UTF-8 in URL-encoding" URIs', function () { | ||
var uri = 'data:text/plain;charset=UTF-8,%d7%a9%d7%9c%d7%95%d7%9d'; | ||
var buf = dataUriToBuffer(uri); | ||
assert.equal('text/plain', buf.type); | ||
assert.equal('UTF-8', buf.charset); | ||
assert.equal(8, buf.length); | ||
assert.equal('שלום', buf.toString('utf8')); | ||
}); | ||
// this next one is from Wikipedia IIRC | ||
it('should decode "base64" Data URIs with newlines', function () { | ||
@@ -56,2 +107,10 @@ var uri = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA\n' + | ||
it('should decode a plain-text URI with a space character in it', function () { | ||
var uri = 'data:,foo bar'; | ||
var buf = dataUriToBuffer(uri); | ||
assert.equal('text/plain', buf.type); | ||
assert.equal('foo bar', buf.toString()); | ||
}); | ||
}); |
7670
130