Skip to content

A platform for community discussion. Free, open, simple.

FIX: bypass source fetch for Reddit oneboxes (#39182)

Rafael dos Santos Silva2c2f0bd906e4
diff --git a/lib/oneboxer.rb b/lib/oneboxer.rb
index 9c79e2fde09..db04b426ac9 100644
--- a/lib/oneboxer.rb
+++ b/lib/oneboxer.rb
@@ -28,6 +28,11 @@ module Oneboxer
"http://www.dropbox.com",
"http://store.steampowered.com",
"http://vimeo.com",
+ "https://reddit.com",
+ "https://www.reddit.com",
+ "https://old.reddit.com",
+ "https://np.reddit.com",
+ "https://new.reddit.com",
"https://www.youtube.com",
"https://youtu.be",
"https://twitter.com",
diff --git a/spec/lib/oneboxer_spec.rb b/spec/lib/oneboxer_spec.rb
index 3aaef4314ff..75178db70be 100644
--- a/spec/lib/oneboxer_spec.rb
+++ b/spec/lib/oneboxer_spec.rb
@@ -771,6 +771,35 @@ RSpec.describe Oneboxer do
expect(redirect_head_stub).to have_been_requested
end
end
+
+ context "with ignore_redirects for Reddit URLs" do
+ before { Discourse.cache.clear }
+
+ it "resolves Reddit URLs without requesting the source URL" do
+ reddit_url =
+ "https://www.reddit.com/r/colors/comments/b4d5xm/literally_nothing_black_edition"
+
+ head_stub =
+ stub_request(:head, reddit_url).to_return(
+ status: 301,
+ body: "",
+ headers: {
+ "location" => "#{reddit_url}/",
+ },
+ )
+
+ get_stub = stub_request(:get, reddit_url).to_return(status: 200, body: html)
+
+ result = Oneboxer.external_onebox(reddit_url)
+
+ expect(result[:onebox]).to be_present
+ expect(result[:onebox]).to include("https://embed.reddit.com/r/colors/comments/b4d5xm/")
+ expect(result[:preview]).to include("placeholder-icon generic")
+
+ expect(head_stub).not_to have_been_requested
+ expect(get_stub).not_to have_been_requested
+ end
+ end
end
describe "onebox custom user agent" do