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

fix filename sanitize method

parent 60deeb18
...@@ -3,22 +3,19 @@ module Dspace ...@@ -3,22 +3,19 @@ module Dspace
module TempfileBuilder module TempfileBuilder
def self.build(filename, contents = nil, bitstreams_path = '/tmp') 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.write contents
f.close f.close
end end
end end
private
def self.sanitize_filename(filename) def self.sanitize_filename(filename)
filename.strip do |name| filename.strip!
# NOTE: File.basename doesn't work right with Windows paths on Unix # NOTE: File.basename doesn't work right with Windows paths on Unix
# get only the filename, not the whole path # get only the filename, not the whole path
name.gsub!(/^.*(\\|\/)/, '') filename.gsub!(/^.*(\\|\/)/, '')
# Strip out the non-ascii character # Strip out the non-ascii character
name.gsub!(/[^0-9A-Za-z.\-]/, '_') filename.gsub!(/[^0-9A-Za-z.\-]/, '_')
end
end end
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