From 757a7da49b40dcf0a0331988f5afdf25db894adb Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 10 May 2017 21:03:29 -0500 Subject: [PATCH] fixup! /source.json: don't encode '&' as '&' in commentaries. --- app/logical/sources/strategies/base.rb | 1 + test/unit/sources/pixiv_test.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/app/logical/sources/strategies/base.rb b/app/logical/sources/strategies/base.rb index c47822175..f1f4909c9 100644 --- a/app/logical/sources/strategies/base.rb +++ b/app/logical/sources/strategies/base.rb @@ -102,6 +102,7 @@ module Sources # Convert commentary to dtext by stripping html tags. Sites can override # this to customize how their markup is translated to dtext. def self.to_dtext(text) + text = text.to_s text = Rails::Html::FullSanitizer.new.sanitize(text, encode_special_chars: false) text = CGI::unescapeHTML(text) text diff --git a/test/unit/sources/pixiv_test.rb b/test/unit/sources/pixiv_test.rb index 7b5b9ea55..f6a5cb91c 100644 --- a/test/unit/sources/pixiv_test.rb +++ b/test/unit/sources/pixiv_test.rb @@ -91,6 +91,8 @@ module Sources should "get the artist commentary" do assert_not_nil(@site.artist_commentary_title) assert_not_nil(@site.artist_commentary_desc) + assert_not_nil(@site.dtext_artist_commentary_title) + assert_not_nil(@site.dtext_artist_commentary_desc) end should "convert a page into a json representation" do @@ -113,6 +115,17 @@ module Sources assert_equal("https://i.pximg.net/img-original/img/2014/10/29/09/27/19/46785915_p0.jpg", @site.image_url) end end + + context "fetching the commentary" do + setup do + get_source("https://www.pixiv.net/member_illust.php?mode=medium&illust_id=46337015") + end + + should "work when the description is blank" do + assert_equal("Illustration (PNG) - foo & bar", @site.dtext_artist_commentary_title) + assert_equal("", @site.dtext_artist_commentary_desc) + end + end end end end