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

fix: parse meta with unnecessary semicolons #18

Merged
merged 1 commit into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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());
});
});