require 'helper' class TestSkimCodeEscaping < TestSkim def test_escaping_evil_method source = %q{ p = @evil_method() } assert_html '

<script>do_something_evil();</script>

', source end def test_render_unsafe source = %q{ p = "Hello World\\n, meet \\"Skim\\"." } assert_html "

<strong>Hello World\n, meet \"Skim\"</strong>.

", source end def test_render_safe source = %q{ p = @safe("Hello World\\n, meet \\"Skim\\".") } assert_html "

Hello World\n, meet \"Skim\".

", source end def test_render_with_disable_escape_false source = %q{ = "

Hello

" == "

World

" } assert_html "<p>Hello</p>

World

", source end def test_render_with_disable_escape_true source = %q{ = "

Hello

" == "

World

" } assert_html "

Hello

World

", source, :disable_escape => true end def test_explicit_escape source = %q{ = @escape "Crate & Barrel" } assert_html "Crate & Barrel", source end def test_explicit_safe source = %q{ = @safe "Crate & Barrel" } assert_html "Crate & Barrel", source end def test_user_defined_escape source = %q{ = "Crate & Barrel" } assert_html "CRATE & BARREL", source, :context => "{escape: function (value) { return value.toUpperCase(); }}" end end