FEATURE: Broader support for post uploads in video markup (#9152)

Ensures URLs in the following HTML attributes are included in post uploads:
- video poster
- source src
- track src
This commit is contained in:
Penar Musaraj 2020-03-10 09:01:40 -04:00 committed by GitHub
parent 826b4793c0
commit e69b6379ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 3 deletions

View File

@ -949,8 +949,9 @@ class Post < ActiveRecord::Base
]
fragments ||= Nokogiri::HTML::fragment(self.cooked)
selectors = fragments.css("a/@href", "img/@src", "source/@src", "track/@src", "video/@poster")
links = fragments.css("a/@href", "img/@src").map do |media|
links = selectors.map do |media|
src = media.value
next if src.blank?

View File

@ -1528,6 +1528,9 @@ describe Post do
upload2 = Fabricate(:upload)
upload3 = Fabricate(:video_upload)
upload4 = Fabricate(:upload)
upload5 = Fabricate(:upload)
upload6 = Fabricate(:video_upload)
upload7 = Fabricate(:upload, extension: "vtt")
set_cdn_url "https://awesome.com/somepath"
@ -1542,6 +1545,11 @@ describe Post do
![](http://example.com/external.png)
#{Discourse.base_url}#{upload3.short_path}
<video poster="#{Discourse.base_url}#{upload5.url}">
<source src="#{Discourse.base_url}#{upload6.url}" type="video/mp4" />
<track src="#{Discourse.base_url}#{upload7.url}" label="English" kind="subtitles" srclang="en" default />
</video>
RAW
urls = []
@ -1556,14 +1564,20 @@ describe Post do
"#{GlobalSetting.cdn_url}#{upload1.url}",
"#{GlobalSetting.cdn_url}#{upload4.url}",
"#{Discourse.base_url}#{upload2.url}",
"#{Discourse.base_url}#{upload3.short_path}"
"#{Discourse.base_url}#{upload3.short_path}",
"#{Discourse.base_url}#{upload5.url}",
"#{Discourse.base_url}#{upload6.url}",
"#{Discourse.base_url}#{upload7.url}"
)
expect(paths).to contain_exactly(
upload1.url,
upload4.url,
upload2.url,
nil
nil,
upload5.url,
upload6.url,
upload7.url
)
end