Tôi đang sử dụng DMOZ 's list of url topics, trong đó có một số url có tên máy chủ chứa dấu gạch dưới.Thay thế cho URI.parse cho phép tên máy chủ chứa dấu gạch dưới
Ví dụ:
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>
Trong khi url này sẽ làm việc trong một trình duyệt web (hoặc, ít nhất, nó làm ở mỏ: p), it's not legal according to the standard:
một hostname có thể không chứa các ký tự khác, chẳng hạn như ký tự gạch dưới (_),
gây ra lỗi khi cố phân tích cú pháp URL đó với URI.parse
:
[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'
Có cách nào khác thay thế cho URI.parse
Tôi có thể sử dụng tính năng này có độ chính xác thấp hơn mà không cần phải tự làm?