Sha256: bd21b800f02b3a0f687f1eca905ab5b34396aaf389700a423e9ecb81c9a9cc71

Contents?: true

Size: 1.47 KB

Versions: 14

Compression:

Stored size: 1.47 KB

Contents

require "test_helper"

class HTML::Pipeline::SanitizationFilterTest < Test::Unit::TestCase
  SanitizationFilter = HTML::Pipeline::SanitizationFilter

  def test_removing_script_tags
    orig = %(<p><img src="http://github.com/img.png" /><script></script></p>)
    html = SanitizationFilter.call(orig).to_s
    assert_no_match /script/, html
  end

  def test_removing_style_tags
    orig = %(<p><style>hey now</style></p>)
    html = SanitizationFilter.call(orig).to_s
    assert_no_match /style/, html
  end

  def test_removing_style_attributes
    orig = %(<p style='font-size:1000%'>YO DAWG</p>)
    html = SanitizationFilter.call(orig).to_s
    assert_no_match /font-size/, html
    assert_no_match /style/, html
  end

  def test_removing_javascript_protocol
    orig = %(<a href='javascript:alert(1)'>YO DAWG</a>)
    html = SanitizationFilter.call(orig).to_s
    assert_no_match /javascript/, html
    assert_no_match /href/, html
  end

  def test_removing_script_event_handler_attributes
    orig = %(<a onclick='javascript:alert(0)'>YO DAWG</a>)
    html = SanitizationFilter.call(orig).to_s
    assert_no_match /javascript/, html
    assert_no_match /onclick/, html
  end

  def test_does_not_sanitize_li_elements_contained_in_ul_or_ol
    stuff = "a\n<ul><li>b</li></ul>\nc"
    assert_equal stuff, SanitizationFilter.call(stuff).to_s
  end

  def test_script_contents_are_removed
    orig = '<script>JavaScript!</script>'
    assert_equal "", SanitizationFilter.call(orig).to_s
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
html-pipeline-linuxfr-0.15.7 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.15.6 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.15.5 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.15.4 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.15.3 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.14.30 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.15.2 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.15.1 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.14.29 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.15.0 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.14.28 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.14.27 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.14.26 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.14.25 test/html/pipeline/sanitization_filter_test.rb