FIX: Set priority for allowlisted_generic_onebox

FIX: Set priority for allowlisted_generic_onebox

Previously we were relying on whitelisted_generic_onebox being late in the alphabet, and therefore lower priority. Now that the name starts with a, we can’t rely on that side effect, so we need to explicitly set the priority.

c27aebce contained a workaround to reverse the alphabetical ordering, but this caused onebox engine priorities to be discarded.

diff --git a/lib/onebox/engine/allowlisted_generic_onebox.rb b/lib/onebox/engine/allowlisted_generic_onebox.rb
index d10c2e8..da71583 100644
--- a/lib/onebox/engine/allowlisted_generic_onebox.rb
+++ b/lib/onebox/engine/allowlisted_generic_onebox.rb
@@ -9,6 +9,10 @@ module Onebox
       include StandardEmbed
       include LayoutSupport
 
+      def self.priority
+        200
+      end
+
       def self.allowed_domains=(list)
         @allowed_domains = list
       end
diff --git a/lib/onebox/matcher.rb b/lib/onebox/matcher.rb
index 4978bc3..f628306 100644
--- a/lib/onebox/matcher.rb
+++ b/lib/onebox/matcher.rb
@@ -16,10 +16,7 @@ module Onebox
       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
-        .select { |engine| engine === uri }
-        .sort_by { |engine| engine.to_s }
-        .last
+      ordered_engines.find { |engine| engine === uri }
     rescue URI::InvalidURIError
       nil
     end
diff --git a/lib/onebox/version.rb b/lib/onebox/version.rb
index 1191407..4f05b1c 100644
--- a/lib/onebox/version.rb
+++ b/lib/onebox/version.rb
@@ -1,5 +1,5 @@
 # frozen_string_literal: true
 
 module Onebox
-  VERSION = "2.0.0"
+  VERSION = "2.0.1"
 end

GitHub sha: eb783a5c

1 Like