Skip to content
This repository was archived by the owner on May 5, 2023. It is now read-only.

Commit a8c8b7e

Browse files
authored
Parse meta with unnecessary semicolons (#18)
Fixes #17.
1 parent 5059522 commit a8c8b7e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function dataUriToBuffer(uri: string): MimeBuffer {
3737
for (let i = 1; i < meta.length; i++) {
3838
if (meta[i] === 'base64') {
3939
base64 = true;
40-
} else {
40+
} else if(meta[i]) {
4141
typeFull += `;${ meta[i]}`;
4242
if (meta[i].indexOf('charset=') === 0) {
4343
charset = meta[i].substring(8);

test/data-uri-to-buffer.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,13 @@ describe('data-uri-to-buffer', function() {
173173
assert.equal('UTF-8', buf.charset);
174174
assert.equal('abc', buf.toString());
175175
});
176+
177+
it('should parse meta with unnecessary semicolons', function() {
178+
var uri = 'data:text/plain;;charset=UTF-8;;;base64;;;;,YWJj';
179+
var buf = dataUriToBuffer(uri);
180+
assert.equal('text/plain', buf.type);
181+
assert.equal('text/plain;charset=UTF-8', buf.typeFull);
182+
assert.equal('UTF-8', buf.charset);
183+
assert.equal('abc', buf.toString());
184+
});
176185
});

0 commit comments

Comments
 (0)