Sha256: 85105f1fedee5fbfd455e16e05208f0f6f7f9b81e7fc7f14298c42b3bd6fca4e

Contents?: true

Size: 892 Bytes

Versions: 26

Compression:

Stored size: 892 Bytes

Contents

# Run from your Rails main directory
require 'test/test_helper'

class TestERB < Test::Unit::TestCase
  def assert_renders_erb(expected, input, shield=true)
    erb_class = shield ? XSSProtectedERB : ERB

    actual = eval(erb_class.new(input).src)
    
    assert_equal expected, actual
  end
  
  def test_erb_with_shield
    assert_renders_erb <<OUT, <<IN, true
Foo &amp;amp; Bar
Foo &amp;amp; Bar
Foo &amp; Bar
Foo &amp; Bar
Foo &amp; Bar
OUT
<%= "Foo &amp; Bar"  %>
<%= h("Foo &amp; Bar") %>
<%= "Foo &amp; Bar".mark_as_xss_protected  %>
<%= h("Foo & Bar") %>
<%= "Foo & Bar" %>
IN
  end
  
  def test_erb_without_shield
    assert_renders_erb <<OUT, <<IN, false
Foo &amp;amp; Bar
Foo &amp; Bar
Foo &amp; Bar
Foo &amp; Bar
Foo & Bar
OUT
<%= h("Foo &amp; Bar") %>
<%= "Foo &amp; Bar"  %>
<%= "Foo &amp; Bar".mark_as_xss_protected  %>
<%= h("Foo & Bar") %>
<%= "Foo & Bar" %>
IN
  end
end

Version data entries

26 entries across 26 versions & 5 rubygems

Version Path
codez-tarantula-0.5.5 vendor/xss-shield/test/test_erb.rb
codez-tarantula-0.5.4 vendor/xss-shield/test/test_erb.rb
artmotion-xss_shield-0.0.1 test/test_erb.rb
artmotion-xss_shield-0.0.2 test/test_erb.rb
relevance-tarantula-0.0.1 vendor/xss-shield/test/test_erb.rb
relevance-tarantula-0.0.2 vendor/xss-shield/test/test_erb.rb
relevance-tarantula-0.0.3 vendor/xss-shield/test/test_erb.rb
relevance-tarantula-0.0.5 vendor/xss-shield/test/test_erb.rb
relevance-tarantula-0.0.6 vendor/xss-shield/test/test_erb.rb
relevance-tarantula-0.0.7.1 vendor/xss-shield/test/test_erb.rb
relevance-tarantula-0.0.7 vendor/xss-shield/test/test_erb.rb
relevance-tarantula-0.0.8.0 vendor/xss-shield/test/test_erb.rb
relevance-tarantula-0.0.8.1 vendor/xss-shield/test/test_erb.rb
romanbsd-tarantula-0.1.8 vendor/xss-shield/test/test_erb.rb
romanbsd-tarantula-0.2.0 vendor/xss-shield/test/test_erb.rb
codez-tarantula-0.5.3 vendor/xss-shield/test/test_erb.rb
codez-tarantula-0.5.1 vendor/xss-shield/test/test_erb.rb
codez-tarantula-0.5.0 vendor/xss-shield/test/test_erb.rb
tarantula-0.5.1 vendor/xss-shield/test/test_erb.rb
tarantula-0.5.0 vendor/xss-shield/test/test_erb.rb