From 775326dc372947cf0c9fc7ec587a9e3659a593ee Mon Sep 17 00:00:00 2001 From: nonamethanks Date: Sat, 1 Oct 2022 00:24:24 +0200 Subject: [PATCH] Tumblr: fix crash when uploading image links from custom domains --- app/logical/source/extractor/tumblr.rb | 4 ++-- test/unit/sources/tumblr_test.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/logical/source/extractor/tumblr.rb b/app/logical/source/extractor/tumblr.rb index 8889e25e3..866e0e70b 100644 --- a/app/logical/source/extractor/tumblr.rb +++ b/app/logical/source/extractor/tumblr.rb @@ -120,11 +120,11 @@ class Source::Extractor end def artist_name - parsed_url.blog_name || parsed_referer&.blog_name || post_url_from_image_html&.blog_name + parsed_url.blog_name || parsed_referer&.blog_name || post_url_from_image_html&.try(:blog_name) # Don't crash with custom domains end def work_id - parsed_url.work_id || parsed_referer&.work_id || post_url_from_image_html&.work_id + parsed_url.work_id || parsed_referer&.work_id || post_url_from_image_html&.try(:work_id) end def api_response diff --git a/test/unit/sources/tumblr_test.rb b/test/unit/sources/tumblr_test.rb index 6474a03ff..a5dcbefeb 100644 --- a/test/unit/sources/tumblr_test.rb +++ b/test/unit/sources/tumblr_test.rb @@ -186,6 +186,18 @@ module Sources ) end + context "A tumblr image url for which the extractable post url is a custom domain" do + strategy_should_work( + "https://64.media.tumblr.com/591b370b9deb7c6ef33d8c18dc2c8db5/tumblr_ph5huubDdz1w0f6yio1_1280.jpg", + image_urls: ["https://media.tumblr.com/591b370b9deb7c6ef33d8c18dc2c8db5/tumblr_ph5huubDdz1w0f6yio1_1280.jpg"], + profile_url: nil, + page_url: "https://compllege.com/post/181217216191" + # XXX this fails on purpose pending implementation of support for custom Tumblr domains + # Right now, if we extract and save the custom url as source, then next time the source is fetched the user won't be able to fetch anything from it, which can be confusing. + # A possible solution could be doing a head request for unknown domains in Source::Extractor::Null to check if they're custom tumblr domains + ) + end + context "generating page urls" do should "work" do source1 = "https://octrain1020.tumblr.com/post/190713122589"