lib/carrierwave/sanitized_file.rb in carrierwave-0.5.4 vs lib/carrierwave/sanitized_file.rb in carrierwave-0.5.5

- old
+ new

@@ -15,10 +15,18 @@ # class SanitizedFile attr_accessor :file + class << self + attr_writer :sanitize_regexp + + def sanitize_regexp + @sanitize_regexp ||= /[^a-zA-Z0-9\.\-\+_]/ + end + end + def initialize(file) self.file = file end ## @@ -125,12 +133,10 @@ # def empty? @file.nil? || self.size.nil? || self.size.zero? end - alias_method :blank?, :empty? - ## # === Returns # # [Boolean] Whether the file exists # @@ -221,18 +227,29 @@ return @content_type if @content_type @file.content_type.chomp if @file.respond_to?(:content_type) and @file.content_type end ## + # Sets the content type of the file. + # + # === Returns + # + # [String] the content type of the file + # + def content_type=(type) + @content_type = type + end + + ## # Used to sanitize the file name. Public to allow overriding for non-latin characters. # # === Returns # # [Regexp] the regexp for sanitizing the file name # def sanitize_regexp - /[^a-zA-Z0-9\.\-\+_]/ + CarrierWave::SanitizedFile.sanitize_regexp end private def file=(file) @@ -261,10 +278,10 @@ name = name.gsub("\\", "/") # work-around for IE name = File.basename(name) name = name.gsub(sanitize_regexp,"_") name = "_#{name}" if name =~ /\A\.+\z/ name = "unnamed" if name.size == 0 - return name.mb_chars.downcase.to_s + return name.mb_chars.to_s end def split_extension(filename) # regular expressions to try for identifying extensions extension_matchers = [