diff options
-rw-r--r-- | actionview/test/template/scrubbers/scrubbers_test.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/actionview/test/template/scrubbers/scrubbers_test.rb b/actionview/test/template/scrubbers/scrubbers_test.rb index 61d2c48373..9bf62f6ec3 100644 --- a/actionview/test/template/scrubbers/scrubbers_test.rb +++ b/actionview/test/template/scrubbers/scrubbers_test.rb @@ -167,4 +167,35 @@ class PermitScrubberTest < ScrubberTest assert_equal Loofah::Scrubber::STOP, scrubbing end +end + +class TargetScrubberTest < ScrubberTest + def setup + @scrubber = TargetScrubber.new + end + + def test_targeting_tags_removes_only_them + @scrubber.tags = %w(a h1) + html = '<script></script><a></a><h1></h1>' + assert_scrubbed html, '<script></script>' + end + + def test_targeting_tags_removes_only_them_nested + @scrubber.tags = %w(a) + html = '<tag><a><tag><a></a></tag></a></tag>' + assert_scrubbed html, '<tag><tag></tag></tag>' + end + + def test_targeting_attributes_removes_only_them + @scrubber.attributes = %w(class id) + html = '<a class="a" id="b" onclick="c"></a>' + assert_scrubbed html, '<a onclick="c"></a>' + end + + def test_targeting_tags_and_attributes_removes_only_them + @scrubber.tags = %w(tag) + @scrubber.attributes = %w(remove) + html = '<tag remove="" other=""></tag><a remove="" other=""></a>' + assert_scrubbed html, '<a other=""></a>' + end end
\ No newline at end of file |