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

Commit

Permalink
Parse meta with unnecessary semicolons (#18)
Browse files Browse the repository at this point in the history
Fixes #17.
  • Loading branch information
melusc committed Jan 13, 2023
1 parent 5059522 commit a8c8b7e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function dataUriToBuffer(uri: string): MimeBuffer {
for (let i = 1; i < meta.length; i++) {
if (meta[i] === 'base64') {
base64 = true;
} else {
} else if(meta[i]) {
typeFull += `;${ meta[i]}`;
if (meta[i].indexOf('charset=') === 0) {
charset = meta[i].substring(8);
Expand Down
9 changes: 9 additions & 0 deletions test/data-uri-to-buffer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,13 @@ describe('data-uri-to-buffer', function() {
assert.equal('UTF-8', buf.charset);
assert.equal('abc', buf.toString());
});

it('should parse meta with unnecessary semicolons', function() {
var uri = 'data:text/plain;;charset=UTF-8;;;base64;;;;,YWJj';
var buf = dataUriToBuffer(uri);
assert.equal('text/plain', buf.type);
assert.equal('text/plain;charset=UTF-8', buf.typeFull);
assert.equal('UTF-8', buf.charset);
assert.equal('abc', buf.toString());
});
});

0 comments on commit a8c8b7e

Please sign in to comment.