CGI.escapeHTML
is pretty bad, but CGI.unescapeHTML
is completely borked. For example:
require 'cgi'
CGI.unescapeHTML('…')
# => "…" # correct - an ellipsis
CGI.unescapeHTML('…')
# => "…" # should be "…"
CGI.unescapeHTML('¢')
# => "\242" # correct - a cent
CGI.unescapeHTML('¢')
# => "¢" # should be "\242"
CGI.escapeHTML("…")
# => "…" # should be "…"
It appears that unescapeHTML
knows about all of the numeric codes plus &
, <
, >
, and "
. And escapeHTML
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 CGI.escapeHTML
knows about. But unescaping should really be better.
Is there a better tool out there, at least for unescaping?