Home > other >  Encode two double quotation marks in ruby
Encode two double quotation marks in ruby

Time:08-19

I have following string saved in database:

<p>ampersand (&amp;), bracket(&lt;&gt;), quotation marks (&quot;&quot;&#39;&#39;)</p>\r\n

I need to encode the special symbols and get a string

<p>ampersand (&), bracket(<>), quotation marks (""'')</p>

I used CGI library to encoding:

CGI::unescapeHTML("<p>ampersand (&amp;), bracket(&lt;&gt;), quotation marks (&quot;&quot;&#39;&#39;)</p>\r\n")

the method returns "<p>ampersand (&), bracket(<>), quotation marks (\"\"'')</p>\r\n"

but should be

<p>ampersand (&), bracket(<>), quotation marks (""'')</p>

CodePudding user response:

It's actually correct (the method). It's returning what you want.

The \ you are seeing before the double quotes are just artifacts of rendering a string with embedded double quotes, so that they're not interpreted as the end of the string.

  • Related