Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoding.Default可能导致的问题 #1

Open
tylerlong opened this issue Jun 17, 2014 · 1 comment
Open

Encoding.Default可能导致的问题 #1

tylerlong opened this issue Jun 17, 2014 · 1 comment

Comments

@tylerlong
Copy link

源码中有如下一段:

private byte[] _bytes(string s) {
    return Encoding.Default.GetBytes(s);
}

private string _string(byte[] bs) {
    return Encoding.Default.GetString(bs);
}

经过测试, 在我的Windows 7系统上, Encoding.Default的值是DBCSCodePageEncoding, 在Ubuntu系统上, Encoding.Default的值是UTF8Encoding.

首先windows上,那个非常不常见的encoding会导致数据丧失可移植性. 把数据拷贝到其它的系统上多半就不能读取了.

再次在不同的系统之间, Encoding.Default的值不同, 这会导致基于这个API编写的代码丧失跨平台性.

我个人感觉不妨直接把encoding定死为UTF8Encoding. 这个编码绝大部分情况下是没有问题的. 另外可以给构造函数加个参数, 允许指定编码.

我自己基于这个api改了很多, 有时间我可能会另外创建一个repo公开我的代码. 目前就先提以上意见, 供参考.

感谢开发维护SSDB!

@ideawu
Copy link
Contributor

ideawu commented Jun 18, 2014

好的, 多谢反馈! 欢迎把你的代码合并进来. 或者我考虑给 SSDB 类提供一个 setEncoding() 方法, 替代 Encoding.Default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants