diff --git a/app/site_files.rb b/app/site_files.rb index 48152b7c..6722388f 100644 --- a/app/site_files.rb +++ b/app/site_files.rb @@ -130,7 +130,8 @@ post '/site_files/upload' do end end - file[:filename] = "#{dir_name}/#{site.scrubbed_path file[:filename]}" + file[:filename] = "#{dir_name.force_encoding('UTF-8')}/#{site.scrubbed_path file[:filename].force_encoding('UTF-8')}" + if current_site.file_size_too_large? file[:tempfile].size file_upload_response "#{Rack::Utils.escape_html file[:filename]} is too large, upload cancelled." end diff --git a/tests/api_tests.rb b/tests/api_tests.rb index 190806b3..68c326f8 100644 --- a/tests/api_tests.rb +++ b/tests/api_tests.rb @@ -423,6 +423,14 @@ describe 'api' do _(site_file_exists?('test.jpg')).must_equal true end + it 'works with unicode chars on filename and dir' do + create_site + basic_authorize @user, @pass + post '/api/upload', '詩經/詩經.jpg' => Rack::Test::UploadedFile.new('./tests/files/詩經.jpg', 'image/jpeg') + _(res[:result]).must_equal 'success' + _(site_file_exists?('詩經/詩經.jpg')).must_equal true + end + it 'succeeds with two files' do create_site basic_authorize @user, @pass diff --git a/tests/files/詩經.jpg b/tests/files/詩經.jpg new file mode 100644 index 00000000..fabe9bc7 Binary files /dev/null and b/tests/files/詩經.jpg differ diff --git a/tests/site_file_tests.rb b/tests/site_file_tests.rb index c82995df..120989ad 100644 --- a/tests/site_file_tests.rb +++ b/tests/site_file_tests.rb @@ -443,6 +443,14 @@ describe 'site_files' do end end + it 'works with unicode chars on filename and dir' do + upload( + 'dir' => '詩經', + 'files[]' => Rack::Test::UploadedFile.new('./tests/files/詩經.jpg', 'image/jpeg') + ) + _(@site.site_files_dataset.where(path: '詩經/詩經.jpg').count).must_equal 1 + end + it 'does not register site changing until root index.html is changed' do upload( 'dir' => 'derpie/derptest',