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

Decode filenames for fileset label #4172

Merged
1 commit merged into from
Jan 2, 2020
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
4 changes: 2 additions & 2 deletions app/actors/hyrax/actors/file_set_actor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ def wrapper!(file:, relation:)
# @note This is only useful for labeling the file_set, because of the recourse to import_url
def label_for(file)
if file.is_a?(Hyrax::UploadedFile) # filename not present for uncached remote file!
file.uploader.filename.present? ? file.uploader.filename : File.basename(Addressable::URI.parse(file.file_url).path)
file.uploader.filename.present? ? file.uploader.filename : File.basename(Addressable::URI.unencode(file.file_url))
elsif file.respond_to?(:original_name) # e.g. Hydra::Derivatives::IoDecorator
file.original_name
elsif file_set.import_url.present?
# This path is taken when file is a Tempfile (e.g. from ImportUrlJob)
File.basename(Addressable::URI.parse(file_set.import_url).path)
File.basename(Addressable::URI.unencode(file.file_url))
else
File.basename(file)
end
Expand Down
16 changes: 16 additions & 0 deletions spec/actors/hyrax/actors/file_set_actor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@
let(:relation) { :original_file }
let(:file_actor) { Hyrax::Actors::FileActor.new(file_set, relation, user) }

describe 'non ascii characters in filenames' do
let(:file_path) { File.join(fixture_path, '世界.png') }
let(:file) { fixture_file_upload(file_path, 'image/png') }
let(:local_file) { File.open(file_path) }
let(:file_set) { build(:file_set) }

before do
actor.create_content(file)
actor.file_set.reload
end

it 'retains the filename with the japanese characters' do
expect(file_set.label).to start_with('世界')
end
end

describe 'private' do
let(:file_set) { build(:file_set) } # avoid 130+ LDP requests

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.