DEV: assign constant to `preserve_fragment_url_hosts`

DEV: assign constant to `preserve_fragment_url_hosts`
diff --git a/lib/oneboxer.rb b/lib/oneboxer.rb
index 69011d0..72d697c 100644
--- a/lib/oneboxer.rb
+++ b/lib/oneboxer.rb
@@ -260,7 +260,7 @@ module Oneboxer
   end
 
   def self.preserve_fragment_url_hosts
-    ['http://github.com']
+    @preserve_fragment_url_hosts ||= ['http://github.com']
   end
 
   def self.external_onebox(url)

GitHub
sha: e5fd018f

I wonder if we should only store the hostname instead of the URL? (github.com vs http://github.com)

2 Likes

URL is required here because we are parsing URI when matching hostname as per:

This results in:

[1] pry(main)> uri = URI.parse('github.com')
=> #<URI::Generic github.com>
[2] pry(main)> uri.hostname
=> nil
[3] pry(main)> uri = URI.parse('http://github.com')
=> #<URI::HTTP http://github.com>
[4] pry(main)> uri.hostname
=> "github.com"

I tried amending uri method to add schema when only domain is being passed but that resulted in failure of multiple specs, including:

So it is required by design to pass URL instead of domain. I took the initial cue (to add URL) from:

1 Like