FIX: Handle invalid URLs gracefully when pulling hotlinked images

This commit is contained in:
David Taylor 2020-06-19 12:52:51 +01:00
parent 78626d2832
commit 9f2e7e4651
No known key found for this signature in database
GPG Key ID: 46904C18B1D3F434
2 changed files with 11 additions and 1 deletions

View File

@ -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

View File

@ -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]