posts: fix exception when post has source like 'https://www.twitter.com/username'.
`twitter.com` sources worked but `www.twitter.com` didn't. Also match the URL by class instead of by site name to ensure we match the expected class.
This commit is contained in:
@@ -29,7 +29,8 @@ class Source::URL::Twitter < Source::URL
|
||||
attr_reader :status_id, :twitter_username, :user_id
|
||||
|
||||
def self.match?(url)
|
||||
url.host.in?(%w[twitter.com mobile.twitter.com pic.twitter.com pbs.twimg.com video.twimg.com t.co])
|
||||
return false if Source::URL::TwitPic.match?(url) # TwitPic uses https://o.twimg.com/ URLs
|
||||
url.domain.in?(%w[twitter.com twimg.com t.co])
|
||||
end
|
||||
|
||||
def parse
|
||||
|
||||
@@ -5,7 +5,7 @@ module Sources
|
||||
module Strategies
|
||||
class Foundation < Base
|
||||
def match?
|
||||
parsed_url&.site_name == "Foundation"
|
||||
Source::URL::Foundation === parsed_url
|
||||
end
|
||||
|
||||
def image_urls
|
||||
|
||||
@@ -5,7 +5,7 @@ module Sources
|
||||
module Strategies
|
||||
class HentaiFoundry < Base
|
||||
def match?
|
||||
parsed_url&.site_name == "Hentai Foundry"
|
||||
Source::URL::HentaiFoundry === parsed_url
|
||||
end
|
||||
|
||||
def image_urls
|
||||
|
||||
@@ -5,7 +5,7 @@ module Sources
|
||||
module Strategies
|
||||
class Lofter < Base
|
||||
def match?
|
||||
parsed_url&.site_name == "Lofter"
|
||||
Source::URL::Lofter === parsed_url
|
||||
end
|
||||
|
||||
def image_urls
|
||||
|
||||
@@ -5,7 +5,7 @@ module Sources
|
||||
module Strategies
|
||||
class Newgrounds < Base
|
||||
def match?
|
||||
parsed_url&.site_name == "Newgrounds"
|
||||
Source::URL::Newgrounds === parsed_url
|
||||
end
|
||||
|
||||
def image_urls
|
||||
|
||||
@@ -5,7 +5,7 @@ module Sources
|
||||
module Strategies
|
||||
class Skeb < Base
|
||||
def match?
|
||||
parsed_url&.site_name == "Skeb"
|
||||
Source::URL::Skeb === parsed_url
|
||||
end
|
||||
|
||||
def image_urls
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
module Sources::Strategies
|
||||
class TwitPic < Base
|
||||
def match?
|
||||
parsed_url&.site_name == "TwitPic"
|
||||
Source::URL::TwitPic === parsed_url
|
||||
end
|
||||
|
||||
def normalize_for_source
|
||||
|
||||
@@ -24,7 +24,7 @@ module Sources::Strategies
|
||||
end
|
||||
|
||||
def match?
|
||||
parsed_url&.site_name == "Twitter"
|
||||
Source::URL::Twitter === parsed_url
|
||||
end
|
||||
|
||||
def image_urls
|
||||
|
||||
@@ -302,6 +302,7 @@ module Sources
|
||||
assert_equal(source2, Sources::Strategies.normalize_source(source2))
|
||||
assert_equal(source2, Sources::Strategies.normalize_source(source3))
|
||||
assert_equal(source2, Sources::Strategies.normalize_source(source4))
|
||||
assert_equal("https://www.twitter.com/irt_5433", Sources::Strategies.normalize_source("https://www.twitter.com/irt_5433"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user