Sha256: 71f4bce8cee51adb4e0ad327fc9a5ed4ceee9a5913f27ec62f28a6dd38c18781

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

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.should == '&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

    body.should == '&lt;&gt; <>'
  end

  it "should allow use of custom :escaper" do
    escaper = Object.new
    def escaper.escape_xml(s)
      s.gsub("'", "''")
    end
    app(:bare) do
      plugin :render, :escape=>true, :escaper=>escaper

      route do |r|
        render(:inline=>'<%= "ab\'1" %> <%== "ab\'1" %>')
      end
    end

    body.should == "ab''1 ab'1"
  end
end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
roda-2.2.0 spec/plugin/_erubis_escaping_spec.rb