rubyhtml-escape-characters

Ruby unescape HTML string


Any idea how I can unescape the following string in Ruby?

C:\inetpub\wwwroot\adminWeb

to

C:\inetpub\wwwroot\adminWeb

or to

C%3A%5Cinetpub%5Cwwwroot%5CadminWeb

Tried with URI.decode with no success.


Solution

  • The CGI library is one option:

    require 'cgi'
    
    CGI.unescapeHTML('C:\inetpub\wwwroot\adminWeb')
    # => "C:\\inetpub\\wwwroot\\adminWeb"