Skip to content

Commit 3fad3ae

Browse files
author
Ben
authored
Update ParseFile.js
Fixed bug when base64 string is too long RangeError: Maximum call stack size exceeded at RegExp.exec (native) at new e (http://localhost:2052/scripts/parse-1.6.14.min.js:13:25178)
1 parent 117c091 commit 3fad3ae

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/ParseFile.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,20 @@ 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+
try {
104+
window.atob(commaIndex === -1?data.base64:data.base64.slice(commaIndex + 1));
105+
return true;
106+
} catch(e) {
107+
throw new TypeError('Cannot create a Parse.File with that data.');
108+
}
109+
110+
if (commaIndex !== -1) {
111+
var matches = dataUriRegexp.slice(100).exec(data.base64);
104112
// if data URI with type and charset, there will be 4 matches.
105113
this._source = {
106114
format: 'base64',
107-
base64: matches.length === 4 ? matches[3] : matches[2],
115+
base64: data.base64.slice(commaIndex + 1),
108116
type: matches[1]
109117
};
110118
} else {

0 commit comments

Comments
 (0)