Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force encoding of IndexedFile original_name to UTF-8 #5046

Merged
merged 1 commit into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/models/indexed_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@

class IndexedFile < ActiveFedora::File
include SpeedyAF::IndexedContent

# Override
def original_name
super.force_encoding("UTF-8")
end
end
13 changes: 13 additions & 0 deletions spec/controllers/admin_collections_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,19 @@
end
end

context 'with a UTF8 filename' do
it 'adds the poster and displays as UTF8' do
file = fixture_file_upload('/きた!.png', 'image/png')
expect { post :attach_poster, params: { id: collection.id, admin_collection: { poster: file } } }.to change { collection.reload.poster.present? }.from(false).to(true)
expect(collection.poster.mime_type).to eq 'image/png'
expect(collection.poster.original_name).to eq 'きた!.png'
expect(collection.poster.original_name.encoding.name).to eq 'UTF-8'
expect(collection.poster.content).not_to be_blank
expect(response).to redirect_to(admin_collection_path(collection))
expect(flash[:success]).not_to be_empty
end
end

context 'when saving fails' do
before do
allow_any_instance_of(Admin::Collection).to receive(:save).and_return(false)
Expand Down
Binary file added spec/fixtures/きた!.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.