Undo html escape with ruby on rails data migration

952 views Asked by At

I have a database, and currently many of the items within it have been html escaped. I need to undo this (don't ask why!), for which I'll carry out a data migration.

But is the a way to un-escape these strings? I've not been able to find anything..

3

There are 3 answers

1
marrat On

If i understand it correct you need to replace strings like > to >. If so - check xml documentation and replace required strings with their real values. I dont code in ruby, so this one you got to figure out :] XML special characters

0
Holin On

You should take a look at the htmlentities gem

0
the Tin Man On

Ruby's CGI::unescapeHTML can do HTML unescaping.

Unescape a string that has been HTML-escaped

  CGI::unescapeHTML("Usage: foo "bar" <baz>")
     # => "Usage: foo \"bar\" <baz>"