From: David Madison Date: 2012-12-02T10:24:56+09:00 Subject: Re: Found a ruby bug in the URI class, what do I do? Here's a workaround that fixes URI.parse. I didn't feel like rewriting the entire split, so I escaped out the '_' in the URL with a legal string. This will work great as long as you don't find a domain that has "_" *and* the string "UNDERLINEuriSplitISbrokenUNDERLINE" in it. That seems like a reasonable premise for a kludgy hack fix. :) See attached file if you have problems with cut-and-paste because of the line wrap: require 'uri' # Fix for broken URI.parse (doesn't allow '_' in subdomains) module URI class << self alias origsplit split def split(uri) return origsplit(uri) unless uri.gsub!(/^([^:]+:\/\/[^\/]+)_/,'\1UNDERLINEuriSplitISbrokenUNDERLINE') fix = origsplit(uri) fix[2].gsub!(/UNDERLINEuriSplitISbrokenUNDERLINE/,'_') fix end end end puts URI.parse("http://whatever.domain.com") puts URI.parse("http://whatever_again.domain.com") Attachments: http://www.ruby-forum.com/attachment/7919/urifix.rb -- Posted via http://www.ruby-forum.com/.