FIX: include video tags and short urls in 'have_uploads' method.

FIX: include video tags and short urls in ‘have_uploads’ method.

While checking the existence of upload in posts we must include <video> tags and ‘short-url’ format of upload URLs.

diff --git a/app/models/post.rb b/app/models/post.rb
index 8efcad9..2d2cb25 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: :user
diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb
index 9f69f4f..92d4aaf 100644
--- a/spec/models/post_spec.rb
+++ b/spec/models/post_spec.rb
@@ -1356,6 +1356,7 @@ describe Post do
       ids << Fabricate(:post, cooked: "A post with optimized image <img src='https://cdn.example.com/bucket/optimized/1X/abc/defghijklmno.png'>").id
       Fabricate(: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>').id
       expect(Post.have_uploads.order(:id).pluck(:id)).to eq(ids)
     end
   end

GitHub sha: 02731ef3

1 Like