私はDMOZのURLトピックのリストを使用しています。これには、アンダースコアを含むホスト名を持ついくつかの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
自分で転がさずに厳しさを抑えて使える代替品はありますか?