2

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..

tiswas
  • 2,041
  • 7
  • 31
  • 43
  • Does the answer to this question help? http://stackoverflow.com/questions/4251284/raw-vs-html-safe-vs-h-to-unescape-html – JeffH Feb 10 '11 at 17:52

3 Answers3

4

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>"
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
1

You should take a look at the htmlentities gem

Holin
  • 1,191
  • 10
  • 10
0

If i understand it correct you need to replace strings like &gt; 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

mu is too short
  • 426,620
  • 70
  • 833
  • 800
marrat
  • 534
  • 1
  • 6
  • 14
  • so you mean explicitly search for things that (say) apostrophe's could have been turned into and change them back? I was wondering whether there was a less arduous way.. – tiswas Feb 10 '11 at 16:38