Sha256: 3a33b218a870025d26c0f3e20d6404ed774e2cb970bfbbc6ad850995913791c1

Contents?: true

Size: 1.79 KB

Versions: 2

Compression:

Stored size: 1.79 KB

Contents

require 'helper'

class TestSlimCodeEscaping < TestSlim
  def test_escaping_evil_method
    source = %q{
p = evil_method
}

    assert_html '<p>&lt;script&gt;do_something_evil();&lt;&#47;script&gt;</p>', source
  end

  def test_escape_interpolation
    source = %q{
p \\#{hello_world}
}

    assert_html '<p>#{hello_world}</p>', source
  end

  def test_render_without_html_safe
    source = %q{
p = "<strong>Hello World\\n, meet \\"Slim\\"</strong>."
}

    assert_html "<p>&lt;strong&gt;Hello World\n, meet \&quot;Slim\&quot;&lt;&#47;strong&gt;.</p>", source
  end

  def test_render_with_html_safe_false
    String.send(:define_method, :html_safe?) { false }

    source = %q{
p = "<strong>Hello World\\n, meet \\"Slim\\"</strong>."
}

    assert_html "<p>&lt;strong&gt;Hello World\n, meet \&quot;Slim\&quot;&lt;&#47;strong&gt;.</p>", source, :use_html_safe => true
  end

  def test_render_with_html_safe_true
    String.send(:define_method, :html_safe?) { true }

    source = %q{
p = "<strong>Hello World\\n, meet \\"Slim\\"</strong>."
}

    assert_html "<p><strong>Hello World\n, meet \"Slim\"</strong>.</p>", source, :use_html_safe => true
  end

  def test_render_with_global_html_safe_false
    String.send(:define_method, :html_safe?) { false }
    Slim::Filter::DEFAULT_OPTIONS[:use_html_safe] = false

    source = %q{
p = "<strong>Hello World\\n, meet \\"Slim\\"</strong>."
}

    assert_html "<p>&lt;strong&gt;Hello World\n, meet \&quot;Slim\&quot;&lt;&#47;strong&gt;.</p>", source
  end

  def test_render_with_global_html_safe_true
    String.send(:define_method, :html_safe?) { true }
    Slim::Filter::DEFAULT_OPTIONS[:use_html_safe] = true

    source = %q{
p = "<strong>Hello World\\n, meet \\"Slim\\"</strong>."
}

    assert_html "<p><strong>Hello World\n, meet \"Slim\"</strong>.</p>", source
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
slim-0.7.0 test/slim/test_code_escaping.rb
slim-0.7.0.beta.2 test/slim/test_code_escaping.rb