diff options
author | Claire <claire.github-309c@sitedethib.com> | 2023-07-07 13:35:22 +0200 |
---|---|---|
committer | Claire <claire.github-309c@sitedethib.com> | 2023-07-07 19:35:24 +0200 |
commit | 517c4a8a7a96bd2f16e369fa794575c30be370c8 (patch) | |
tree | dcfe928ad4c2ff23770efc1da790f9e00ec6fc23 | |
parent | dca0d8427e42e9a498b2c88b85660fef19d8fd1a (diff) |
Fix processing of media files with unusual names (#25788)
-rw-r--r-- | app/models/concerns/attachmentable.rb | 2 | ||||
-rw-r--r-- | spec/fixtures/files/attachment-jpg.123456_abcd | bin | 0 -> 61022 bytes | |||
-rw-r--r-- | spec/requests/api/v2/media_spec.rb | 18 |
3 files changed, 19 insertions, 1 deletions
diff --git a/app/models/concerns/attachmentable.rb b/app/models/concerns/attachmentable.rb index 35819003e7d..662b2ef529b 100644 --- a/app/models/concerns/attachmentable.rb +++ b/app/models/concerns/attachmentable.rb @@ -24,7 +24,7 @@ module Attachmentable def self.has_attached_file(name, options = {}) # rubocop:disable Naming/PredicateName super(name, options) - send(:"before_#{name}_validate") do + send(:"before_#{name}_validate", prepend: true) do attachment = send(name) check_image_dimension(attachment) set_file_content_type(attachment) diff --git a/spec/fixtures/files/attachment-jpg.123456_abcd b/spec/fixtures/files/attachment-jpg.123456_abcd Binary files differnew file mode 100644 index 00000000000..f1d40539ac0 --- /dev/null +++ b/spec/fixtures/files/attachment-jpg.123456_abcd diff --git a/spec/requests/api/v2/media_spec.rb b/spec/requests/api/v2/media_spec.rb new file mode 100644 index 00000000000..89384d0ca36 --- /dev/null +++ b/spec/requests/api/v2/media_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Media API', paperclip_processing: true do + let(:user) { Fabricate(:user) } + let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) } + let(:scopes) { 'write' } + let(:headers) { { 'Authorization' => "Bearer #{token.token}" } } + + describe 'POST /api/v2/media' do + it 'returns http success' do + post '/api/v2/media', headers: headers, params: { file: fixture_file_upload('attachment-jpg.123456_abcd', 'image/jpeg') } + expect(File.exist?(user.account.media_attachments.first.file.path(:small))).to be true + expect(response).to have_http_status(200) + end + end +end |