FIX: Do not download emojis in pull_hotlinked_images

FIX: Do not download emojis in pull_hotlinked_images

diff --git a/app/jobs/regular/pull_hotlinked_images.rb b/app/jobs/regular/pull_hotlinked_images.rb
index 672b85a..23f6934 100644
--- a/app/jobs/regular/pull_hotlinked_images.rb
+++ b/app/jobs/regular/pull_hotlinked_images.rb
@@ -156,7 +156,10 @@ module Jobs
       # If file is on the forum or CDN domain
       if || src =~ /\A\/[^\/]/i
-        # Return true if we can't find the upload in the db
+        return false if src =~ /\/images\/emoji\//
+        # Someone could hotlink a file from a different site on the same CDN,
+        # so check whether we have it in this database
         return !Upload.get_from_url(src)
diff --git a/spec/jobs/pull_hotlinked_images_spec.rb b/spec/jobs/pull_hotlinked_images_spec.rb
index 962699f..446adea 100644
--- a/spec/jobs/pull_hotlinked_images_spec.rb
+++ b/spec/jobs/pull_hotlinked_images_spec.rb
@@ -191,6 +191,11 @@ describe Jobs::PullHotlinkedImages do
         expect(subject.should_download_image?(src)).to eq(true)
+      it "returns false for emoji" do
+        src = Emoji.url_for("testemoji.png")
+        expect(subject.should_download_image?(src)).to eq(false)
+      end
       it 'returns false for valid remote URLs' do
         expect(subject.should_download_image?("")).to eq(false)

GitHub sha: 54afa314

1 Like

I think we’ll need to check against the host/cdn as well. The regexp here is too generic such that a possible URL like will not be pulled.

This all happens inside the conditional, which checks the file is on the CDN, or on the host.

Could it potentially return false and match on src =~ /\A\/[^\/]/i? Just thinking out loud.

src =~ /\A\/[^\/]/i translates to “a URL starting with a single forward-slash”. So that shouldn’t match any URLs that point to a different host.

O good point xD I guess I should go to bed now