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
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/slim-4.1.0/lib/slim/smart/escaper.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/slim-4.1.0/lib/slim/smart/escaper.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/slim-4.1.0/lib/slim/smart/escaper.rb
brakeman-6.1.2 bundle/ruby/3.3.0/gems/slim-4.1.0/lib/slim/smart/escaper.rb
brakeman-6.1.1 bundle/ruby/3.0.0/gems/slim-4.1.0/lib/slim/smart/escaper.rb
brakeman-6.1.0 bundle/ruby/3.1.0/gems/slim-4.1.0/lib/slim/smart/escaper.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/slim-4.1.0/lib/slim/smart/escaper.rb
brakeman-6.0.1 bundle/ruby/3.1.0/gems/slim-4.1.0/lib/slim/smart/escaper.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/slim-4.1.0/lib/slim/smart/escaper.rb
brakeman-6.0.0 bundle/ruby/3.0.0/gems/slim-4.1.0/lib/slim/smart/escaper.rb
slim-5.1.0 lib/slim/smart/escaper.rb
brakeman-5.4.1 bundle/ruby/3.1.0/gems/slim-4.1.0/lib/slim/smart/escaper.rb
slim-5.0.0 lib/slim/smart/escaper.rb
brakeman-5.4.0 bundle/ruby/2.7.0/gems/slim-4.1.0/lib/slim/smart/escaper.rb
brakeman-5.3.1 bundle/ruby/2.7.0/gems/slim-4.1.0/lib/slim/smart/escaper.rb
brakeman-5.3.0 bundle/ruby/2.7.0/gems/slim-4.1.0/lib/slim/smart/escaper.rb
brakeman-5.2.3 bundle/ruby/2.7.0/gems/slim-4.1.0/lib/slim/smart/escaper.rb
brakeman-5.2.2 bundle/ruby/2.7.0/gems/slim-4.1.0/lib/slim/smart/escaper.rb
brakeman-5.2.1 bundle/ruby/2.7.0/gems/slim-4.1.0/lib/slim/smart/escaper.rb
brakeman-5.2.0 bundle/ruby/2.7.0/gems/slim-4.1.0/lib/slim/smart/escaper.rb