From 290ee312e673c81f0b7ff3c1433a0ecb9801044b Mon Sep 17 00:00:00 2001
From: Arpit Jalan <arpit@techapj.com>
Date: Fri, 18 May 2018 18:01:36 +0530
Subject: [PATCH] FIX: handle invalid mailto links

---
 app/models/upload.rb       | 2 +-
 spec/models/upload_spec.rb | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/app/models/upload.rb b/app/models/upload.rb
index a9907954922..754e5d7f69a 100644
--- a/app/models/upload.rb
+++ b/app/models/upload.rb
@@ -85,7 +85,7 @@ class Upload < ActiveRecord::Base
     # always try to get the path
     uri = begin
       URI(URI.unescape(url))
-    rescue URI::InvalidURIError
+    rescue URI::InvalidURIError, URI::InvalidComponentError
     end
 
     url = uri.path if uri.try(:scheme)
diff --git a/spec/models/upload_spec.rb b/spec/models/upload_spec.rb
index a7c0d4ab0e8..32b86bbc182 100644
--- a/spec/models/upload_spec.rb
+++ b/spec/models/upload_spec.rb
@@ -88,6 +88,7 @@ describe Upload do
     it "doesn't blow up with an invalid URI" do
       expect { Upload.get_from_url("http://ip:port/index.html") }.not_to raise_error
       expect { Upload.get_from_url("mailto:admin%40example.com") }.not_to raise_error
+      expect { Upload.get_from_url("mailto:example") }.not_to raise_error
     end
 
     describe "s3 store" do