FIX: ensure emojis have absolute URLs and uses CDN
This commit is contained in:
parent
6ed03bf3d9
commit
caa1aea995
|
@ -3,8 +3,7 @@ class UrlHelper
|
||||||
def self.is_local(url)
|
def self.is_local(url)
|
||||||
url.present? && (
|
url.present? && (
|
||||||
Discourse.store.has_been_uploaded?(url) ||
|
Discourse.store.has_been_uploaded?(url) ||
|
||||||
!!(url =~ /^\/assets\//) ||
|
!!(url =~ /^\/(assets|plugins|images)\//) ||
|
||||||
!!(url =~ /^\/plugins\//) ||
|
|
||||||
url.start_with?(Discourse.asset_host || Discourse.base_url_no_prefix)
|
url.start_with?(Discourse.asset_host || Discourse.base_url_no_prefix)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
@ -384,7 +384,7 @@ describe CookedPostProcessor do
|
||||||
|
|
||||||
it "uses schemaless url for uploads" do
|
it "uses schemaless url for uploads" do
|
||||||
cpp.optimize_urls
|
cpp.optimize_urls
|
||||||
expect(cpp.html).to match_html '<p><a href="//test.localhost/uploads/default/2/2345678901234567.jpg">Link</a><br><img src="//test.localhost/uploads/default/1/1234567890123456.jpg"><br><a href="http://www.google.com" rel="nofollow">Google</a><br><img src="http://foo.bar/image.png"><br><a class="attachment" href="//test.localhost/uploads/default/original/1X/af2c2618032c679333bebf745e75f9088748d737.txt">text.txt</a> (20 Bytes)</p>'
|
expect(cpp.html).to match_html '<p><a href="//test.localhost/uploads/default/2/2345678901234567.jpg">Link</a><br><img src="//test.localhost/uploads/default/1/1234567890123456.jpg"><br><a href="http://www.google.com" rel="nofollow">Google</a><br><img src="http://foo.bar/image.png"><br><a class="attachment" href="//test.localhost/uploads/default/original/1X/af2c2618032c679333bebf745e75f9088748d737.txt">text.txt</a> (20 Bytes)<br><img src="//test.localhost/images/emoji/emoji_one/smile.png?v=2" title=":smile:" class="emoji" alt=":smile:"></p>'
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when CDN is enabled" do
|
context "when CDN is enabled" do
|
||||||
|
@ -392,20 +392,20 @@ describe CookedPostProcessor do
|
||||||
it "does use schemaless CDN url for http uploads" do
|
it "does use schemaless CDN url for http uploads" do
|
||||||
Rails.configuration.action_controller.stubs(:asset_host).returns("http://my.cdn.com")
|
Rails.configuration.action_controller.stubs(:asset_host).returns("http://my.cdn.com")
|
||||||
cpp.optimize_urls
|
cpp.optimize_urls
|
||||||
expect(cpp.html).to match_html '<p><a href="//my.cdn.com/uploads/default/2/2345678901234567.jpg">Link</a><br><img src="//my.cdn.com/uploads/default/1/1234567890123456.jpg"><br><a href="http://www.google.com" rel="nofollow">Google</a><br><img src="http://foo.bar/image.png"><br><a class="attachment" href="//my.cdn.com/uploads/default/original/1X/af2c2618032c679333bebf745e75f9088748d737.txt">text.txt</a> (20 Bytes)</p>'
|
expect(cpp.html).to match_html '<p><a href="//my.cdn.com/uploads/default/2/2345678901234567.jpg">Link</a><br><img src="//my.cdn.com/uploads/default/1/1234567890123456.jpg"><br><a href="http://www.google.com" rel="nofollow">Google</a><br><img src="http://foo.bar/image.png"><br><a class="attachment" href="//my.cdn.com/uploads/default/original/1X/af2c2618032c679333bebf745e75f9088748d737.txt">text.txt</a> (20 Bytes)<br><img src="//my.cdn.com/images/emoji/emoji_one/smile.png?v=2" title=":smile:" class="emoji" alt=":smile:"></p>'
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not use schemaless CDN url for https uploads" do
|
it "does not use schemaless CDN url for https uploads" do
|
||||||
Rails.configuration.action_controller.stubs(:asset_host).returns("https://my.cdn.com")
|
Rails.configuration.action_controller.stubs(:asset_host).returns("https://my.cdn.com")
|
||||||
cpp.optimize_urls
|
cpp.optimize_urls
|
||||||
expect(cpp.html).to match_html '<p><a href="https://my.cdn.com/uploads/default/2/2345678901234567.jpg">Link</a><br><img src="https://my.cdn.com/uploads/default/1/1234567890123456.jpg"><br><a href="http://www.google.com" rel="nofollow">Google</a><br><img src="http://foo.bar/image.png"><br><a class="attachment" href="https://my.cdn.com/uploads/default/original/1X/af2c2618032c679333bebf745e75f9088748d737.txt">text.txt</a> (20 Bytes)</p>'
|
expect(cpp.html).to match_html '<p><a href="https://my.cdn.com/uploads/default/2/2345678901234567.jpg">Link</a><br><img src="https://my.cdn.com/uploads/default/1/1234567890123456.jpg"><br><a href="http://www.google.com" rel="nofollow">Google</a><br><img src="http://foo.bar/image.png"><br><a class="attachment" href="https://my.cdn.com/uploads/default/original/1X/af2c2618032c679333bebf745e75f9088748d737.txt">text.txt</a> (20 Bytes)<br><img src="https://my.cdn.com/images/emoji/emoji_one/smile.png?v=2" title=":smile:" class="emoji" alt=":smile:"></p>'
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not use CDN when login is required" do
|
it "does not use CDN when login is required" do
|
||||||
SiteSetting.login_required = true
|
SiteSetting.login_required = true
|
||||||
Rails.configuration.action_controller.stubs(:asset_host).returns("http://my.cdn.com")
|
Rails.configuration.action_controller.stubs(:asset_host).returns("http://my.cdn.com")
|
||||||
cpp.optimize_urls
|
cpp.optimize_urls
|
||||||
expect(cpp.html).to match_html '<p><a href="//my.cdn.com/uploads/default/2/2345678901234567.jpg">Link</a><br><img src="//my.cdn.com/uploads/default/1/1234567890123456.jpg"><br><a href="http://www.google.com" rel="nofollow">Google</a><br><img src="http://foo.bar/image.png"><br><a class="attachment" href="//test.localhost/uploads/default/original/1X/af2c2618032c679333bebf745e75f9088748d737.txt">text.txt</a> (20 Bytes)</p>'
|
expect(cpp.html).to match_html '<p><a href="//my.cdn.com/uploads/default/2/2345678901234567.jpg">Link</a><br><img src="//my.cdn.com/uploads/default/1/1234567890123456.jpg"><br><a href="http://www.google.com" rel="nofollow">Google</a><br><img src="http://foo.bar/image.png"><br><a class="attachment" href="//test.localhost/uploads/default/original/1X/af2c2618032c679333bebf745e75f9088748d737.txt">text.txt</a> (20 Bytes)<br><img src="//my.cdn.com/images/emoji/emoji_one/smile.png?v=2" title=":smile:" class="emoji" alt=":smile:"></p>'
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -101,6 +101,7 @@ Fabricator(:post_with_uploads_and_links, from: :post) do
|
||||||
<a href="http://www.google.com">Google</a>
|
<a href="http://www.google.com">Google</a>
|
||||||
<img src="http://foo.bar/image.png">
|
<img src="http://foo.bar/image.png">
|
||||||
<a class="attachment" href="/uploads/default/original/1X/af2c2618032c679333bebf745e75f9088748d737.txt">text.txt</a> (20 Bytes)
|
<a class="attachment" href="/uploads/default/original/1X/af2c2618032c679333bebf745e75f9088748d737.txt">text.txt</a> (20 Bytes)
|
||||||
|
:smile:
|
||||||
'
|
'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue