FIX: Escaped `mailto` URLs would raise an exception

FIX: Escaped mailto URLs would raise an exception

This prevents exceptions from being raised if a URL has an invalid component.

diff --git a/lib/url_helper.rb b/lib/url_helper.rb
index 7968c9a..f52b90c 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 d56efc2..8328cec 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

GitHub sha: 00afd308

This commit appears in #10827 which was approved by gschlager. It was merged by eviltrout.