文件识别编码不对的问题

dev_cs
daiao 5 years ago
parent d26526be12
commit 264f711046

@ -23,7 +23,7 @@ module GitHelper
Rails.logger.info "encoding: #{cd['encoding']} confidence: #{cd['confidence']}"
# 字符编码问题GB18030编码识别率不行
decode_content =
if cd["encoding"] == 'GB18030' && cd['confidence'] == 1.0
if cd["encoding"] == 'GB18030' && cd['confidence'] > 0.8
content.encode('UTF-8', 'GBK', {:invalid => :replace, :undef => :replace, :replace => ' '})
else
content.force_encoding('UTF-8')

Loading…
Cancel
Save