HTML::FullSanitizer
我在 Rails控制台上使用 Rails 遇到了这个错误:
h = HTML::FullSanitizer.new
html = "Something with invalid characters \x80 and tags ī."
h.sanitze html
ArgumentError: invalid byte sequence in UTF-8
from /Users/benaluan/.rbenv/versions/1.9.3-p385/lib/ruby/gems/1.9.1/gems/actionpack-3.2.12/lib/action_controller/vendor/html-scanner/html/sanitizer.rb:37:in `sanitize'
我尝试的是在清理之前对 html 进行编码:
html = html.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
它有效,但是,它删除了ī字符。有没有人遇到过同样的问题?