Is there a better HTML escaping and unescaping tool than CGI for Ruby?

后端 未结 2 1415
慢半拍i
慢半拍i 2021-02-05 08:12

CGI.escapeHTML is pretty bad, but CGI.unescapeHTML is completely borked. For example:

require \'cgi\'

CGI.unescapeHTML(\'…\         


        
2条回答
  •  孤街浪徒
    2021-02-05 08:53

    require 'rubygems'
    require 'hpricot'
    
    Hpricot('…', :xhtml_strict => true).to_plain_text
    

    Though you might have to fiddle around with the character encoding.

提交回复
热议问题