Skip to content

Bad encoding experience #456

@legendtang

Description

@legendtang

Node version:

6.1.0

ShellJS version (the most recent version/Github branch you see the bug on):

0.7.0

Operating system:

Windows 10

Description of the bug:

Due to Node.js default behavior about encoding, all standard output will be transformed hard to utf-8. However, the default encoding of CMD is based on default lang of Windows, which means once you send command to non-utf8 terminal you will get non-utf8 output with utf-8 buffer string. That would probably irreversible, at least in my case in Chinese GB2312 (or Windows-936) encoding. Using iconv cannot revert the output again.

Example ShellJS command to reproduce the error:

sh.exec('dir', function(code, stdout, stderr) {
     console.log(stdout)
}

The output will be something like this:

 ������ D �еľ�û�б�ǩ��
 ���������

2016/06/06  13:55    <DIR>          .
2016/06/06  13:55    <DIR>          ..
2016/05/30  17:40                27 .babelrc
2016/06/03  13:37                95 .editorconfig
2016/05/30  17:40                29 .gitignore
2016/06/02  17:02             1,340 index.js
2016/05/31  11:27            93,035 jquery.min.js
2016/06/06  15:44    <DIR>          node_modules
2016/06/06  13:55             2,664 package.json
2016/05/19  13:07                39 README.md
2016/05/30  18:50    <DIR>          statics
2016/05/30  18:50    <DIR>          webpack-config
               7 ���ļ�         97,229 �ֽ�
               9 ��Ŀ¼ 311,094,530,048 �����ֽ�

If you manually convert to GBK, that will be:


2016/06/06  13:55    <DIR>          .
2016/06/06  13:55    <DIR>          ..
2016/05/30  17:40                27 .babelrc
2016/06/03  13:37                95 .editorconfig
2016/05/30  17:40                29 .gitignore
2016/06/02  17:02             1,340 index.js
2016/05/31  11:27            93,035 jquery.min.js
2016/06/06  15:44    <DIR>          node_modules
2016/06/06  13:55             2,664 package.json
2016/05/19  13:07                39 README.md
2016/05/30  18:50    <DIR>          statics
2016/05/30  18:50    <DIR>          webpack-config
               7 锟斤拷锟侥硷拷         97,229 锟街斤拷
               9 锟斤拷目录 311,094,530,048 锟斤拷锟斤拷锟街斤拷

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixBug/defect, or a fix for such a problemhelp wanted

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions