Ruby: Escapar caracteres especiais em HTML (entities)

Palavras-chave: HTML, escape, escapar, cgi

Para “escapar” e “desescapar” caracteres especiais HTML:

require "cgi"

s = CGI.escapeHTML("a > x && y < 0")
puts s
puts CGI.unescapeHTML(s)

Rodando:

a &gt; x &amp;&amp; y &lt; 0
a > x && y < 0

Veja esta dica em Python.

This entry was posted in Ruby. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>