Fix remote statuses with large media descriptions being rejected (#39135)
This commit is contained in:
@@ -205,7 +205,7 @@ class MediaAttachment < ApplicationRecord
|
|||||||
remotable_attachment :thumbnail, IMAGE_LIMIT, suppress_errors: true, download_on_assign: false
|
remotable_attachment :thumbnail, IMAGE_LIMIT, suppress_errors: true, download_on_assign: false
|
||||||
|
|
||||||
validates :account, presence: true
|
validates :account, presence: true
|
||||||
validates :description, length: { maximum: MAX_DESCRIPTION_LENGTH }
|
validates :description, length: { maximum: MAX_DESCRIPTION_LENGTH }, if: :local?
|
||||||
validates :file, presence: true, if: :local?
|
validates :file, presence: true, if: :local?
|
||||||
validates :thumbnail, absence: true, if: -> { local? && !audio_or_video? }
|
validates :thumbnail, absence: true, if: -> { local? && !audio_or_video? }
|
||||||
|
|
||||||
|
|||||||
@@ -608,19 +608,19 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||||||
type: 'Document',
|
type: 'Document',
|
||||||
mediaType: 'image/png',
|
mediaType: 'image/png',
|
||||||
url: 'http://example.com/attachment.png',
|
url: 'http://example.com/attachment.png',
|
||||||
name: '*' * MediaAttachment::MAX_DESCRIPTION_LENGTH,
|
name: '*' * (MediaAttachment::MAX_DESCRIPTION_HARD_LENGTH_LIMIT + 5),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates status' do
|
it 'creates status with truncated description' do
|
||||||
expect { subject.perform }.to change(sender.statuses, :count).by(1)
|
expect { subject.perform }.to change(sender.statuses, :count).by(1)
|
||||||
|
|
||||||
status = sender.statuses.first
|
status = sender.statuses.first
|
||||||
|
|
||||||
expect(status).to_not be_nil
|
expect(status).to_not be_nil
|
||||||
expect(status.media_attachments.map(&:description)).to include('*' * MediaAttachment::MAX_DESCRIPTION_LENGTH)
|
expect(status.media_attachments.map(&:description)).to include('*' * MediaAttachment::MAX_DESCRIPTION_HARD_LENGTH_LIMIT)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -632,19 +632,19 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||||||
type: 'Document',
|
type: 'Document',
|
||||||
mediaType: 'image/png',
|
mediaType: 'image/png',
|
||||||
url: 'http://example.com/attachment.png',
|
url: 'http://example.com/attachment.png',
|
||||||
summary: '*' * MediaAttachment::MAX_DESCRIPTION_LENGTH,
|
summary: '*' * (MediaAttachment::MAX_DESCRIPTION_HARD_LENGTH_LIMIT + 5),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates status' do
|
it 'creates status with truncated description' do
|
||||||
expect { subject.perform }.to change(sender.statuses, :count).by(1)
|
expect { subject.perform }.to change(sender.statuses, :count).by(1)
|
||||||
|
|
||||||
status = sender.statuses.first
|
status = sender.statuses.first
|
||||||
|
|
||||||
expect(status).to_not be_nil
|
expect(status).to_not be_nil
|
||||||
expect(status.media_attachments.map(&:description)).to include('*' * MediaAttachment::MAX_DESCRIPTION_LENGTH)
|
expect(status.media_attachments.map(&:description)).to include('*' * MediaAttachment::MAX_DESCRIPTION_HARD_LENGTH_LIMIT)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user