From 35d52b4642b0aafd1104e495dafb52eba03da4ee Mon Sep 17 00:00:00 2001 From: Julie Allinson Date: Thu, 12 Dec 2019 11:20:36 +0000 Subject: [PATCH] support non-ascii characters in filenames --- app/actors/hyrax/actors/file_set_actor.rb | 4 ++-- spec/actors/hyrax/actors/file_set_actor_spec.rb | 16 ++++++++++++++++ "spec/fixtures/\344\270\226\347\225\214.png" | Bin 0 -> 4218 bytes 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 "spec/fixtures/\344\270\226\347\225\214.png" diff --git a/app/actors/hyrax/actors/file_set_actor.rb b/app/actors/hyrax/actors/file_set_actor.rb index 908c4c1fb7..bee7d9cf53 100644 --- a/app/actors/hyrax/actors/file_set_actor.rb +++ b/app/actors/hyrax/actors/file_set_actor.rb @@ -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 diff --git a/spec/actors/hyrax/actors/file_set_actor_spec.rb b/spec/actors/hyrax/actors/file_set_actor_spec.rb index 87dca7d78c..af41d52ce9 100644 --- a/spec/actors/hyrax/actors/file_set_actor_spec.rb +++ b/spec/actors/hyrax/actors/file_set_actor_spec.rb @@ -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 diff --git "a/spec/fixtures/\344\270\226\347\225\214.png" "b/spec/fixtures/\344\270\226\347\225\214.png" new file mode 100644 index 0000000000000000000000000000000000000000..efbe348def1bec831e4e848f9bebf0c4ae25fe00 GIT binary patch literal 4218 zcmV-=5QXoFP)i_@{97#k$RA_!f*{Z*<&gj( ziBmy>n>dd1aBQ#RwY~N}z3-jbdF{OKJ*R)n%*G7NK03USf4?Vo9_o*lcX_$r4FtGD9&emXipZ@eCzdn#d-#2=5BVTd3t&jfUgSUEj^tLiQd68u10ukSDEa^t?{M zbqXm3jg3D1eh(gxg>5^W8U6#J=>sTL262?aaTH1^T0U0mv#i>5vh?7!oO ziHpx=-V%^qhYq{6^gXk+xBZrfKlBdo@az(?)kj#SpCxPcbmI zjXU@E8tH7wKR=Ur@5a5iersXysPm>ldLQ`WC&G;lAOHA=Z}*=ai4h5Wn@y23T$nn< zLUJFQng(!`4~-W?N~Dk|u?Zo(q>B$?7zTzREA9*Y=HuA9nU>Hwws-u1Y(C7;)cc4u zoTtGvL2GaTzk3?=9OuTiaOc5ZV|+T%7>yM=;zK|G>6-%Se&BC5o5FhRV;{P`VP-Lp z*ZL0Kt*`LH`OlHgb>np}adZFIh%`)4w8IoiEf`V&5sKuPAs*JlI_KIEH*VAgNmAItqFLh$QAR9&Ti)R1Dmar=O+5RUGI1$dHK1~UmB#j z@4hGQ{Ow&^I@%&)F8Vb69Y>H-&>lHQuGGSguBQliWB5Et+*XcgYByjZr9eu75M|S7 zw9*uu8$hSARRcb6iO$xa<2VMr8=eLnwAK{^r8FVm2$RufG#lyJ)a<@EI&)W3?*m_3 zynJNc6k8Xh_x>-wt0Cb3(+}OZ-}~x?H@I=jH!%%`lmfSvXG7=$jlOxnMKZgUT(ON( zF-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