Skip to content

Commit

Permalink
fix: creating a Parse.File with base64 string fails for some encodings (
Browse files Browse the repository at this point in the history
  • Loading branch information
justinlettau authored Jul 28, 2022
1 parent fc79281 commit 0439862
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
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

0 comments on commit 0439862

Please sign in to comment.