diff --git a/app/finders/users/oembed_api.rb b/app/finders/users/oembed_api.rb index f97813a6d..d34c96977 100644 --- a/app/finders/users/oembed_api.rb +++ b/app/finders/users/oembed_api.rb @@ -36,6 +36,8 @@ def user_details_from_oembed_data(oembed_data) oembed_data = oembed_data.first if oembed_data.is_a?(Array) + oembed_data = {} unless oembed_data.is_a?(Hash) + if oembed_data['author_url'] =~ %r{/author/([^/]+)/?\z} details = [Regexp.last_match[1], 'Author URL', 90] elsif oembed_data['author_name'] && !oembed_data['author_name'].empty? diff --git a/app/finders/users/wp_json_api.rb b/app/finders/users/wp_json_api.rb index 73b23f368..8d9f9a1e9 100644 --- a/app/finders/users/wp_json_api.rb +++ b/app/finders/users/wp_json_api.rb @@ -42,12 +42,16 @@ def aggressive(_opts = {}) def users_from_response(response) found = [] - JSON.parse(response.body)&.each do |user| - found << Model::User.new(user['slug'], - id: user['id'], - found_by: found_by, - confidence: 100, - interesting_entries: [response.effective_url]) + json = JSON.parse(response.body) + + if json.is_a?(Enumerable) + json.each do |user| + found << Model::User.new(user['slug'], + id: user['id'], + found_by: found_by, + confidence: 100, + interesting_entries: [response.effective_url]) + end end found diff --git a/spec/app/finders/users/oembed_api_spec.rb b/spec/app/finders/users/oembed_api_spec.rb index 01d053575..c4a2dea5a 100644 --- a/spec/app/finders/users/oembed_api_spec.rb +++ b/spec/app/finders/users/oembed_api_spec.rb @@ -13,9 +13,17 @@ end context 'when not a JSON response' do - let(:body) { '' } + context 'when empty' do + let(:body) { '' } - its(:aggressive) { should eql([]) } + its(:aggressive) { should eql([]) } + end + + context 'when a string' do + let(:body) { '404' } + + its(:aggressive) { should eql([]) } + end end context 'when a JSON response' do diff --git a/spec/app/finders/users/wp_json_api_spec.rb b/spec/app/finders/users/wp_json_api_spec.rb index a9af123ec..7f38a818f 100644 --- a/spec/app/finders/users/wp_json_api_spec.rb +++ b/spec/app/finders/users/wp_json_api_spec.rb @@ -20,9 +20,17 @@ end context 'when not a JSON response' do - let(:body) { '' } + context 'when empty' do + let(:body) { '' } - its(:aggressive) { should eql([]) } + its(:aggressive) { should eql([]) } + end + + context 'when a string' do + let(:body) { '404' } + + its(:aggressive) { should eql([]) } + end end context 'when a JSON response' do