C0 code coverage information
Generated on Fri Jul 11 15:55:32 -0700 2008 with rcov 0.7.0
Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
1 require 'uri'
2
3 require "openid/extras"
4
5 module OpenID
6
7 module URINorm
8 public
9 def URINorm.urinorm(uri)
10 uri = URI.parse(uri)
11
12 raise URI::InvalidURIError.new('no scheme') unless uri.scheme
13 uri.scheme = uri.scheme.downcase
14 unless ['http','https'].member?(uri.scheme)
15 raise URI::InvalidURIError.new('Not an HTTP or HTTPS URI')
16 end
17
18 raise URI::InvalidURIError.new('no host') unless uri.host
19 uri.host = uri.host.downcase
20
21 uri.path = remove_dot_segments(uri.path)
22 uri.path = '/' if uri.path.length == 0
23
24 uri = uri.normalize.to_s
25 uri = uri.gsub(PERCENT_ESCAPE_RE) {
26 sub = $&[1..2].to_i(16).chr
27 reserved(sub) ? $&.upcase : sub
28 }
29
30 return uri
31 end
32
33 private
34 RESERVED_RE = /[A-Za-z0-9._~-]/
35 PERCENT_ESCAPE_RE = /%[0-9a-zA-Z]{2}/
36
37 def URINorm.reserved(chr)
38 not RESERVED_RE =~ chr
39 end
40
41 def URINorm.remove_dot_segments(path)
42 result_segments = []
43
44 while path.length > 0
45 if path.starts_with?('../')
46 path = path[3..-1]
47 elsif path.starts_with?('./')
48 path = path[2..-1]
49 elsif path.starts_with?('/./')
50 path = path[2..-1]
51 elsif path == '/.'
52 path = '/'
53 elsif path.starts_with?('/../')
54 path = path[3..-1]
55 result_segments.pop if result_segments.length > 0
56 elsif path == '/..'
57 path = '/'
58 result_segments.pop if result_segments.length > 0
59 elsif path == '..' or path == '.'
60 path = ''
61 else
62 i = 0
63 i = 1 if path[0].chr == '/'
64 i = path.index('/', i)
65 i = path.length if i.nil?
66 result_segments << path[0...i]
67 path = path[i..-1]
68 end
69 end
70
71 return result_segments.join('')
72 end
73 end
74
75 end
Generated using the rcov code coverage analysis tool for Ruby version 0.7.0.