From 7394660ba901bf0423f81537612dcb6b52d13d29 Mon Sep 17 00:00:00 2001 From: evazion Date: Sun, 20 Mar 2022 20:43:22 -0500 Subject: [PATCH] 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. --- app/logical/source/url/twitter.rb | 3 ++- app/logical/sources/strategies/foundation.rb | 2 +- app/logical/sources/strategies/hentai_foundry.rb | 2 +- app/logical/sources/strategies/lofter.rb | 2 +- app/logical/sources/strategies/newgrounds.rb | 2 +- app/logical/sources/strategies/skeb.rb | 2 +- app/logical/sources/strategies/twit_pic.rb | 2 +- app/logical/sources/strategies/twitter.rb | 2 +- test/unit/sources/twitter_test.rb | 1 + 9 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/logical/source/url/twitter.rb b/app/logical/source/url/twitter.rb index 57cf3db6f..ca49e6cda 100644 --- a/app/logical/source/url/twitter.rb +++ b/app/logical/source/url/twitter.rb @@ -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 diff --git a/app/logical/sources/strategies/foundation.rb b/app/logical/sources/strategies/foundation.rb index 2d1ba0eb7..daa039892 100644 --- a/app/logical/sources/strategies/foundation.rb +++ b/app/logical/sources/strategies/foundation.rb @@ -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 diff --git a/app/logical/sources/strategies/hentai_foundry.rb b/app/logical/sources/strategies/hentai_foundry.rb index f3e962e5c..29031317e 100644 --- a/app/logical/sources/strategies/hentai_foundry.rb +++ b/app/logical/sources/strategies/hentai_foundry.rb @@ -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 diff --git a/app/logical/sources/strategies/lofter.rb b/app/logical/sources/strategies/lofter.rb index 77e1baf86..d3dbf593b 100644 --- a/app/logical/sources/strategies/lofter.rb +++ b/app/logical/sources/strategies/lofter.rb @@ -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 diff --git a/app/logical/sources/strategies/newgrounds.rb b/app/logical/sources/strategies/newgrounds.rb index d985272fc..fdc1dd3b3 100644 --- a/app/logical/sources/strategies/newgrounds.rb +++ b/app/logical/sources/strategies/newgrounds.rb @@ -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 diff --git a/app/logical/sources/strategies/skeb.rb b/app/logical/sources/strategies/skeb.rb index 4c17b25e0..66008bcfa 100644 --- a/app/logical/sources/strategies/skeb.rb +++ b/app/logical/sources/strategies/skeb.rb @@ -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 diff --git a/app/logical/sources/strategies/twit_pic.rb b/app/logical/sources/strategies/twit_pic.rb index 1cfad1dea..944f0fb73 100644 --- a/app/logical/sources/strategies/twit_pic.rb +++ b/app/logical/sources/strategies/twit_pic.rb @@ -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 diff --git a/app/logical/sources/strategies/twitter.rb b/app/logical/sources/strategies/twitter.rb index 5ea6f37ff..8851bfae7 100644 --- a/app/logical/sources/strategies/twitter.rb +++ b/app/logical/sources/strategies/twitter.rb @@ -24,7 +24,7 @@ module Sources::Strategies end def match? - parsed_url&.site_name == "Twitter" + Source::URL::Twitter === parsed_url end def image_urls diff --git a/test/unit/sources/twitter_test.rb b/test/unit/sources/twitter_test.rb index 46de8c04a..cc562f6e9 100644 --- a/test/unit/sources/twitter_test.rb +++ b/test/unit/sources/twitter_test.rb @@ -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