Skip to content

Wrong processing of a base64 string in accordance to RFC 2397 when calling new Parse.File #1466

Closed
@RazvanCristian

Description

@RazvanCristian

New Issue Checklist

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');
});

With the following results:
image

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:bugImpaired feature or lacking behavior that is likely assumed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions