title: Is there a better HTML escaping and unescaping tool than CGI for Ruby?
body: <p><code>CGI.escapeHTML</code> is pretty bad, but <code>CGI.unescapeHTML</code> is completely borked.  For example:</p>
  
  <pre><code>require 'cgi'
  
  CGI.unescapeHTML('&amp;#8230;')
  # =&gt; "…"                    # correct - an ellipsis
  
  CGI.unescapeHTML('&amp;hellip;')
  # =&gt; "&amp;hellip;"             # should be "…"
  
  CGI.unescapeHTML('&amp;#162;')
  # =&gt; "\242"                 # correct - a cent
  
  CGI.unescapeHTML('&amp;cent;')
  # =&gt; "&amp;cent;"               # should be "\242"
  
  CGI.escapeHTML("…")
  # =&gt; "…"                    # should be "&amp;#8230;"
  </code></pre>
  
  <p>It appears that <code>unescapeHTML</code> knows about all of the numeric codes plus <code>&amp;amp;</code>, <code>&amp;lt;</code>, <code>&amp;gt;</code>, and <code>&amp;quot;</code>.  And <code>escapeHTML</code> only knows about those last four -- it doesn't do any of the numeric codes.  I understand that escaping doesn't generally need to be as robust since HTML will allow the literal versions of most characters except the four that <code>CGI.escapeHTML</code> knows about.  But unescaping should really be better.</p>
  
  <p>Is there a better tool out there, at least for unescaping?</p>