diff --git a/README.md b/README.md index 855c9784..b6ba9e2a 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ Adding Support for a new URL ---------------------------- 1. Check if the site supports [oEmbed](http://oembed.com/) or [Open Graph](https://developers.facebook.com/docs/opengraph/). - If it does, you can probably get away with just allowlisting the URL in `Onebox::Engine::AllowlistedGenericOnebox` (see: [Allowlisted Generic Onebox caveats](#user-content-allowlisted-generic-onebox-caveats)). + If it does, you can probably get away with just allowing the URL in `Onebox::Engine::AllowlistedGenericOnebox` (see: [Allowlisted Generic Onebox caveats](#user-content-allowlisted-generic-onebox-caveats)). If the site does not support open standards, you can create a new engine. 2. Create new onebox engine diff --git a/lib/onebox/engine/allowlisted_generic_onebox.rb b/lib/onebox/engine/allowlisted_generic_onebox.rb index b476926f..d10c2e84 100644 --- a/lib/onebox/engine/allowlisted_generic_onebox.rb +++ b/lib/onebox/engine/allowlisted_generic_onebox.rb @@ -9,15 +9,15 @@ class AllowlistedGenericOnebox include StandardEmbed include LayoutSupport - def self.allowlist=(list) - @allowlist = list + def self.allowed_domains=(list) + @allowed_domains = list end - def self.allowlist - @allowlist ||= default_allowlist.dup + def self.allowed_domains + @allowed_domains ||= default_allowed_domains.dup end - def self.default_allowlist + def self.default_allowed_domains %w( 23hq.com 500px.com @@ -176,13 +176,13 @@ def self.probable_wordpress(uri) !!(uri.path =~ /\d{4}\/\d{2}\//) end - def self.twitter_label_allowlist + def self.allowed_twitter_labels ['brand', 'price', 'usd', 'cad', 'reading time', 'likes'] end def self.===(other) other.kind_of?(URI) ? - host_matches(other, allowlist) || probable_wordpress(other) || probable_discourse(other) : + host_matches(other, allowed_domains) || probable_wordpress(other) || probable_discourse(other) : super end @@ -233,11 +233,11 @@ def data end # Twitter labels - if !Onebox::Helpers.blank?(d[:label1]) && !Onebox::Helpers.blank?(d[:data1]) && !!AllowlistedGenericOnebox.twitter_label_allowlist.find { |l| d[:label1] =~ /#{l}/i } + if !Onebox::Helpers.blank?(d[:label1]) && !Onebox::Helpers.blank?(d[:data1]) && !!AllowlistedGenericOnebox.allowed_twitter_labels.find { |l| d[:label1] =~ /#{l}/i } d[:label_1] = Onebox::Helpers.truncate(d[:label1]) d[:data_1] = Onebox::Helpers.truncate(d[:data1]) end - if !Onebox::Helpers.blank?(d[:label2]) && !Onebox::Helpers.blank?(d[:data2]) && !!AllowlistedGenericOnebox.twitter_label_allowlist.find { |l| d[:label2] =~ /#{l}/i } + if !Onebox::Helpers.blank?(d[:label2]) && !Onebox::Helpers.blank?(d[:data2]) && !!AllowlistedGenericOnebox.allowed_twitter_labels.find { |l| d[:label2] =~ /#{l}/i } unless Onebox::Helpers.blank?(d[:label_1]) d[:label_2] = Onebox::Helpers.truncate(d[:label2]) d[:data_2] = Onebox::Helpers.truncate(d[:data2]) diff --git a/spec/lib/onebox/engine/allowlisted_generic_onebox_spec.rb b/spec/lib/onebox/engine/allowlisted_generic_onebox_spec.rb index 27a0e38d..5fee2a26 100644 --- a/spec/lib/onebox/engine/allowlisted_generic_onebox_spec.rb +++ b/spec/lib/onebox/engine/allowlisted_generic_onebox_spec.rb @@ -6,7 +6,7 @@ describe ".===" do before do - described_class.allowlist = %w(eviltrout.com discourse.org) + described_class.allowed_domains = %w(eviltrout.com discourse.org) end it "matches an entire domain" do @@ -154,7 +154,7 @@ def generic_html let(:redirect_link) { 'http://www.dailymail.co.uk/news/article-479146/Brutality-justice-The-truth-tarred-feathered-drug-dealer.html' } before do - described_class.allowlist = %w(dailymail.co.uk discourse.org) + described_class.allowed_domains = %w(dailymail.co.uk discourse.org) FakeWeb.register_uri( :get, original_link, diff --git a/spec/lib/onebox_spec.rb b/spec/lib/onebox_spec.rb index d66881b5..f6ca4f4f 100644 --- a/spec/lib/onebox_spec.rb +++ b/spec/lib/onebox_spec.rb @@ -24,7 +24,7 @@ def expect_templates_to_not_match(text) describe 'has_matcher?' do before do - Onebox::Engine::AllowlistedGenericOnebox.allowlist = %w(youtube.com) + Onebox::Engine::AllowlistedGenericOnebox.allowed_domains = %w(youtube.com) end it "has no matcher for a made up url" do