Skip to content

A platform for community discussion. Free, open, simple.

FIX: Handle invalid URLs gracefully when pulling hotlinked images

David Taylor9f2e7e465149
diff --git a/app/jobs/regular/pull_hotlinked_images.rb b/app/jobs/regular/pull_hotlinked_images.rb
index 80367f4f51c..415ce3b569c 100644
--- a/app/jobs/regular/pull_hotlinked_images.rb
+++ b/app/jobs/regular/pull_hotlinked_images.rb
@@ -220,7 +220,7 @@ module Jobs
uri.normalize!
uri.scheme = nil
uri.to_s
- rescue URI::Error
+ rescue URI::Error, Addressable::URI::InvalidURIError
src
end
end
diff --git a/spec/jobs/pull_hotlinked_images_spec.rb b/spec/jobs/pull_hotlinked_images_spec.rb
index 37499a81e0f..b5893830046 100644
--- a/spec/jobs/pull_hotlinked_images_spec.rb
+++ b/spec/jobs/pull_hotlinked_images_spec.rb
@@ -222,6 +222,16 @@ describe Jobs::PullHotlinkedImages do
MD
end
+ it 'works when invalid url in post' do
+ post = Fabricate(:post, raw: <<~MD)
+ ![some test](#{image_url})
+ ![some test 2]("#{image_url})
+ MD
+
+ expect { Jobs::PullHotlinkedImages.new.execute(post_id: post.id) }
+ .to change { Upload.count }.by(1)
+ end
+
it 'replaces bbcode images' do
post = Fabricate(:post, raw: <<~MD)
[img]