Loading Changelog.md +1 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ ## Refactor ## Bug fixes * Improve handling of mixed case hostnames while fetching OpenGraph data [#8021](https://github.com/diaspora/diaspora/pull/8021) ## Features * Add line mentioning diaspora\* on the splash page [#7966](https://github.com/diaspora/diaspora/pull/7966) Loading app/models/open_graph_cache.rb +3 −1 Original line number Diff line number Diff line Loading @@ -33,7 +33,9 @@ class OpenGraphCache < ApplicationRecord end def fetch_and_save_opengraph_data! object = OpenGraphReader.fetch!(self.url) uri = URI.parse(url.start_with?("http") ? url : "http://#{url}") uri.normalize! object = OpenGraphReader.fetch!(uri) return unless object Loading spec/models/open_graph_cache_spec.rb +19 −2 Original line number Diff line number Diff line Loading @@ -8,7 +8,7 @@ describe OpenGraphCache, type: :model do describe "fetch_and_save_opengraph_data!" do context "with an unsecure video url" do it "doesn't save the video url" do expect(OpenGraphReader).to receive(:fetch!).with("https://example.com/article/123").and_return( expect(OpenGraphReader).to receive(:fetch!).with(URI.parse("https://example.com/article/123")).and_return( double( og: double( description: "This is the article lead", Loading @@ -34,7 +34,7 @@ describe OpenGraphCache, type: :model do context "with a secure video url" do it "saves the video url" do expect(OpenGraphReader).to receive(:fetch!).with("https://example.com/article/123").and_return( expect(OpenGraphReader).to receive(:fetch!).with(URI.parse("https://example.com/article/123")).and_return( double( og: double( description: "This is the article lead", Loading @@ -57,5 +57,22 @@ describe OpenGraphCache, type: :model do expect(ogc.video_url).to eq("https://bandcamp.com/EmbeddedPlayer/v=2/track=12/size=small") end end context "a mixed case hostname" do it "downcases the hostname" do stub_request(:head, "http:///wetter.com") .with(headers: { "Accept" => "text/html", "User-Agent" => "OpenGraphReader/0.6.2 (+https://github.com/jhass/open_graph_reader)" }) .to_return(status: 200, body: "", headers: {"Set-Cookie" => "Dabgroup=A;path=/;Expires=Thu, 23 May 2019 16:12:01 GMT;httpOnly"}) ogc = OpenGraphCache.new(url: "Wetter.com") expect { ogc.fetch_and_save_opengraph_data! }.to_not raise_error end end end end Loading
Changelog.md +1 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ ## Refactor ## Bug fixes * Improve handling of mixed case hostnames while fetching OpenGraph data [#8021](https://github.com/diaspora/diaspora/pull/8021) ## Features * Add line mentioning diaspora\* on the splash page [#7966](https://github.com/diaspora/diaspora/pull/7966) Loading
app/models/open_graph_cache.rb +3 −1 Original line number Diff line number Diff line Loading @@ -33,7 +33,9 @@ class OpenGraphCache < ApplicationRecord end def fetch_and_save_opengraph_data! object = OpenGraphReader.fetch!(self.url) uri = URI.parse(url.start_with?("http") ? url : "http://#{url}") uri.normalize! object = OpenGraphReader.fetch!(uri) return unless object Loading
spec/models/open_graph_cache_spec.rb +19 −2 Original line number Diff line number Diff line Loading @@ -8,7 +8,7 @@ describe OpenGraphCache, type: :model do describe "fetch_and_save_opengraph_data!" do context "with an unsecure video url" do it "doesn't save the video url" do expect(OpenGraphReader).to receive(:fetch!).with("https://example.com/article/123").and_return( expect(OpenGraphReader).to receive(:fetch!).with(URI.parse("https://example.com/article/123")).and_return( double( og: double( description: "This is the article lead", Loading @@ -34,7 +34,7 @@ describe OpenGraphCache, type: :model do context "with a secure video url" do it "saves the video url" do expect(OpenGraphReader).to receive(:fetch!).with("https://example.com/article/123").and_return( expect(OpenGraphReader).to receive(:fetch!).with(URI.parse("https://example.com/article/123")).and_return( double( og: double( description: "This is the article lead", Loading @@ -57,5 +57,22 @@ describe OpenGraphCache, type: :model do expect(ogc.video_url).to eq("https://bandcamp.com/EmbeddedPlayer/v=2/track=12/size=small") end end context "a mixed case hostname" do it "downcases the hostname" do stub_request(:head, "http:///wetter.com") .with(headers: { "Accept" => "text/html", "User-Agent" => "OpenGraphReader/0.6.2 (+https://github.com/jhass/open_graph_reader)" }) .to_return(status: 200, body: "", headers: {"Set-Cookie" => "Dabgroup=A;path=/;Expires=Thu, 23 May 2019 16:12:01 GMT;httpOnly"}) ogc = OpenGraphCache.new(url: "Wetter.com") expect { ogc.fetch_and_save_opengraph_data! }.to_not raise_error end end end end