Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Ignore JSON-LD profile in mime type comparison (mastodon#9179)
Browse files Browse the repository at this point in the history
Ignore JSON-LD profile in mime type comparison
  • Loading branch information
valerauko authored and Gargron committed Nov 22, 2018
1 parent 473998c commit 824497f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/services/fetch_atom_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def process(url, terminal = false)

def perform_request(&block)
accept = 'text/html'
accept = 'application/activity+json, application/ld+json, application/atom+xml, ' + accept unless @unsupported_activity
accept = 'application/activity+json, application/ld+json; profile="https://www.w3.org/ns/activitystreams", application/atom+xml, ' + accept unless @unsupported_activity

Request.new(:get, @url).add_headers('Accept' => accept).perform(&block)
end
Expand All @@ -39,7 +39,7 @@ def process_response(response, terminal = false)

if response.mime_type == 'application/atom+xml'
[@url, { prefetched_body: response.body_with_limit }, :ostatus]
elsif ['application/activity+json', 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'].include?(response.mime_type)
elsif ['application/activity+json', 'application/ld+json'].include?(response.mime_type)
body = response.body_with_limit
json = body_to_json(body)
if supported_context?(json) && equals_or_includes_any?(json['type'], ActivityPub::FetchRemoteAccountService::SUPPORTED_TYPES) && json['inbox'].present?
Expand Down
11 changes: 9 additions & 2 deletions spec/services/fetch_atom_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,15 @@
it { is_expected.to eq [url, { :prefetched_body => "" }, :ostatus] }
end

context 'content_type is json' do
let(:content_type) { 'application/activity+json' }
context 'content_type is activity+json' do
let(:content_type) { 'application/activity+json; charset=utf-8' }
let(:body) { json }

it { is_expected.to eq [1, { prefetched_body: body, id: true }, :activitypub] }
end

context 'content_type is ld+json with profile' do
let(:content_type) { 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' }
let(:body) { json }

it { is_expected.to eq [1, { prefetched_body: body, id: true }, :activitypub] }
Expand Down

0 comments on commit 824497f

Please sign in to comment.