inexorabletash / text-encoding

Polyfill for the Encoding Living Standard's API
Other
722 stars 267 forks source link

Encode Chinese Problem #74

Closed Nitromethane closed 7 years ago

Nitromethane commented 7 years ago
<script type="text/javascript">
        var csvContent = 'éà; ça; 12\nà@€; çï; 13中文',
            textEncoder = new CustomTextEncoder('windows-1252', {NONSTANDARD_allowLegacyEncoding: true}),
            fileName = 'some-data.csv';

        var a = document.getElementById('download-csv');
        a.addEventListener('click', function(e) {
            var csvContentEncoded = textEncoder.encode([csvContent]);
            var blob = new Blob([csvContentEncoded], {type: 'text/csv;charset=windows-1252;'});
            saveAs(blob, fileName);
            e.preventDefault();
        });
</script>

this will cause a problem;

encoding.js:273 Uncaught TypeError: The code point 20013 could not be encoded. at encoderError (encoding.js:273) at SingleByteEncoder.handler (encoding.js:1438) at TextEncoder.encode (encoding.js:1122) at HTMLAnchorElement. (example.html:21)

inexorabletash commented 7 years ago

The windows-1252 encoding only handles Western European scripts. The characters 中文 can't be encoded in windows-1252, hence the error.

What behavior are you expecting?

On Aug 15, 2017, at 12:33 AM, 连_欣 notifications@github.com wrote:

this will cause a problem;

encoding.js:273 Uncaught TypeError: The code point 20013 could not be encoded. at encoderError (encoding.js:273) at SingleByteEncoder.handler (encoding.js:1438) at TextEncoder.encode (encoding.js:1122) at HTMLAnchorElement. (example.html:21)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

Ruffio commented 7 years ago

@Nitromethane do you have an answer to the question?

inexorabletash commented 7 years ago

I think there was just an understanding of how character encodings work. Closing, pending further data.