From 1f951228293d240ad31f73e08b8f1ed6b8d3d67b Mon Sep 17 00:00:00 2001 From: Karel Picman Date: Tue, 27 Mar 2018 13:02:16 +0200 Subject: [PATCH] Hardcoded file path separators --- app/controllers/dmsf_controller.rb | 6 +++--- lib/dmsf_zip.rb | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb index eb58706d..e039712d 100644 --- a/app/controllers/dmsf_controller.rb +++ b/app/controllers/dmsf_controller.rb @@ -157,7 +157,7 @@ class DmsfController < ApplicationController render_404 #and return rescue DmsfAccessError render_403 # and return - rescue Exception => e + rescue StandardError => e flash[:error] = e.message Rails.logger.error e.message end @@ -423,7 +423,7 @@ class DmsfController < ApplicationController :filename => filename_for_content_disposition("#{@project.name}-#{DateTime.now.strftime('%y%m%d%H%M%S')}.zip"), :type => 'application/zip', :disposition => 'attachment') - rescue Exception + rescue StandardError raise ensure zip.close if zip @@ -447,7 +447,7 @@ class DmsfController < ApplicationController unless (file.project == @project) || User.current.allowed_to?(:view_dmsf_files, file.project) raise DmsfAccessError end - zip.add_file(file, member, (file.dmsf_folder.dmsf_path_str if file.dmsf_folder)) if file + zip.add_file(file, member, (file.dmsf_folder.dmsf_path_str if file.dmsf_folder)) end max_files = Setting.plugin_redmine_dmsf['dmsf_max_file_download'].to_i if max_files > 0 && zip.files.length > max_files diff --git a/lib/dmsf_zip.rb b/lib/dmsf_zip.rb index 0dd1e6d2..73d1a967 100644 --- a/lib/dmsf_zip.rb +++ b/lib/dmsf_zip.rb @@ -43,7 +43,10 @@ class DmsfZip def add_file(file, member, root_path = nil) unless @files.include?(file) - string_path = file.dmsf_folder.nil? ? '' : "#{file.dmsf_folder.dmsf_path_str}/" + unless file && file.last_revision && File.exist?(file.last_revision.disk_file) + raise FileNotFound + end + string_path = file.dmsf_folder.nil? ? '' : (file.dmsf_folder.dmsf_path_str + File::SEPARATOR) string_path = string_path[(root_path.length + 1) .. string_path.length] if root_path if member && !member.dmsf_title_format.nil? && !member.dmsf_title_format.empty? string_path += file.formatted_name(member.dmsf_title_format) @@ -64,7 +67,7 @@ class DmsfZip def add_folder(folder, member, root_path = nil) unless @folders.include?(folder) - string_path = "#{folder.dmsf_path_str}/" + string_path = folder.dmsf_path_str + File::SEPARATOR string_path = string_path[(root_path.length + 1) .. string_path.length] if root_path zip_entry = ::Zip::Entry.new(@zip_file, string_path, nil, nil, nil, nil, nil, nil, ::Zip::DOSTime.at(folder.modified))