Closed
Description
New Issue Checklist
- I am not disclosing a vulnerability.
- I am not just asking a question.
- I have searched through existing issues.
- I can reproduce the issue with the latest versions of Parse Server and the Parse JS SDK.
Issue Description
It is common practice to specify other parameters in the date URI such as ;filename="parse.pdf"
.
I discovered this issue after generating a pdf in the browser and tried to create a new file using Parse.File(...)
.
I created the following test to point out the error:
it('can extract data type from base64 with a filename parameter', () => {
const file = new ParseFile('parse.pdf', {
base64: 'data:application/pdf;filename=parse.pdf;base64,ParseA==',
});
expect(file._source.base64).toBe('ParseA==');
expect(file._source.type).toBe('application/pdf');
});
The main problem is that the currently used regex doesn't take into account that there may be other parameters (such as filename
). It takes into account only charset
.
const dataUriRegexp = /^data:([a-zA-Z]+\/[-a-zA-Z0-9+.]+)(;charset=[a-zA-Z0-9\-\/]*)?;base64,/;
Steps to reproduce
Create a new Parse.File with data starting with data:application/pdf;filename=test.pdf;base64,
Actual Outcome
new Parse.File(...)
throws an error at line 150 in ParseFile.js.
Expected Outcome
new Parse.File(...)
should return a new object even when there are other parameters specified.
Environment
Client
- Parse JS SDK version:
3.4.1
Logs
- n/a