From 183a7e07e308401f74d9948b8f8c2b6dc6624e02 Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 21 Nov 2017 10:13:49 -0600 Subject: [PATCH] pixiv: fix failbooru when uploading bad pixiv id posts. Fixes an "incompatible character encodings: UTF-8 and ASCII-8BIT" exception when uploading a deleted Pixiv post. Caused by the Pixiv API error message not having the encoding set to UTF-8. --- app/logical/pixiv_api_client.rb | 11 +++++++---- app/views/static/error.html.erb | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/logical/pixiv_api_client.rb b/app/logical/pixiv_api_client.rb index b23962820..59830d78d 100644 --- a/app/logical/pixiv_api_client.rb +++ b/app/logical/pixiv_api_client.rb @@ -141,12 +141,13 @@ class PixivApiClient url = "https://public-api.secure.pixiv.net/v#{API_VERSION}/works/#{illust_id.to_i}.json" resp = HTTParty.get(url, Danbooru.config.httparty_options.deep_merge(query: params, headers: headers)) + body = resp.body.force_encoding("utf-8") if resp.success? - json = parse_api_json(resp.body) + json = parse_api_json(body) WorksResponse.new(json["response"][0]) else - raise Error.new("Pixiv API call failed (status=#{resp.code} body=#{resp.body})") + raise Error.new("Pixiv API call failed (status=#{resp.code} body=#{body})") end end @@ -177,11 +178,13 @@ private url = "https://oauth.secure.pixiv.net/auth/token" resp = HTTParty.post(url, Danbooru.config.httparty_options.deep_merge(body: params, headers: headers)) + body = resp.body.force_encoding("utf-8") + if resp.success? - json = JSON.parse(resp.body) + json = JSON.parse(body) access_token = json["response"]["access_token"] else - raise Error.new("Pixiv API access token call failed (status=#{resp.code} body=#{resp.body})") + raise Error.new("Pixiv API access token call failed (status=#{resp.code} body=#{body})") end access_token diff --git a/app/views/static/error.html.erb b/app/views/static/error.html.erb index e0daa2bbd..6d09563e7 100644 --- a/app/views/static/error.html.erb +++ b/app/views/static/error.html.erb @@ -1,7 +1,7 @@ <% if CurrentUser.user.is_builder? && @exception.present? %>

<%= @exception.class.to_s %> exception raised