Skip to content

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

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

Closed
4 tasks done
RazvanCristian opened this issue Mar 29, 2022 · 2 comments · Fixed by #1467
Closed
4 tasks done
Labels
type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@RazvanCristian
Copy link
Contributor

RazvanCristian commented Mar 29, 2022

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
@parse-github-assistant
Copy link

parse-github-assistant bot commented Mar 29, 2022

Thanks for opening this issue!

  • 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.

@RazvanCristian
Copy link
Contributor Author

PR: #1467

@RazvanCristian RazvanCristian changed the title Wrong formatting of a base64 string in accordance to RFC 2397 when calling new Parse.File Wrong processing of a base64 string in accordance to RFC 2397 when calling new Parse.File Mar 31, 2022
@mtrezza mtrezza linked a pull request Apr 4, 2022 that will close this issue
4 tasks
@mtrezza mtrezza added the type:bug Impaired feature or lacking behavior that is likely assumed label Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants