C0 code coverage information
Generated on Fri Jul 11 15:55:31 -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 "openid/yadis/htmltokenizer"
2
3 module OpenID
4
5 # Stuff to remove before we start looking for tags
6 REMOVED_RE = /
7 # Comments
8 <!--.*?-->
9
10 # CDATA blocks
11 | <!\[CDATA\[.*?\]\]>
12
13 # script blocks
14 | <script\b
15
16 # make sure script is not an XML namespace
17 (?!:)
18
19 [^>]*>.*?<\/script>
20
21 /mixu
22
23 def OpenID.openid_unescape(s)
24 s.gsub('&','&').gsub('<','<').gsub('>','>').gsub('"','"')
25 end
26
27 def OpenID.unescape_hash(h)
28 newh = {}
29 h.map{|k,v|
30 newh[k]=openid_unescape(v)
31 }
32 newh
33 end
34
35
36 def OpenID.parse_link_attrs(html)
37 stripped = html.gsub(REMOVED_RE,'')
38 parser = HTMLTokenizer.new(stripped)
39
40 links = []
41 # to keep track of whether or not we are in the head element
42 in_head = false
43 in_html = false
44 saw_head = false
45
46 begin
47 while el = parser.getTag('head', '/head', 'link', 'body', '/body',
48 'html', '/html')
49
50 # we are leaving head or have reached body, so we bail
51 return links if ['/head', 'body', '/body', '/html'].member?(el.tag_name)
52
53 # enforce html > head > link
54 if el.tag_name == 'html'
55 in_html = true
56 end
57 next unless in_html
58 if el.tag_name == 'head'
59 if saw_head
60 return links #only allow one head
61 end
62 saw_head = true
63 unless el.to_s[-2] == 47 # tag ends with a /: a short tag
64 in_head = true
65 end
66 end
67 next unless in_head
68
69 return links if el.tag_name == 'html'
70
71 if el.tag_name == 'link'
72 links << unescape_hash(el.attr_hash)
73 end
74
75 end
76 rescue Exception # just stop parsing if there's an error
77 end
78 return links
79 end
80
81 def OpenID.rel_matches(rel_attr, target_rel)
82 # Does this target_rel appear in the rel_str?
83 # XXX: TESTME
84 rels = rel_attr.strip().split()
85 rels.each { |rel|
86 rel = rel.downcase
87 if rel == target_rel
88 return true
89 end
90 }
91
92 return false
93 end
94
95 def OpenID.link_has_rel(link_attrs, target_rel)
96 # Does this link have target_rel as a relationship?
97
98 # XXX: TESTME
99 rel_attr = link_attrs['rel']
100 return (rel_attr and rel_matches(rel_attr, target_rel))
101 end
102
103 def OpenID.find_links_rel(link_attrs_list, target_rel)
104 # Filter the list of link attributes on whether it has target_rel
105 # as a relationship.
106
107 # XXX: TESTME
108 matchesTarget = lambda { |attrs| link_has_rel(attrs, target_rel) }
109 result = []
110
111 link_attrs_list.each { |item|
112 if matchesTarget.call(item)
113 result << item
114 end
115 }
116
117 return result
118 end
119
120 def OpenID.find_first_href(link_attrs_list, target_rel)
121 # Return the value of the href attribute for the first link tag in
122 # the list that has target_rel as a relationship.
123
124 # XXX: TESTME
125 matches = find_links_rel(link_attrs_list, target_rel)
126 if !matches or matches.empty?
127 return nil
128 end
129
130 first = matches[0]
131 return first['href']
132 end
133 end
134
Generated using the rcov code coverage analysis tool for Ruby version 0.7.0.