diff --git a/app/models/topic_link.rb b/app/models/topic_link.rb index c9abf160c42..48c7c279c02 100644 --- a/app/models/topic_link.rb +++ b/app/models/topic_link.rb @@ -164,7 +164,7 @@ SQL added_urls << url unless TopicLink.exists?(topic_id: post.topic_id, post_id: post.id, url: url) - file_extension = File.extname(parsed.path)[1..5].downcase unless File.extname(parsed.path).empty? + file_extension = File.extname(parsed.path)[1..10].downcase unless File.extname(parsed.path).empty? begin TopicLink.create!(post_id: post.id, user_id: post.user_id, diff --git a/lib/upload_creator.rb b/lib/upload_creator.rb index a00b13f08fc..503c0fadefa 100644 --- a/lib/upload_creator.rb +++ b/lib/upload_creator.rb @@ -73,6 +73,7 @@ class UploadCreator @upload.sha1 = sha1 @upload.url = "" @upload.origin = @opts[:origin][0...1000] if @opts[:origin] + @upload.extension = File.extname(@filename)[1..10] if FileHelper.is_image?(@filename) @upload.width, @upload.height = ImageSizer.resize(*@image_info.size) diff --git a/spec/components/search_spec.rb b/spec/components/search_spec.rb index c7c2c5609e4..7faf1bac437 100644 --- a/spec/components/search_spec.rb +++ b/spec/components/search_spec.rb @@ -712,14 +712,16 @@ describe Search do raw: "Discourse logo\n"\ "https://www.discourse.org/a/img/favicon.png\n"\ "https://www.discourse.org/a/img/trust-1x.jpg") + post_with_upload = Fabricate(:post) + post_with_upload.uploads = [Fabricate(:upload)] Fabricate(:post) TopicLink.extract_from(post1) TopicLink.extract_from(post2) expect(Search.execute('filetype:jpg').posts.map(&:id)).to eq([post2.id]) - expect(Search.execute('filetype:png').posts.map(&:id)).to contain_exactly(post1.id, post2.id) - expect(Search.execute('logo filetype:jpg').posts.map(&:id)).to eq([post2.id]) + expect(Search.execute('filetype:png').posts.map(&:id)).to contain_exactly(post1.id, post2.id, post_with_upload.id) + expect(Search.execute('logo filetype:png').posts.map(&:id)).to eq([post2.id]) end end diff --git a/spec/fabricators/upload_fabricator.rb b/spec/fabricators/upload_fabricator.rb index a2afdf7af0a..7d0c7f43be6 100644 --- a/spec/fabricators/upload_fabricator.rb +++ b/spec/fabricators/upload_fabricator.rb @@ -6,6 +6,7 @@ Fabricator(:upload) do width 100 height 200 url { sequence(:url) { |n| "/uploads/default/#{n}/1234567890123456.png" } } + extension "png" end Fabricator(:upload_s3, from: :upload) do