diff --git a/README.md b/README.md index daa64792..a4d98231 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,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 whitelisting the URL in `Onebox::Engine::WhitelistedGenericOnebox` (see: [Whitelisted Generic Onebox caveats](#user-content-whitelisted-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 @@ -163,12 +163,12 @@ Adding Support for a new URL require_relative "engine/name_onebox" ``` -Whitelisted Generic Onebox caveats +Allowlisted Generic Onebox caveats ---------------------------------- -The Whitelisted Generic Onebox has some caveats for its use, beyond simply whitelisting the domain. +The Allowlisted Generic Onebox has some caveats for its use, beyond simply allowlisting the domain. - 1. The domain must be whitelisted + 1. The domain must be allowlisted 2. The URL you're oneboxing cannot be a root url (e.g. `http://example.com` won't work, but `http://example.com/page` will) 3. If the oneboxed URL responds with oEmbed and has a `rich` type: the `html` content must contain an ` HTML else - html = Onebox::Engine::WhitelistedGenericOnebox.new(@url, @timeout).to_html + html = Onebox::Engine::AllowlistedGenericOnebox.new(@url, @timeout).to_html return if Onebox::Helpers.blank?(html) html end diff --git a/lib/onebox/engine/gfycat_onebox.rb b/lib/onebox/engine/gfycat_onebox.rb index 97e188e8..702ab1be 100644 --- a/lib/onebox/engine/gfycat_onebox.rb +++ b/lib/onebox/engine/gfycat_onebox.rb @@ -10,7 +10,7 @@ class GfycatOnebox always_https def self.priority - # This engine should have priority over WhitelistedGenericOnebox. + # This engine should have priority over AllowlistedGenericOnebox. 1 end diff --git a/lib/onebox/engine/image_onebox.rb b/lib/onebox/engine/image_onebox.rb index dc7f1901..91d64f69 100644 --- a/lib/onebox/engine/image_onebox.rb +++ b/lib/onebox/engine/image_onebox.rb @@ -8,7 +8,7 @@ class ImageOnebox matches_regexp(/^(https?:)?\/\/.+\.(png|jpg|jpeg|gif|bmp|tif|tiff)(\?.*)?$/i) def always_https? - WhitelistedGenericOnebox.host_matches(uri, WhitelistedGenericOnebox.https_hosts) + AllowlistedGenericOnebox.host_matches(uri, AllowlistedGenericOnebox.https_hosts) end def to_html diff --git a/lib/onebox/engine/reddit_media_onebox.rb b/lib/onebox/engine/reddit_media_onebox.rb index f7db11a9..c9d6cdcb 100644 --- a/lib/onebox/engine/reddit_media_onebox.rb +++ b/lib/onebox/engine/reddit_media_onebox.rb @@ -45,7 +45,7 @@ def to_html HTML else - html = Onebox::Engine::WhitelistedGenericOnebox.new(@url, @timeout).to_html + html = Onebox::Engine::AllowlistedGenericOnebox.new(@url, @timeout).to_html return if Onebox::Helpers.blank?(html) html end diff --git a/lib/onebox/engine/standard_embed.rb b/lib/onebox/engine/standard_embed.rb index 9654161b..9116476c 100644 --- a/lib/onebox/engine/standard_embed.rb +++ b/lib/onebox/engine/standard_embed.rb @@ -32,7 +32,7 @@ def self.add_opengraph_provider(regexp) add_oembed_provider(/nytimes\.com\//, 'https://www.nytimes.com/svc/oembed/json/') def always_https? - WhitelistedGenericOnebox.host_matches(uri, WhitelistedGenericOnebox.https_hosts) || super + AllowlistedGenericOnebox.host_matches(uri, AllowlistedGenericOnebox.https_hosts) || super end def raw diff --git a/lib/onebox/engine/video_onebox.rb b/lib/onebox/engine/video_onebox.rb index e22904f8..1be12a06 100644 --- a/lib/onebox/engine/video_onebox.rb +++ b/lib/onebox/engine/video_onebox.rb @@ -8,7 +8,7 @@ class VideoOnebox matches_regexp(/^(https?:)?\/\/.*\.(mov|mp4|webm|ogv)(\?.*)?$/i) def always_https? - WhitelistedGenericOnebox.host_matches(uri, WhitelistedGenericOnebox.https_hosts) + AllowlistedGenericOnebox.host_matches(uri, AllowlistedGenericOnebox.https_hosts) end def to_html diff --git a/lib/onebox/engine/youtube_onebox.rb b/lib/onebox/engine/youtube_onebox.rb index 7d25f392..8ee3ad12 100644 --- a/lib/onebox/engine/youtube_onebox.rb +++ b/lib/onebox/engine/youtube_onebox.rb @@ -45,7 +45,7 @@ def to_html HTML else # for channel pages - html = Onebox::Engine::WhitelistedGenericOnebox.new(@url, @timeout).to_html + html = Onebox::Engine::AllowlistedGenericOnebox.new(@url, @timeout).to_html return if Onebox::Helpers.blank?(html) html.gsub!(/['"]\/\//, "https://") html diff --git a/lib/onebox/matcher.rb b/lib/onebox/matcher.rb index f628306e..4978bc3e 100644 --- a/lib/onebox/matcher.rb +++ b/lib/onebox/matcher.rb @@ -16,7 +16,10 @@ def oneboxed uri = URI(@url) return unless uri.port.nil? || Onebox.options.allowed_ports.include?(uri.port) return unless uri.scheme.nil? || Onebox.options.allowed_schemes.include?(uri.scheme) - ordered_engines.find { |engine| engine === uri } + ordered_engines + .select { |engine| engine === uri } + .sort_by { |engine| engine.to_s } + .last rescue URI::InvalidURIError nil end diff --git a/lib/onebox/version.rb b/lib/onebox/version.rb index 32428381..1191407b 100644 --- a/lib/onebox/version.rb +++ b/lib/onebox/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Onebox - VERSION = "1.9.30" + VERSION = "2.0.0" end diff --git a/spec/fixtures/discourse_topic.response b/spec/fixtures/discourse_topic.response index 197d16dc..00a0e24f 100644 --- a/spec/fixtures/discourse_topic.response +++ b/spec/fixtures/discourse_topic.response @@ -355,7 +355,7 @@ And that too in just over an year, way to go! [boom]"> - + diff --git a/spec/fixtures/discourse_topic_reply.response b/spec/fixtures/discourse_topic_reply.response index a767b381..d204320e 100644 --- a/spec/fixtures/discourse_topic_reply.response +++ b/spec/fixtures/discourse_topic_reply.response @@ -351,7 +351,7 @@ And that too in just over an year, way to go! [boom]"> - + diff --git a/spec/lib/onebox/engine/whitelisted_generic_onebox_spec.rb b/spec/lib/onebox/engine/allowlisted_generic_onebox_spec.rb similarity index 90% rename from spec/lib/onebox/engine/whitelisted_generic_onebox_spec.rb rename to spec/lib/onebox/engine/allowlisted_generic_onebox_spec.rb index 9a13e5b4..5fee2a26 100644 --- a/spec/lib/onebox/engine/whitelisted_generic_onebox_spec.rb +++ b/spec/lib/onebox/engine/allowlisted_generic_onebox_spec.rb @@ -2,11 +2,11 @@ require "spec_helper" -describe Onebox::Engine::WhitelistedGenericOnebox do +describe Onebox::Engine::AllowlistedGenericOnebox do describe ".===" do before do - described_class.whitelist = %w(eviltrout.com discourse.org) + described_class.allowed_domains = %w(eviltrout.com discourse.org) end it "matches an entire domain" do @@ -31,7 +31,7 @@ end describe 'html_providers' do - class HTMLOnebox < Onebox::Engine::WhitelistedGenericOnebox + class HTMLOnebox < Onebox::Engine::AllowlistedGenericOnebox def data { html: 'cool html', @@ -42,30 +42,30 @@ def data end it "doesn't return the HTML when not in the `html_providers`" do - Onebox::Engine::WhitelistedGenericOnebox.html_providers = [] + Onebox::Engine::AllowlistedGenericOnebox.html_providers = [] expect(HTMLOnebox.new("http://coolsite.com").to_html).to be_nil end it "returns the HMTL when in the `html_providers`" do - Onebox::Engine::WhitelistedGenericOnebox.html_providers = ['CoolSite'] + Onebox::Engine::AllowlistedGenericOnebox.html_providers = ['CoolSite'] expect(HTMLOnebox.new("http://coolsite.com").to_html).to eq "cool html" end end describe 'rewrites' do - class DummyOnebox < Onebox::Engine::WhitelistedGenericOnebox + class DummyOnebox < Onebox::Engine::AllowlistedGenericOnebox def generic_html "" end end it "doesn't rewrite URLs that arent in the list" do - Onebox::Engine::WhitelistedGenericOnebox.rewrites = [] + Onebox::Engine::AllowlistedGenericOnebox.rewrites = [] expect(DummyOnebox.new("http://youtube.com").to_html).to eq "" end - it "rewrites URLs when whitelisted" do - Onebox::Engine::WhitelistedGenericOnebox.rewrites = %w(youtube.com) + it "rewrites URLs when allowlisted" do + Onebox::Engine::AllowlistedGenericOnebox.rewrites = %w(youtube.com) expect(DummyOnebox.new("http://youtube.com").to_html).to eq "" end end @@ -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.whitelist = %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/layout_spec.rb b/spec/lib/onebox/layout_spec.rb index 07415f0f..cd6b4f7f 100644 --- a/spec/lib/onebox/layout_spec.rb +++ b/spec/lib/onebox/layout_spec.rb @@ -59,7 +59,7 @@ it "rewrites relative image path" do record = { image: "/image.png", link: "https://discourse.org" } - klass = described_class.new("whitelistedgeneric", record) + klass = described_class.new("allowlistedgeneric", record) expect(klass.view.record[:image]).to include("https://discourse.org") end end diff --git a/spec/lib/onebox/matcher_spec.rb b/spec/lib/onebox/matcher_spec.rb index 2905a8d9..419d71bd 100644 --- a/spec/lib/onebox/matcher_spec.rb +++ b/spec/lib/onebox/matcher_spec.rb @@ -52,7 +52,7 @@ def self.===(uri) end end - describe "with a whitelisted port/scheme" do + describe "with a allowlisted port/scheme" do %w{http://example.com https://example.com http://example.com:80 //example.com}.each do |url| it "finds an engine for '#{url}'" do matcher = Onebox::Matcher.new(url) @@ -62,7 +62,7 @@ def self.===(uri) end end - describe "without a whitelisted port/scheme" do + describe "without a allowlisted port/scheme" do %w{http://example.com:21 ftp://example.com}.each do |url| it "doesn't find an engine for '#{url}'" do matcher = Onebox::Matcher.new(url) diff --git a/spec/lib/onebox_spec.rb b/spec/lib/onebox_spec.rb index e1bee2ec..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::WhitelistedGenericOnebox.whitelist = %w(youtube.com) + Onebox::Engine::AllowlistedGenericOnebox.allowed_domains = %w(youtube.com) end it "has no matcher for a made up url" do diff --git a/templates/whitelistedgeneric.mustache b/templates/allowlistedgeneric.mustache similarity index 100% rename from templates/whitelistedgeneric.mustache rename to templates/allowlistedgeneric.mustache