sources: don't escape Unicode characters in tag search URLs.
Fix it so that Unicode characters aren't unnecessarily percent-encoded when generating tag search URLs. For example, generate URLs like this: * https://www.pixiv.net/tags/オリジナル/artworks Not like this: * https://www.pixiv.net/tags/%E3%82%AA%E3%83%AA%E3%82%B8%E3%83%8A%E3%83%AB/artworks
This commit is contained in:
@@ -68,6 +68,17 @@ module Danbooru
|
||||
nil
|
||||
end
|
||||
|
||||
# Escape a string for use in an URL path or query parameter. Like `CGI.escape`, but leaves Unicode characters as Unicode.
|
||||
#
|
||||
# @example
|
||||
# Danbooru::URL.escape("fate/stay_night") # => "fate%2Fstay_night"
|
||||
# Danbooru::URL.escape("大丈夫?おっぱい揉む?") # => "大丈夫%3Fおっぱい揉む%3F"
|
||||
#
|
||||
# @return [String] The escaped string
|
||||
def self.escape(string)
|
||||
Addressable::URI.encode_component(string, /[\/?#&+%]/).force_encoding("UTF-8")
|
||||
end
|
||||
|
||||
# @return [String] the URL in unnormalized form
|
||||
def to_s
|
||||
original_url
|
||||
|
||||
@@ -48,7 +48,7 @@ class Source::Extractor
|
||||
|
||||
def tags
|
||||
api_response[:tags].to_a.map do |tag|
|
||||
[tag, "https://www.artstation.com/search?q=#{CGI.escape(tag)}"]
|
||||
[tag, "https://www.artstation.com/search?q=#{Danbooru::URL.escape(tag)}"]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ module Source
|
||||
|
||||
tags = api_response[:tags].split + ["rating:#{api_response[:rating]}"]
|
||||
tags.map do |tag|
|
||||
[tag, "https://#{domain}/index.php?page=post&s=list&tags=#{CGI.escape(tag)}"]
|
||||
[tag, "https://#{domain}/index.php?page=post&s=list&tags=#{Danbooru::URL.escape(tag)}"]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ module Source
|
||||
tags = page&.search(".boxbody [rel='tag']").to_a.map(&:text)
|
||||
|
||||
tags.map do |tag|
|
||||
[tag, "https://www.hentai-foundry.com/pictures/tagged/#{CGI.escape(tag)}"]
|
||||
[tag, "https://www.hentai-foundry.com/pictures/tagged/#{Danbooru::URL.escape(tag)}"]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ module Source
|
||||
|
||||
def tags
|
||||
api_response[:tags].to_s.split.map do |tag|
|
||||
[tag, "https://#{domain}/post?tags=#{CGI.escape(tag)}"]
|
||||
[tag, "https://#{domain}/post?tags=#{Danbooru::URL.escape(tag)}"]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -77,12 +77,8 @@ module Source
|
||||
def tags
|
||||
return [] if api_client.blank?
|
||||
|
||||
base_url = "https://seiga.nicovideo.jp/"
|
||||
base_url += "manga/" if manga_id.present?
|
||||
base_url += "tag/"
|
||||
|
||||
api_client.tags.map do |name|
|
||||
[name, base_url + CGI.escape(name)]
|
||||
[name, "https://seiga.nicovideo.jp/#{"manga/" if manga_id}tag/#{Danbooru::URL.escape(name)}"]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ module Source
|
||||
|
||||
def tags
|
||||
tags = api_illust.dig(:tags, :tags).to_a.map do |item|
|
||||
[item[:tag], "https://www.pixiv.net/tags/#{CGI.escape(item[:tag])}/artworks"]
|
||||
[item[:tag], "https://www.pixiv.net/tags/#{Danbooru::URL.escape(item[:tag])}/artworks"]
|
||||
end
|
||||
|
||||
if api_illust["aiType"] == 2
|
||||
|
||||
@@ -28,7 +28,7 @@ module Source
|
||||
|
||||
def tags
|
||||
page&.css("meta[name='keywords']")&.attr("content")&.value.to_s.split(/, /).compact.map do |tag|
|
||||
[tag.tr(" ", "_"), "https://rule34.us/index.php?r=posts/index&q=#{CGI.escape(tag)}"]
|
||||
[tag.tr(" ", "_"), "https://rule34.us/index.php?r=posts/index&q=#{Danbooru::URL.escape(tag)}"]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ module Source
|
||||
|
||||
def tags
|
||||
page&.css("#view .tag a[href^='/search/list']").to_a.map do |tag|
|
||||
[tag.text, "https://www.tinami.com/search/list?keyword=#{CGI.escape(tag.text)}"]
|
||||
[tag.text, "https://www.tinami.com/search/list?keyword=#{Danbooru::URL.escape(tag.text)}"]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ class Source::Extractor
|
||||
|
||||
def tags
|
||||
post[:tags].to_a.map do |tag|
|
||||
[tag, "https://tumblr.com/tagged/#{CGI.escape(tag)}"]
|
||||
[tag, "https://tumblr.com/tagged/#{Danbooru::URL.escape(tag)}"]
|
||||
end.uniq
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user