Skip to content

Commit

Permalink
backport support for non-ascii characters in filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
Julie Allinson authored and Tom Johnson committed Jan 2, 2020
1 parent 26895fb commit 4ae0d3f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
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 @@ -129,12 +129,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 @@ -12,6 +12,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.

0 comments on commit 4ae0d3f

Please sign in to comment.