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:
parent
39ad9a4734
commit
00afd308c1
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue