当我通过路径时,它读取并处理它,一切都很好。
当我传递内容时,它与 string contains null byte
string contains null byte
下面是检查传递的参数是否为文件的代码部分:
contents = File.exists?(param) ? File.read(param) : param
param File.exists?
param
File.exists?
您可以先检查字符串是否包含空字节:
contents = case input when /\u0000/ then param when File.exists?(param) then File.read(param) else param end
File#read 成功:
File#read
contents = File.read(param) rescue param