Skip to content

fix: creating a Parse.File with base64 string fails for some encodings #1517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 28, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ParseFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export type FileSource =
};

const base64Regex = new RegExp(
'([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))',
'([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/][AQgw]==)|([0-9a-zA-Z+/]{2}[AEIMQUYcgkosw048]=)|([0-9a-zA-Z+/]{4}))',
'i'
);

Expand Down
14 changes: 13 additions & 1 deletion src/__tests__/ParseFile-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,19 @@ describe('ParseFile', () => {
process.env.PARSE_BUILD = 'node';
});

it('can create files with base64 encoding', () => {
it('can create files with base64 encoding (no padding)', () => {
const file = new ParseFile('parse.txt', { base64: 'YWJj' });
expect(file._source.base64).toBe('YWJj');
expect(file._source.type).toBe('');
});

it('can create files with base64 encoding (1 padding)', () => {
const file = new ParseFile('parse.txt', { base64: 'YWI=' });
expect(file._source.base64).toBe('YWI=');
expect(file._source.type).toBe('');
});

it('can create files with base64 encoding (2 padding)', () => {
const file = new ParseFile('parse.txt', { base64: 'ParseA==' });
expect(file._source.base64).toBe('ParseA==');
expect(file._source.type).toBe('');
Expand Down