<commit_before>require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))

begin
  require 'erubis'
  require 'tilt/erb'
  begin
    require 'tilt/erubis'
  rescue LoadError
    # Tilt 1 support
  end
rescue LoadError
  warn "tilt or erubis not installed, skipping _erubis_escaping plugin test"  
else
describe "_erubis_escaping plugin" do
  it "should escape inside <%= %> and not inside <%== %>, and handle postfix conditionals" do
    app(:bare) do
      plugin :render, :escape=>true

      route do |r|
        render(:inline=>'<%= "<>" %> <%== "<>" %><%= "<>" if false %>')
      end
    end

    body.must_equal '&lt;&gt; <>'
  end

  it "should consider classes in :escape_safe_classes as safe" do
    c = Class.new(String)
    c2 = Class.new(String)
    app(:bare) do
      plugin :render, :escape=>true, :escape_safe_classes=>c

      route do |r|
        @c, @c2 = c, c2
        render(:inline=>'<%= @c2.new("<>") %> <%= @c.new("<>") %>')
      end
    end
<commit_msg>Add workaround for tilt erb handler issue in erubis escaping spec<commit_after>require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))

begin
  require 'erubis'
  require 'tilt'
  require 'tilt/erb'
  begin
    require 'tilt/erubis'
  rescue LoadError
    # Tilt 1 support
  end

  if defined?(Tilt::ErubisTemplate) && ::Tilt['erb'] != Tilt::ErubisTemplate
    # Work around error where erubis isn't set as erb template handler
    Tilt.register(Tilt::ErubisTemplate, 'erb')
  end
rescue LoadError
  warn "tilt or erubis not installed, skipping _erubis_escaping plugin test"  
else
describe "_erubis_escaping plugin" do
  it "should escape inside <%= %> and not inside <%== %>, and handle postfix conditionals" do
    app(:bare) do
      plugin :render, :escape=>true

      route do |r|
        render(:inline=>'<%= "<>" %> <%== "<>" %><%= "<>" if false %>')
      end
    end

    body.must_equal '&lt;&gt; <>'
  end

  it "should consider classes in :escape_safe_classes as safe" do
    c = Class.new(String)
    c2 = Class.new(String)
    app(:bare) do
      plugin :render, :escape=>true, :escape_safe_classes=>c

      route do |r|
        @c, @c2 = c, c2
        render(:inline=>'<%= @c2.new("<>") %> <%= @c.new("<>") %>')
      end
    end

{'fraction_non_alphanumeric': 0.15381225209343324, 'fraction_numerical': 0.004407227853680035, 'mean_word_length': 3.235074626865672, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6629410', 'n_tokens_mistral': 822, 'n_tokens_neox': 778, 'n_words': 216}