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
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/temple-0.8.2/lib/temple/filters/encoding.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/temple-0.8.2/lib/temple/filters/encoding.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/temple-0.8.2/lib/temple/filters/encoding.rb
brakeman-6.1.2 bundle/ruby/3.3.0/gems/temple-0.8.2/lib/temple/filters/encoding.rb
brakeman-6.1.1 bundle/ruby/3.0.0/gems/temple-0.8.2/lib/temple/filters/encoding.rb
brakeman-6.1.0 bundle/ruby/3.1.0/gems/temple-0.8.2/lib/temple/filters/encoding.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/temple-0.8.2/lib/temple/filters/encoding.rb
brakeman-6.0.1 bundle/ruby/3.1.0/gems/temple-0.8.2/lib/temple/filters/encoding.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/temple-0.8.2/lib/temple/filters/encoding.rb
brakeman-6.0.0 bundle/ruby/3.0.0/gems/temple-0.8.2/lib/temple/filters/encoding.rb
brakeman-5.4.1 bundle/ruby/3.1.0/gems/temple-0.8.2/lib/temple/filters/encoding.rb
temple-0.10.0 lib/temple/filters/encoding.rb
brakeman-5.4.0 bundle/ruby/2.7.0/gems/temple-0.8.2/lib/temple/filters/encoding.rb
temple-0.9.1 lib/temple/filters/encoding.rb
temple-0.9.0 lib/temple/filters/encoding.rb
brakeman-5.3.1 bundle/ruby/2.7.0/gems/temple-0.8.2/lib/temple/filters/encoding.rb
brakeman-5.3.0 bundle/ruby/2.7.0/gems/temple-0.8.2/lib/temple/filters/encoding.rb
brakeman-5.2.3 bundle/ruby/2.7.0/gems/temple-0.8.2/lib/temple/filters/encoding.rb
brakeman-5.2.2 bundle/ruby/2.7.0/gems/temple-0.8.2/lib/temple/filters/encoding.rb
brakeman-5.2.1 bundle/ruby/2.7.0/gems/temple-0.8.2/lib/temple/filters/encoding.rb