inexorabletash / text-encoding

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

throw TypeError on "GBK" #38

Closed honger05 closed 9 years ago

honger05 commented 9 years ago

Hi!, I'm a Chinese.

when I use the library like :

var dataString = '"操作","运单状态","运单号","货物名称","件数","寄件客户","寄件人电话","寄件地址","收件客户","收件人电话","收件地址","寄件网点","目的地","目的网点","重量(kg)","体积(M³)","到货时间","包装","到付款","代收货款","回付金额","寄货日期","回单号","回单","回单备注","提货密码"'

var textEncoder = new CustomTextEncoder('gbk', {NONSTANDARD_allowLegacyEncoding: true});

var csvContentEncoded = textEncoder.encode([dataString]);

var blob = new Blob([csvContentEncoded], {type: 'text/csv;charset=gbk;'});

Uncaught TypeError: The code point 179 could not be encoded.

some words could not be encoded ?

I found that 'M³' in the words caused, 'M' is ok, can support 'M³' ?

inexorabletash commented 9 years ago

Correct. The Unicode character ³ (U+00B3) can't be encoded in GBK.

The ICU tool iconv has the same behavior. If you have a Linux or OSX machine handy, put your data into a file (as utf-8) and then try:

iconv -f utf-8 -t gbk < file

I get e.g.

var dataString = '"????","?˵?״̬","?˵???","????????","????","?ļ??ͻ?","?ļ??˵绰","?ļ???ַ","?ռ??ͻ?","?ռ??˵绰","?ռ???ַ","?ļ?????","Ŀ?ĵ?","Ŀ??????","????(kg)","???(M
iconv: (stdin):1:182: cannot convert