Skip to content

Commit

Permalink
make sure invalid uri exception is backward compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
terryyin committed Feb 6, 2021
1 parent a5353a5 commit d9b305d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/mechanize/page/link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ def uri
begin
URI.parse @href
rescue URI::InvalidURIError
URI.parse Addressable::URI.escape @href
begin
URI.parse Addressable::URI.escape @href
rescue Addressable::URI::InvalidURIError
raise URI::InvalidURIError
end
end
end
end
Expand Down
13 changes: 13 additions & 0 deletions test/test_mechanize_link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,19 @@ def test_uri_weird_with_fragment
assert_equal '%D1%83%D0%B2%D0%B0%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5', link.uri.fragment
end

def test_bad_uri_raise_compatible_exception
doc = Nokogiri::HTML::Document.new

node = Nokogiri::XML::Node.new('foo', doc)
node['href'] = 'http://http:foo.bar/ baz'

link = Mechanize::Page::Link.new(node, nil, nil)

assert_raises URI::InvalidURIError do
link.uri
end
end

def test_resolving_full_uri
page = @mech.get("http://localhost/frame_test.html")
link = page.link_with(:text => "Form Test")
Expand Down

0 comments on commit d9b305d

Please sign in to comment.