Skip to content
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

dataUrlToBlob ignores type parameters and assumes base64-encoding #62

Open
Treora opened this issue Aug 12, 2020 · 1 comment
Open

dataUrlToBlob ignores type parameters and assumes base64-encoding #62

Treora opened this issue Aug 12, 2020 · 1 comment
Labels

Comments

@Treora
Copy link
Contributor

Treora commented Aug 12, 2020

As remarked in #61:

a quick look at this library’s dataUrlToBlob() implementation reveals however that it throws away all of the media type parameters! And blindly assumes base64 encoding.

Current implementation:

export function dataURLToBlob (dataURL: string): Blob {
  var type = dataURL.match(/data:([^;]+)/)[1]
  var base64 = dataURL.replace(/^[^,]+,/, '')

  var buff = binaryStringToArrayBuffer(atob(base64))
  return createBlob([buff], { type: type })
}

Issues:

  • A data url without ;base64 appended to the media type should just percent-decode the data.

  • The type should include its parameters; for example, in text/plain;charset=iso-8859-5 (used with or without the base64-encoding), dropping the charset parameter might result in problems when decoding the blob’s data.

@nolanlawson
Copy link
Owner

Yep, this is true! I assumed base64 encoding for data URLs (for both input and output).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants