mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 10:20:58 -06:00
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.
This commit is contained in:
parent
cb8fa46970
commit
02731ef33e
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user