Sha256: 9d3297db21dad261ae0895f5136b4232fb6a5b9dcf7e3f7541a01a14cd4eeef5

Contents?: true

Size: 994 Bytes

Versions: 11

Compression:

Stored size: 994 Bytes

Contents

module Slim
  module Smart
    # Perform smart entity escaping in the
    # expressions `[:slim, :text, type, Expression]`.
    #
    # @api private
    class Escaper < ::Slim::Filter
      define_options smart_text_escaping: true

      def call(exp)
        if options[:smart_text_escaping]
          super
        else
          exp
        end
      end

      def on_slim_text(type, content)
        [:escape, type != :verbatim, [:slim, :text, type, compile(content)]]
      end

      def on_static(string)
        # Prevent obvious &foo; and &#1234; and &#x00ff; entities from escaping.
        block = [:multi]
        until string.empty?
          case string
          when /\A&(\w+|#x[0-9a-f]+|#\d+);/i
            # Entity.
            block << [:escape, false, [:static, $&]]
            string = $'
          when /\A&?[^&]*/
            # Other text.
            block << [:static, $&]
            string = $'
          end
        end
        block
      end

    end
  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
brakeman-3.3.0 bundle/ruby/2.3.0/gems/slim-3.0.6/lib/slim/smart/escaper.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/slim-3.0.6/lib/slim/smart/escaper.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/slim-3.0.6/lib/slim/smart/escaper.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/slim-3.0.6/lib/slim/smart/escaper.rb
slim-3.0.6 lib/slim/smart/escaper.rb
slim-3.0.3 lib/slim/smart/escaper.rb
slim-3.0.2 lib/slim/smart/escaper.rb
slim-3.0.1 lib/slim/smart/escaper.rb
slim-3.0.0 lib/slim/smart/escaper.rb
slim-3.0.0.beta.3 lib/slim/smart/escaper.rb
slim-3.0.0.beta.2 lib/slim/smart/escaper.rb