public
Created

@imperator

  • Download Gist
uri_parse_invalid_uri.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# Fix uri's with only 1 '/' in them
require 'uri'
 
module URI
class << self
alias parse_orig parse
 
def parse(string)
unless string.include?("//")
string[string.index('/')] = "//" if string.include?("http")
end
parse_orig(string)
end
end
end
 
uri = URI.parse('http:/www.google.com')
p uri.host # => www.google.com

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.