Fix handling of rdf:langString in media summary and name (#39590)

This commit is contained in:
Claire authored and GitHub committed 2026-07-01 12:21:17 +00:00
1 parent 15c6f9a277
commit 68627adff4
3 files changed
+18 -2

No files matched your search

+16
View File
@@ -17,6 +17,22 @@ module JsonLdHelper
value.is_a?(Array) ? value.first : value
end
# Some attributes we read can be either `xsd:string` or `rdf:langString`
# and will lead to different compacted forms depending on which they are.
# Furthermore, we don't unconditionally compact to our context, so we
# may also find non-compacted forms.
# This is the case of `summary`, `name` and `content` as defined in ActivityStreams.
def first_lang_string(json, name)
if json[name]
value = first_of_value(json[name])
return value if value.is_a?(String)
value['@value'] if value.is_a?(Hash)
elsif json["#{name}Map"]
json["#{name}Map"].values.first
end
end
def uri_from_bearcap(str)
if str&.start_with?('bear:')
Addressable::URI.parse(str).query_values['u']
@@ -29,7 +29,7 @@ class ActivityPub::Parser::MediaAttachmentParser
end
def description
str = @json['summary'].presence || @json['name'].presence
str = first_lang_string(@json, 'summary').presence || first_lang_string(@json, 'name').presence
str = str.strip[0...MediaAttachment::MAX_DESCRIPTION_HARD_LENGTH_LIMIT] if str.present?
str
end
@@ -256,7 +256,7 @@ class ActivityPub::ProcessAccountService < BaseService
if value.is_a?(Hash) && value['type'] == 'Image'
url = first_of_value(value['url'])
url = url['href'] if url.is_a?(Hash)
description = value['summary'].presence || value['name'].presence
description = first_lang_string(value, 'summary').presence || first_lang_string(value, 'name').presence
description = description.strip[0...MediaAttachment::MAX_DESCRIPTION_HARD_LENGTH_LIMIT] if description.present?
else
url = value