FIX: Escaped `mailto` URLs would raise an exception

This prevents exceptions from being raised if a URL has an invalid
component.
This commit is contained in:
Robin Ward 2020-10-05 14:12:33 -04:00
parent 39ad9a4734
commit 00afd308c1
2 changed files with 6 additions and 1 deletions

View File

@ -70,7 +70,7 @@ class UrlHelper
def self.rails_route_from_url(url)
path = URI.parse(encode(url)).path
Rails.application.routes.recognize_path(path)
rescue Addressable::URI::InvalidURIError
rescue Addressable::URI::InvalidURIError, URI::InvalidComponentError
nil
end

View File

@ -205,5 +205,10 @@ describe UrlHelper do
url = "http://URL:%20https://google.com"
expect(described_class.rails_route_from_url(url)).to eq(nil)
end
it "does not raise for invalid mailtos" do
url = "mailto:eviltrout%2540example.com"
expect(described_class.rails_route_from_url(url)).to eq(nil)
end
end
end