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.