From 45780be2a7d6ddb5851e04279728c817c941c31c Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 9 May 2005 11:24:18 +0000 Subject: Added TextHelper#sanitize that can will remove any Javascript handlers, blocks, and forms from an input of HTML. This allows for use of HTML on public sites, but still be free of XSS issues. #1277 [Jamis Buck] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1298 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/test/template/text_helper_test.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'actionpack/test/template') diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb index ed2f08e755..926ebdaf47 100644 --- a/actionpack/test/template/text_helper_test.rb +++ b/actionpack/test/template/text_helper_test.rb @@ -86,5 +86,29 @@ class TextHelperTest < Test::Unit::TestCase assert_equal %(

Link #{link2_result}

), auto_link("

Link #{link2_raw}

") assert_equal %(

#{link2_result} Link

), auto_link("

#{link2_raw} Link

") end + + def test_sanitize_form + raw = "
" + result = sanitize(raw) + assert_equal "<form action='/foo/bar' method='post'></form>", result + end + + def test_sanitize_script + raw = "" + result = sanitize(raw) + assert_equal "<script language='Javascript'>blah blah blah</script>", result + end + + def test_sanitize_js_handlers + raw = %{onthis="do that" hello} + result = sanitize(raw) + assert_equal %{onthis="do that" hello}, result + end + + def test_sanitize_javascript_href + raw = %{href="javascript:bang" foo, bar} + result = sanitize(raw) + assert_equal %{href="javascript:bang" foo, bar}, result + end end -- cgit v1.2.3