Skip to content

Commit 91e5487

Browse files
author
Kevin Turner
committed
[project @ Yadis.html_yadis_location: catch HTMLTokenizerError]
1 parent 439e2f4 commit 91e5487

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

lib/openid/yadis/parsehtml.rb

+20-19
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,36 @@ def Yadis.html_yadis_location(html)
99
# to keep track of whether or not we are in the head element
1010
in_head = false
1111

12-
while el = parser.getTag('head', '/head', 'meta', 'body', '/body', 'html',
13-
'script')
12+
begin
13+
while el = parser.getTag('head', '/head', 'meta', 'body', '/body',
14+
'html', 'script')
1415

15-
# we are leaving head or have reached body, so we bail
16-
return nil if ['/head', 'body', '/body'].member?(el.tag_name)
16+
# we are leaving head or have reached body, so we bail
17+
return nil if ['/head', 'body', '/body'].member?(el.tag_name)
1718

18-
if el.tag_name == 'head'
19-
unless el.to_s[-2] == ?/ # tag ends with a /: a short tag
20-
in_head = true
19+
if el.tag_name == 'head'
20+
unless el.to_s[-2] == ?/ # tag ends with a /: a short tag
21+
in_head = true
22+
end
2123
end
22-
end
23-
next unless in_head
24+
next unless in_head
2425

25-
if el.tag_name == 'script'
26-
unless el.to_s[-2] == ?/ # tag ends with a /: a short tag
27-
parser.getTag('/script')
26+
if el.tag_name == 'script'
27+
unless el.to_s[-2] == ?/ # tag ends with a /: a short tag
28+
parser.getTag('/script')
29+
end
2830
end
29-
end
3031

31-
return nil if el.tag_name == 'html'
32+
return nil if el.tag_name == 'html'
3233

33-
if el.tag_name == 'meta' and (equiv = el.attr_hash['http-equiv'])
34-
if ['x-xrds-location','x-yadis-location'].member?(equiv.downcase)
35-
return CGI::unescapeHTML(el.attr_hash['content'])
34+
if el.tag_name == 'meta' and (equiv = el.attr_hash['http-equiv'])
35+
if ['x-xrds-location','x-yadis-location'].member?(equiv.downcase)
36+
return CGI::unescapeHTML(el.attr_hash['content'])
37+
end
3638
end
3739
end
38-
40+
rescue HTMLTokenizerError # just stop parsing if there's an error
3941
end
4042
end
4143
end
4244
end
43-

0 commit comments

Comments
 (0)