I have the same problem. I used this aproach to solve this problem:
require 'cgi' url = "http://website.com/dirs/filex[a]" safeurl = URI.parse(CGI.escape(url).gsub("%3A", ":").gsub("%2F", "/"))
Instead of requiring uri, I use the CGI class to remove invalid characters, but CGI avoids everything, including colons and forward slashes, so after I use gsub to return them.
source share