A platform for community discussion. Free, open, simple.
FIX: include video tags and short urls in 'have_uploads' method.
Vinoth Kannan02731ef33ef5
diff --git a/app/models/post.rb b/app/models/post.rbindex 8efcad9d540..2d2cb253e46 100644--- a/app/models/post.rb+++ b/app/models/post.rb@@ -116,10 +116,19 @@ class Post < ActiveRecord::Base}scope :have_uploads, -> {- where(- "(posts.cooked LIKE '%<a %' OR posts.cooked LIKE '%<img %') AND (posts.cooked LIKE ? OR posts.cooked LIKE '%/original/%' OR posts.cooked LIKE '%/optimized/%' OR posts.cooked LIKE '%data-orig-src=%')",- "%/uploads/#{RailsMultisite::ConnectionManagement.current_db}/%"- )+ where("+ (+ posts.cooked LIKE '%<a %' OR+ posts.cooked LIKE '%<img %' OR+ posts.cooked LIKE '%<video %'+ ) AND (+ posts.cooked LIKE ? OR+ posts.cooked LIKE '%/original/%' OR+ posts.cooked LIKE '%/optimized/%' OR+ posts.cooked LIKE '%data-orig-src=%' OR+ posts.cooked LIKE '%/uploads/short-url/%'+ )", "%/uploads/#{RailsMultisite::ConnectionManagement.current_db}/%"+ )}delegate :username, to: :userdiff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rbindex 9f69f4fd380..92d4aafad16 100644--- a/spec/models/post_spec.rb+++ b/spec/models/post_spec.rb@@ -1356,6 +1356,7 @@ describe Post doids << Fabricate(:post, cooked: "A post with optimized image <img src='https://cdn.example.com/bucket/optimized/1X/abc/defghijklmno.png'>").idFabricate(:post, cooked: "A post with external link <a href='https://example.com/wp-content/uploads/abcdef.gif'>")ids << Fabricate(:post, cooked: 'A post with missing upload <img src="https://cdn.example.com/images/transparent.png" data-orig-src="upload://defghijklmno.png">').id+ ids << Fabricate(:post, cooked: 'A post with video upload <video width="100%" height="100%" controls=""><source src="https://cdn.example.com/uploads/short-url/XefghijklmU9.mp4"><a href="https://cdn.example.com/uploads/short-url/XefghijklmU9.mp4">https://cdn.example.com/uploads/short-url/XefghijklmU9.mp4</a></video>').idexpect(Post.have_uploads.order(:id).pluck(:id)).to eq(ids)endend