2016-01-21 59 views
0

这里是我的test file引发ArgumentError:字符串包含空字节时使用StringValueCStr

这里是我的全部代码(github.com/roroco/ro_article/tree/string-contains-null-byte)

我得到“引发ArgumentError:字符串包含空字节的” 运行时下面的代码:在红宝石侧

get_article(File.read("test_file")) 

在C端:

VALUE get_article(VALUE self, VALUE html) { 
    str html2 = StringValueCStr(html); 

test file这么大,如何在这个文件中找到空字节?如何使StringValueCStr工作的所有字符串,即使它包含“空字节”

回答

1

当我使用下面的代码:

body = File.read("test_file") 
result = body.inspect 

我有“结果”包含“\ u0000的”(我的编码是UTF8)因此该解决方案是

body.gsub(%r{\u0000}, "") 

做到这一点在红宝石侧或c侧