Module: WebUnit::Utils

Included in:
Web::Unit, WebUnit, Parser, Response, TestCase
Defined in:
lib/webunit/utils.rb

Instance Method Summary collapse

Instance Method Details

#complete_url(url, base) ⇒ Object

— Utils#complete_url(url,base)

return url, is completed with ((|base||).


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/webunit/utils.rb', line 46

def complete_url( url, base )
  if base
    prot,host,port,path = parse_url( base )
    prefix = prot + "://" + host + ":" + port.to_s
    case url
    when nil then
      url = base.sub( /\?.*/, '' )
    when %r!^http://! then
      url
    when %r!^/! then
      url = prefix + url
    else
      url = prefix + File::dirname( path ) + "/" + url
    end
    orthop_url( url )
  else
    url
  end
end

#orthop_url(url) ⇒ Object

— Utils#orthop_url(url)

return url, is orthopped by Utils#parse_url.


34
35
36
37
38
39
# File 'lib/webunit/utils.rb', line 34

def orthop_url( url )
  prot, host, port, path = parse_url url
  path.gsub!( %r![^/]*/\.\./!, '/' )
  path.gsub!( %r!/\.*/!, '/' )
  "#{prot}://#{host}:#{port}#{path}"
end

#parse_url(url) ⇒ Object

— Utils#parse_url(url)

return an Array of protocol, hostname, port, and path.


18
19
20
21
22
23
24
25
26
# File 'lib/webunit/utils.rb', line 18

def parse_url( url )
  if url =~ %r!^([a-z]+)://([-0-9A-Aa-z_.]+):?([0-9]*)(/.*)?$!
    [ $1, $2, $3 == "" ? 80 : $3.to_i, $4 ? $4 : '' ]
  elsif url =~ %r!^file:(/.*)$!
    [ 'file', nil, nil, $1 ]
  else
    [ nil, nil, nil, url ]
  end
end