How do I percent-escape a Base64 string in Ruby?

In a Ruby program I have a password that is a Base64 string and so can contain forward slashes. I use that password and the username to perform HTTP requests

username = "User"
password = "/Base/64/With/Slashes"
requestUrl = "http://#{username}:#{password}"
response = RestClient.get(requestUrl)

so if password happens to contain forward-slashes those will be interpreted as port of the URI and I'll have an error message saying I have an invalid URI. Clearly each forward slash inside password must be replaced with %2F.

I tried to use URI.escape(), but it doesn't affect forward slashes.

How do I percent-escape Base64 string so that the result can be used for HTTP requests authentication?


@injekt has the right answer in a comment, but here's a slightly elaborated version as an answer:

CGI.escape() is an appropriate tool for that task. Its documentation:

URL-encode a string.

Need Your Help

UISearchDisplayController - Not getting result in uitableview

ios delegates uitableview uisearchbar uisearchdisplaycontroller

I am using UISearchDisplayController ,I am getting filtered data but this property is not active .

Need help with a 'No persister for:' exception with Fluent Nhibernate Automapping

c# .net nhibernate fluent-nhibernate automapping

I'm having some problems with applying NHibernate Fluent Automapping. It worked great in a test project. But now..