Skip to content

Commit 38e3794

Browse files
committed
Fix parsing response if Content-Type contains charset
1 parent 256e1f3 commit 38e3794

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

app/adapters/abstract_adapter.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ def self.parse_response(response)
9494

9595
content_type = response.content_type.presence or return body
9696

97-
case Mime::Type.lookup(content_type)
98-
when JSON_TYPE then JSON.parse(body)
99-
else raise InvalidResponseError.new response: response, message: 'Unknown Content-Type'
97+
if Mime::Type.lookup(content_type).match? JSON_TYPE
98+
JSON.parse(body)
99+
else
100+
raise InvalidResponseError.new response: response, message: 'Unknown Content-Type'
100101
end
101102
end
102103

test/adapters/abstract_adapter_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,15 @@ class AbstractAdapterTest < ActiveSupport::TestCase
3838
assert_nil subject.new('https://example.com').authentication
3939
end
4040
end
41+
42+
test 'content-type with charset' do
43+
content_type = 'application/json;charset=UTF-8'
44+
stub_request(:get, 'https://example.com/.well-known/openid-configuration').
45+
to_return(body: '{}', headers: {'Content-Type': content_type})
46+
stub_request(:post, 'https://example.com').to_return(status: 200, body: '{"access_token": "test"}', headers: {'Content-Type': content_type})
47+
48+
assert_nothing_raised do
49+
subject.new('https://example.com').authentication
50+
end
51+
end
4152
end

0 commit comments

Comments
 (0)