Merge commit from fork
This commit is contained in:
parent
ec2a99341c
commit
0786c1e57a
@ -3,6 +3,8 @@
|
|||||||
module JsonLdHelper
|
module JsonLdHelper
|
||||||
include ContextHelper
|
include ContextHelper
|
||||||
|
|
||||||
|
UNSUPPORTED_JSONLD_KEYWORDS = %w(@graph @included @reverse).freeze
|
||||||
|
|
||||||
def equals_or_includes?(haystack, needle)
|
def equals_or_includes?(haystack, needle)
|
||||||
haystack.is_a?(Array) ? haystack.include?(needle) : haystack == needle
|
haystack.is_a?(Array) ? haystack.include?(needle) : haystack == needle
|
||||||
end
|
end
|
||||||
@ -110,6 +112,16 @@ module JsonLdHelper
|
|||||||
compacted
|
compacted
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def unsupported_jsonld_features?(json)
|
||||||
|
if json.is_a?(Hash)
|
||||||
|
json.any? { |key, value| UNSUPPORTED_JSONLD_KEYWORDS.include?(key) || unsupported_jsonld_features?(value) }
|
||||||
|
elsif json.is_a?(Array)
|
||||||
|
json.any? { |value| unsupported_jsonld_features?(value) }
|
||||||
|
else
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Patches a JSON-LD document to avoid compatibility issues on redistribution
|
# Patches a JSON-LD document to avoid compatibility issues on redistribution
|
||||||
#
|
#
|
||||||
# Since compacting a JSON-LD document against Mastodon's built-in vocabulary
|
# Since compacting a JSON-LD document against Mastodon's built-in vocabulary
|
||||||
|
|||||||
@ -12,6 +12,7 @@ class ActivityPub::LinkedDataSignature
|
|||||||
|
|
||||||
def verify_actor!
|
def verify_actor!
|
||||||
return unless @json['signature'].is_a?(Hash)
|
return unless @json['signature'].is_a?(Hash)
|
||||||
|
return if unsupported_jsonld_features?(@json)
|
||||||
|
|
||||||
type = @json['signature']['type']
|
type = @json['signature']['type']
|
||||||
creator_uri = @json['signature']['creator']
|
creator_uri = @json['signature']['creator']
|
||||||
|
|||||||
@ -13,6 +13,10 @@ class ActivityPub::ProcessCollectionService < BaseService
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
@json = compact(@json) if @json['signature'].is_a?(Hash)
|
@json = compact(@json) if @json['signature'].is_a?(Hash)
|
||||||
|
if unsupported_jsonld_features?(@json)
|
||||||
|
Rails.logger.debug { "JSON-LD document for #{value_or_id(@json['actor'])} contains unsupported JSON-LD features" }
|
||||||
|
@json = original_json.without('signature')
|
||||||
|
end
|
||||||
rescue JSON::LD::JsonLdError => e
|
rescue JSON::LD::JsonLdError => e
|
||||||
Rails.logger.debug { "Error when compacting JSON-LD document for #{value_or_id(@json['actor'])}: #{e.message}" }
|
Rails.logger.debug { "Error when compacting JSON-LD document for #{value_or_id(@json['actor'])}: #{e.message}" }
|
||||||
@json = original_json.without('signature')
|
@json = original_json.without('signature')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user