Sha256: f977c4138b70974f982fe468c841ff7dd8239802058550775a0a4b7514dde351

Contents?: true

Size: 619 Bytes

Versions: 106

Compression:

Stored size: 619 Bytes

Contents

module Temple
  module Filters
    # Try to encode input string
    #
    # @api public
    class Encoding < Parser
      define_options encoding: 'utf-8'

      def call(s)
        if options[:encoding] && s.respond_to?(:encoding)
          old_enc = s.encoding
          s = s.dup if s.frozen?
          s.force_encoding(options[:encoding])
          # Fall back to old encoding if new encoding is invalid
          unless s.valid_encoding?
            s.force_encoding(old_enc)
            s.force_encoding(::Encoding::BINARY) unless s.valid_encoding?
          end
        end
        s
      end
    end
  end
end

Version data entries

106 entries across 92 versions & 7 rubygems

Version Path
brakeman-3.7.2 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/filters/encoding.rb
brakeman-3.7.1 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/filters/encoding.rb
brakeman-3.7.0 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/filters/encoding.rb
brakeman-3.6.2 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/filters/encoding.rb
brakeman-3.6.1 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/filters/encoding.rb
brakeman-3.6.0 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/filters/encoding.rb
temple-0.8.0 lib/temple/filters/encoding.rb
brakeman-3.5.0 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/filters/encoding.rb
brakeman-3.4.1 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/filters/encoding.rb
brakeman-3.4.0 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/filters/encoding.rb
brakeman-3.3.5 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/filters/encoding.rb
brakeman-3.3.4 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/filters/encoding.rb
brakeman-3.3.3 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/filters/encoding.rb
brakeman-3.3.2 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/filters/encoding.rb
brakeman-3.3.1 bundle/ruby/2.3.0/gems/temple-0.7.7/lib/temple/filters/encoding.rb
temple-0.7.7 lib/temple/filters/encoding.rb
brakeman-3.3.0 bundle/ruby/2.3.0/gems/temple-0.7.6/lib/temple/filters/encoding.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/temple-0.7.6/lib/temple/filters/encoding.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/temple-0.7.6/lib/temple/filters/encoding.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/temple-0.7.6/lib/temple/filters/encoding.rb