Skip to content

Commit

Permalink
Correctly validate the mime-type part of data-uris. Fixes #1607.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marsup committed Nov 11, 2018
1 parent a483e18 commit 1c9d2bb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/types/string/index.js
Expand Up @@ -471,7 +471,7 @@ internals.String = class extends Any {

dataUri(dataUriOptions = {}) {

const regex = /^data:[\w\/\+]+;((charset=[\w-]+|base64),)?(.*)$/;
const regex = /^data:[\w+.-]+\/[\w+.-]+;((charset=[\w-]+|base64),)?(.*)$/;

// Determine if padding is required.
const paddingRequired = dataUriOptions.paddingRequired === false ?
Expand Down
3 changes: 2 additions & 1 deletion test/types/string.js
Expand Up @@ -10222,7 +10222,8 @@ describe('string', () => {
}]
}],
['data:image/png;base64,YW55IGNhcm5hbCBwbGVhc3VyZS4=', true],
['data:image/png;charset=utf-8,=YW55IGNhcm5hbCBwbGVhc3VyZS', true]
['data:image/png;charset=utf-8,=YW55IGNhcm5hbCBwbGVhc3VyZS', true],
['data:text/x-script.phyton;charset=utf-8,=YW55IGNhcm5hbCBwbGVhc3VyZS', true]
]);
});

Expand Down

0 comments on commit 1c9d2bb

Please sign in to comment.