Fix #4720: Pixiv commentary links all create invalid urls.

Regression caused by the switch from the mobile API to the Ajax API. In
the Ajax API, commentaries have /jump.php?<url> links that we have to strip out.
This commit is contained in:
evazion
2021-02-13 17:41:01 -06:00
parent 39cc3ed5cf
commit 23a06aff1d
2 changed files with 21 additions and 1 deletions

View File

@@ -66,12 +66,17 @@ module Sources
text = text.gsub(%r{<a href="https?://www\.pixiv\.net/en/users/([0-9]+)">user/[0-9]+</a>}i) do |_match|
member_id = $1
profile_url = "https://www.pixiv.net/users/#{member_id}"
artist_search_url = Routes.artists_path(search: { url_matches: profile_url })
%("user/#{member_id}":[#{profile_url}] "»":[#{artist_search_url}])
end
DText.from_html(text)
DText.from_html(text) do |element|
if element.name == "a" && element["href"].match?(%r!\A/jump\.php\?!)
element["href"] = Addressable::URI.heuristic_parse(element["href"]).normalized_query
end
end
end
def domains

View File

@@ -196,6 +196,21 @@ module Sources
dtext_desc = %(foo 【[b]pixiv #46337015 "»":[/posts?tags=pixiv%3A46337015][/b]】bar 【[b]pixiv #14901720 "»":[/posts?tags=pixiv%3A14901720][/b]】\n\nbaz【[b]"user/83739":[https://www.pixiv.net/users/83739] "»":[/artists?search%5Burl_matches%5D=https%3A%2F%2Fwww.pixiv.net%2Fusers%2F83739][/b]】)
assert_equal(dtext_desc, @site.dtext_artist_commentary_desc)
end
should "convert jump.php links" do
get_source("https://www.pixiv.net/en/artworks/68955584")
dtext_desc = <<~EOS
([b]pixiv #68490887 "»":[/posts?tags=pixiv%3A68490887][/b])を一部加筆して再版しました。通販在庫復活しているのでよろしければ▷<https://www.melonbooks.co.jp/detail/detail.php?product_id=364421>
 13
pixivFANBOX開設してみました稿(:˒[]<https://www.pixiv.net/fanbox/creator/143555>
EOS
assert_equal(dtext_desc.chomp, @site.dtext_artist_commentary_desc)
end
end
context "translating the tags" do