Andreas Köberle
Andreas Köberle

Reputation: 110982

Whats the right way to encode an umlaut in a dataURI

I have a small script that let the user save a CSV file using dataURI. Unfortunately there are some problems with german umlauts, so Käufe will become Käufe. The href with the dataURI is created like this:

'data:application/csv;charset=utf-8,' + encodeURIComponent(csvString)

Upvotes: 0

Views: 448

Answers (1)

deceze
deceze

Reputation: 522432

It's very likely not a problem of the encoding in the URL, but of whoever is interpreting that data later not understanding that it's encoded in UTF-8 and interpreting it in Latin-1 instead. There is no "right way" to encode non-ASCII characters in a URL. URLs can only consist of a subset of ASCII characters, period. For anything else there's the percent encoding method to encode arbitrary bytes to the %xx format. What encoding those bytes represent is entirely up to you and is entirely up to the recipient to interpret in the correct encoding.

Upvotes: 1

Related Questions