Sha256: 42dbbe02a42a89c1f02edf311262d9fdb12861095399439ca5106d9f955c5e09

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

# We need to have an ability to upload files which includes russian characters, so we
# have to extend upload carrierwave security rules (see code below). Because of ruby
# bug you can't upload such files in Windows OS
unless RUBY_PLATFORM.downcase.include?("win") || RUBY_PLATFORM.downcase.include?("mingw")

  CarrierWave::SanitizedFile.sanitize_regexp = /[^[:word:]\.\-\+]/

end

if RUBY_VERSION == "1.9.3"

  module CarrierWave

    class SanitizedFile

      private

      # Sanitize the filename, to prevent hacking
      def sanitize(name)
        name = name.force_encoding(Encoding::UTF_8)
        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.to_s
      end

    end

  end

  module CarrierWave

    module Mount

      class Mounter

        def url(*args)
          url = uploader.url(*args)
          url = url.force_encoding(Encoding::UTF_8) if url
          url
        end

      end

    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
coalla-cms-0.4.2.0 lib/generators/coalla/cms/templates/initializers/carrierwave.rb
coalla-cms-0.4.4.3 lib/generators/coalla/cms/templates/initializers/carrierwave.rb