diff --git a/app/controllers/dmsf_state_controller.rb b/app/controllers/dmsf_state_controller.rb index e3551e56..4f2efecd 100644 --- a/app/controllers/dmsf_state_controller.rb +++ b/app/controllers/dmsf_state_controller.rb @@ -49,7 +49,7 @@ class DmsfStateController < ApplicationController private def format_valid?(format) - format.blank? || ((format =~ /%(t|d|v|i|r)/) && format.length < 256) + format.blank? || ((/%(t|d|v|i|r)/.match?(format)) && format.length < 256) end end \ No newline at end of file diff --git a/app/helpers/dmsf_helper.rb b/app/helpers/dmsf_helper.rb index 0f7ec4e3..a3af0d0c 100644 --- a/app/helpers/dmsf_helper.rb +++ b/app/helpers/dmsf_helper.rb @@ -48,11 +48,13 @@ module DmsfHelper # get only the filename, not the whole path just_filename = File.basename(filename.gsub('\\\\', '/')) # replace all non alphanumeric, hyphens or periods with underscore - just_filename = just_filename.gsub(/[^\w\.\-]/,'_') - unless just_filename =~ %r{^[a-zA-Z0-9_\.\-]*$} + just_filename.gsub!(/[^\w\.\-]/, '_') + unless %r{^[a-zA-Z0-9_\.\-]*$}.match?(just_filename) # keep the extension if any - extension = $1 if just_filename =~ %r{(\.[a-zA-Z0-9]+)$} - just_filename = Digest::SHA256.hexdigest(just_filename) << extension + if just_filename =~ %r{(\.[a-zA-Z0-9]+)$} + extension = $1 + just_filename = Digest::SHA256.hexdigest(just_filename) << extension + end end just_filename end diff --git a/app/validators/dmsf_file_name_validator.rb b/app/validators/dmsf_file_name_validator.rb index 5996dbc7..7e9b0411 100644 --- a/app/validators/dmsf_file_name_validator.rb +++ b/app/validators/dmsf_file_name_validator.rb @@ -22,7 +22,7 @@ class DmsfFileNameValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) - unless value =~ /\A[^#{DmsfFolder::INVALID_CHARACTERS}]*\z/ + unless /\A[^#{DmsfFolder::INVALID_CHARACTERS}]*\z/.match?(value) record.errors.add attribute, :error_contains_invalid_character end end