Commit 0c5cf2d1 authored by Mateus Rambo Strey's avatar Mateus Rambo Strey

fix filename sanitize method

parent 60deeb18
Pipeline #3734 passed with stage
......@@ -3,22 +3,19 @@ module Dspace
module TempfileBuilder
def self.build(filename, contents = nil, bitstreams_path = '/tmp')
file = Tempfile.new([sanitize_filename(filename), File.extname(filename)], bitstreams_path, encoding: 'ascii-8bit').tap do |f|
Tempfile.new([sanitize_filename(filename), File.extname(filename)], bitstreams_path, encoding: 'ascii-8bit').tap do |f|
f.write contents
f.close
end
end
private
def self.sanitize_filename(filename)
filename.strip do |name|
# NOTE: File.basename doesn't work right with Windows paths on Unix
# get only the filename, not the whole path
name.gsub!(/^.*(\\|\/)/, '')
# Strip out the non-ascii character
name.gsub!(/[^0-9A-Za-z.\-]/, '_')
end
filename.strip!
# NOTE: File.basename doesn't work right with Windows paths on Unix
# get only the filename, not the whole path
filename.gsub!(/^.*(\\|\/)/, '')
# Strip out the non-ascii character
filename.gsub!(/[^0-9A-Za-z.\-]/, '_')
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment