Method: Spidr::Page#to_absolute
- Defined in:
- lib/spidr/page/html.rb
#to_absolute(link) ⇒ URI::HTTP
Normalizes and expands a given link into a proper URI.
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/spidr/page/html.rb', line 267 def to_absolute(link) link = link.to_s new_url = begin url.merge(link) rescue URI::Error return end if (!new_url.opaque) && (path = new_url.path) # ensure that paths begin with a leading '/' for URI::FTP if (new_url.scheme == 'ftp' && !path.start_with?('/')) path.insert(0,'/') end # make sure the path does not contain any .. or . directories, # since URI::Generic#merge cannot normalize paths such as # "/stuff/../" new_url.path = URI.(path) end return new_url end |