Skip to content

Commit 5b4108b

Browse files
committed
fix: creating a Parse.File with base64 string fails
Closes #1510
1 parent 23d3e7d commit 5b4108b

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/ParseFile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export type FileSource =
4343
};
4444

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

src/__tests__/ParseFile-test.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,21 @@ describe('ParseFile', () => {
6060
process.env.PARSE_BUILD = 'node';
6161
});
6262

63-
it('can create files with base64 encoding', () => {
64-
const file = new ParseFile('parse.txt', { base64: 'ParseA==' });
65-
expect(file._source.base64).toBe('ParseA==');
63+
it('can create files with base64 encoding (no padding)', () => {
64+
const file = new ParseFile('parse.txt', { base64: 'YWJj' });
65+
expect(file._source.base64).toBe('YWJj');
6666
expect(file._source.type).toBe('');
6767
});
6868

69-
it('can create files with base64 encoding (no padding)', () => {
70-
const file = new ParseFile('parse.txt', { base64: 'SGVsbG8gV29ybGQh' });
71-
expect(file._source.base64).toBe('SGVsbG8gV29ybGQh');
69+
it('can create files with base64 encoding (1 padding)', () => {
70+
const file = new ParseFile('parse.txt', { base64: 'YWI=' });
71+
expect(file._source.base64).toBe('YWI=');
72+
expect(file._source.type).toBe('');
73+
});
74+
75+
it('can create files with base64 encoding (2 padding)', () => {
76+
const file = new ParseFile('parse.txt', { base64: 'ParseA==' });
77+
expect(file._source.base64).toBe('ParseA==');
7278
expect(file._source.type).toBe('');
7379
});
7480

0 commit comments

Comments
 (0)