Skip to content
This repository has been archived by the owner on Jan 27, 2020. It is now read-only.

Commit

Permalink
Merge pull request mastodon#1297 from pixiv/bugfix/fix_empty_body
Browse files Browse the repository at this point in the history
Fix undefined method error in sidekiq (mastodon#9807)
  • Loading branch information
abcang authored Sep 27, 2019
2 parents 66ee775 + 9dd45be commit 768aa3c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/services/fetch_oembed_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def fetch!
res.code != 200 ? nil : res.body_with_limit
end

validate(parse_for_format(body)) unless body.nil?
validate(parse_for_format(body)) if body.present?
rescue Oj::ParseError, Ox::ParseError
nil
end
Expand Down
7 changes: 7 additions & 0 deletions spec/fixtures/requests/oembed_json_empty.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<link href='https://host.test/empty_provider.json' rel='alternate' type='application/json+oembed'>
</head>
<body></body>
</html>
18 changes: 18 additions & 0 deletions spec/services/fetch_oembed_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
before do
stub_request(:get, "https://host.test/provider.json").to_return(status: 404)
stub_request(:get, "https://host.test/provider.xml").to_return(status: 404)
stub_request(:get, "https://host.test/empty_provider.json").to_return(status: 200)
end

describe 'discover_provider' do
Expand Down Expand Up @@ -93,6 +94,23 @@
expect(subject.call('https://host.test/oembed.html')).to be_nil
end
end

context 'Empty JSON provider is discoverable' do
before do
stub_request(:get, 'https://host.test/oembed.html').to_return(
status: 200,
headers: { 'Content-Type': 'text/html' },
body: request_fixture('oembed_json_empty.html')
)
end

it 'returns new OEmbed::Provider for JSON provider' do
subject.call('https://host.test/oembed.html')
expect(subject.endpoint_url).to eq 'https://host.test/empty_provider.json'
expect(subject.format).to eq :json
end
end

end

context 'when status code is not 200' do
Expand Down

0 comments on commit 768aa3c

Please sign in to comment.