diff --git a/lib/url_helper.rb b/lib/url_helper.rb index 7968c9ab39a..f52b90c3ba1 100644 --- a/lib/url_helper.rb +++ b/lib/url_helper.rb @@ -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 diff --git a/spec/components/url_helper_spec.rb b/spec/components/url_helper_spec.rb index d56efc2b15b..8328cec9b96 100644 --- a/spec/components/url_helper_spec.rb +++ b/spec/components/url_helper_spec.rb @@ -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