Sha256: 9474c5c08fc1700c652e1272873d1e9f1ec03b8f685bfbd1c0af6a5fb5f0b795

Contents?: true

Size: 1005 Bytes

Versions: 96

Compression:

Stored size: 1005 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&([a-z][a-z0-9]*|#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

96 entries across 82 versions & 5 rubygems

Version Path
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/brakeman-4.7.2/bundle/ruby/2.6.0/gems/slim-4.0.1/lib/slim/smart/escaper.rb
brakeman-4.7.2 bundle/ruby/2.6.0/gems/slim-4.0.1/lib/slim/smart/escaper.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/brakeman-4.7.1/bundle/ruby/2.6.0/gems/slim-4.0.1/lib/slim/smart/escaper.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/brakeman-4.5.1/bundle/ruby/2.5.0/gems/slim-4.0.1/lib/slim/smart/escaper.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/brakeman-4.7.0/bundle/ruby/2.6.0/gems/slim-4.0.1/lib/slim/smart/escaper.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/brakeman-4.6.1/bundle/ruby/2.6.0/gems/slim-4.0.1/lib/slim/smart/escaper.rb
brakeman-4.7.1 bundle/ruby/2.6.0/gems/slim-4.0.1/lib/slim/smart/escaper.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/brakeman-4.5.1/bundle/ruby/2.5.0/gems/slim-4.0.1/lib/slim/smart/escaper.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/brakeman-4.6.1/bundle/ruby/2.6.0/gems/slim-4.0.1/lib/slim/smart/escaper.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/brakeman-4.7.0/bundle/ruby/2.6.0/gems/slim-4.0.1/lib/slim/smart/escaper.rb
brakeman-4.7.0 bundle/ruby/2.6.0/gems/slim-4.0.1/lib/slim/smart/escaper.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/brakeman-4.6.1/bundle/ruby/2.6.0/gems/slim-4.0.1/lib/slim/smart/escaper.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/brakeman-4.5.1/bundle/ruby/2.5.0/gems/slim-4.0.1/lib/slim/smart/escaper.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/brakeman-4.6.1/bundle/ruby/2.6.0/gems/slim-4.0.1/lib/slim/smart/escaper.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/brakeman-4.5.1/bundle/ruby/2.5.0/gems/slim-4.0.1/lib/slim/smart/escaper.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/brakeman-4.5.1/bundle/ruby/2.5.0/gems/slim-4.0.1/lib/slim/smart/escaper.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/brakeman-4.6.1/bundle/ruby/2.6.0/gems/slim-4.0.1/lib/slim/smart/escaper.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/brakeman-4.6.1/bundle/ruby/2.6.0/gems/slim-4.0.1/lib/slim/smart/escaper.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/brakeman-4.5.1/bundle/ruby/2.5.0/gems/slim-4.0.1/lib/slim/smart/escaper.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/brakeman-4.6.1/bundle/ruby/2.6.0/gems/slim-4.0.1/lib/slim/smart/escaper.rb