我是使用DMOZ的网址主题列表,其中包含一些主机名包含下划线的url。
例如:
例如:
608 <ExternalPage about="http://outer_heaven4.tripod.com/index2.htm">
609 <d:Title>The Outer Heaven</d:Title>
610 <d:Description>Information and image gallery of McFarlane's action figures for Trigun, Akira, Tenchi Muyo and other Japanese Sci-Fi animations.</d:Description>
611 <topic>Top/Arts/Animation/Anime/Collectibles/Models_and_Figures/Action_Figures</topic>
612 </ExternalPage>
虽然这个URL在Web浏览器中能够使用(至少在我的浏览器中是可以的:p),但是根据标准,它是不合法的:
主机名不能包含其他字符,比如下划线(_)等,
如果尝试使用 URI.parse
解析这样的URL会出现错误:
[2] pry(main)> require 'uri'
=> true
[3] pry(main)> URI.parse "http://outer_heaven4.tripod.com/index2.htm"
URI::InvalidURIError: the scheme http does not accept registry part: outer_heaven4.tripod.com (or bad hostname?)
from ~/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/uri/generic.rb:213:in `initialize'
有没有其他的替代方法可以代替 URI.parse
,并且更加宽松一些,而不是自己编写代码?