Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

Fix utf-8 support for dataUri base64 #14

Closed
wants to merge 1 commit into from

Conversation

xiaoxiangmoe
Copy link
Contributor

@xiaoxiangmoe xiaoxiangmoe commented Dec 14, 2019

close #13

@lydell

@xiaoxiangmoe xiaoxiangmoe force-pushed the master branch 3 times, most recently from 1c871c5 to d63937e Compare December 14, 2019 09:50
Copy link
Owner

@lydell lydell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pull request!

Can you add tests for this? (I'm sorry, the tests are super old and horrible to work with, but it would be nice having tests for this.)

lib/source-map-resolve-node.js Outdated Show resolved Hide resolved
.map(function(x) {
return x.slice('charset='.length)
})
.pop() || defaultCharset
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know what happens if charset is provided multiple times? Is it an error? Does the first one win? The last one?

I also think we should do something like this:

var dataUriRegex = /^data:([^,;]*)(?:;([^,;]+))?(?:,(.*))?$/
var mimeType = dataUri[1]
var parameters = (dataUri[2] || "").split(";")
var encoded = dataUri[3] || ""
var charsetRegex = /^charset=(.+)$/
var charset = parameters.reduce(function(result, param) {
  var match = charsetRegex.exec(param)
  return match ? match[1] : result
}, "us-ascii")

// ...

  parameters[parameters.length - 1] === "base64" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first one win in Firefox and chrome.
and more, https://tools.ietf.org/html/rfc8259#section-8.1 only allow use utf-8. maybe we could ignore charset and always use utf-8

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always using utf-8 sounds good to me!

Copy link
Contributor Author

@xiaoxiangmoe xiaoxiangmoe Dec 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we check charset and console.warn or throw new Error if charset is not utf-8?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think that’s necessary. I think we can just assume utf-8.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lydell Hi,Do you have time to add a test?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the reminder! I’m working on it now.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#15

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lydell you can push to my repo now.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, but I’m too lazy to move back over here now.

@xiaoxiangmoe xiaoxiangmoe changed the title Add charset support for dataUri base64 Fix utf-8 support for dataUri base64 Dec 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Garbled characters appear when sourcesContent contains Chinese characters
2 participants