Skip to content

Commit 41a709d

Browse files
authored
Merge pull request #294 from benjaminmcdonald/patch-1
Update ParseFile.js
2 parents aabbfcd + 040e32f commit 41a709d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/ParseFile.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export type FileSource = {
2424
};
2525

2626
var dataUriRegexp =
27-
/^data:([a-zA-Z]*\/[a-zA-Z+.-]*);(charset=[a-zA-Z0-9\-\/\s]*,)?base64,(\S+)/;
27+
/^data:([a-zA-Z]*\/[a-zA-Z+.-]*);(charset=[a-zA-Z0-9\-\/\s]*,)?base64,/;
2828

2929
function b64Digit(number: number): string {
3030
if (number < 26) {
@@ -99,12 +99,14 @@ export default class ParseFile {
9999
type: specifiedType
100100
};
101101
} else if (data && data.hasOwnProperty('base64')) {
102-
var matches = dataUriRegexp.exec(data.base64);
103-
if (matches && matches.length > 0) {
102+
var commaIndex = data.base64.indexOf(',');
103+
104+
if (commaIndex !== -1) {
105+
var matches = dataUriRegexp.exec(data.base64.slice(0, commaIndex + 1));
104106
// if data URI with type and charset, there will be 4 matches.
105107
this._source = {
106108
format: 'base64',
107-
base64: matches.length === 4 ? matches[3] : matches[2],
109+
base64: data.base64.slice(commaIndex + 1),
108110
type: matches[1]
109111
};
110112
} else {

0 commit comments

Comments
 (0)