Sha256: 9586081665d4cc80701d20e18fad23f9e9e1778117cb15f7b5929be07a70ea7b

Contents?: true

Size: 1.62 KB

Versions: 27

Compression:

Stored size: 1.62 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_script_event_handler_attributes
    orig = %(<a onclick='javascript:alert(0)'>YO DAWG</a>)
    html = SanitizationFilter.call(orig).to_s
    assert_no_match /javscript/, html
    assert_no_match /onclick/, html
  end

  def test_sanitizes_li_elements_not_contained_in_ul_or_ol
    stuff = "a\n<li>b</li>\nc"
    html  = SanitizationFilter.call(stuff).to_s
    assert_equal "a\nb\nc", 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_github_specific_protocols_are_not_removed
    stuff = '<a href="github-windows://spillthelog">Spill this yo</a> and so on'
    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

27 entries across 27 versions & 2 rubygems

Version Path
html-pipeline-linuxfr-0.14.23 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.14.22 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.14.21 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.14.20 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.14.19 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.14.18 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.14.17 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.14.16 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.14.15 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.14.14 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.14.13 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.14.12 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.14.11 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.14.10 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.14.9 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.14.8 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.14.7 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.14.6 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.14.5 test/html/pipeline/sanitization_filter_test.rb
html-pipeline-linuxfr-0.14.4 test/html/pipeline/sanitization_filter_test.rb