2016-01-21 57 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側