From 22c9cfcec51a744a7986783afb8370287dc21616 Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 18 Nov 2017 10:54:56 -0600 Subject: [PATCH] Fix #3384: Fetch commentary not creating fully formed textile links --- app/logical/sources/strategies/deviant_art.rb | 7 +++++++ test/unit/sources/deviantart_test.rb | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/app/logical/sources/strategies/deviant_art.rb b/app/logical/sources/strategies/deviant_art.rb index e7b54dd2d..69c1d0137 100644 --- a/app/logical/sources/strategies/deviant_art.rb +++ b/app/logical/sources/strategies/deviant_art.rb @@ -44,6 +44,13 @@ module Sources DText.from_html(text) do |element| if element.name == "a" && element["href"].present? element["href"] = element["href"].gsub(%r!\Ahttps?://www\.deviantart\.com/users/outgoing\?!i, "") + + # href may be missing the `http://` bit (ex: `inprnt.com`, `//inprnt.com`). Add it if missing. + uri = Addressable::URI.heuristic_parse(element["href"]) rescue nil + if uri.present? + uri.scheme ||= "http" + element["href"] = uri.to_s + end end end end diff --git a/test/unit/sources/deviantart_test.rb b/test/unit/sources/deviantart_test.rb index 81dd8b910..649392587 100644 --- a/test/unit/sources/deviantart_test.rb +++ b/test/unit/sources/deviantart_test.rb @@ -82,5 +82,14 @@ module Sources assert_equal("http://orig14.deviantart.net/cb25/f/2017/160/1/9/hidden_work_by_noizave-dbc3r29.png", @site.image_url) end end + + context "A source with malformed links in the artist commentary" do + should "fix the links" do + @site = Sources::Site.new("https://teemutaiga.deviantart.com/art/Kisu-620666655") + @site.get + + assert_match(%r!"Print available at Inprnt":\[http://www.inprnt.com/gallery/teemutaiga/kisu\]!, @site.dtext_artist_commentary_desc) + end + end end end