Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 229
bsteo Avatar asked Aug 18 '15 06:08

bsteo


2 Answers

The CGI library is one option:

require 'cgi'

CGI.unescapeHTML('C:\inetpub\wwwroot\adminWeb')
# => "C:\\inetpub\\wwwroot\\adminWeb"
like image 59
Yu Hao Avatar answered Oct 11 '22 07:10

Yu Hao


One more variant is HTMLEntities

HTMLEntities.new.decode "C:\inetpub\wwwroot\adminWeb"             
# => "C:\\inetpub\\wwwroot\\adminWeb"

I prefer to use it because it deals with rare cases aså and — which CGI.unescapeHTML does not

like image 40
goodniceweb Avatar answered Oct 11 '22 08:10

goodniceweb