diff --git a/govspeak.gemspec b/govspeak.gemspec index 7498724f..66ce16cc 100644 --- a/govspeak.gemspec +++ b/govspeak.gemspec @@ -29,7 +29,7 @@ library for use in the UK Government Single Domain project} s.add_dependency 'kramdown', '~> 1.15.0' s.add_dependency 'htmlentities', '~> 4' - s.add_dependency "sanitize", "~> 2.1.0" + s.add_dependency "sanitize", "~> 4.6" s.add_dependency 'nokogiri', '~> 1.5' s.add_dependency 'addressable', '>= 2.3.8', '< 3' s.add_dependency 'actionview', '>= 4.1', '< 6' diff --git a/test/html_sanitizer_test.rb b/test/html_sanitizer_test.rb index 240520bf..b84fc970 100644 --- a/test/html_sanitizer_test.rb +++ b/test/html_sanitizer_test.rb @@ -53,13 +53,24 @@ class HtmlSanitizerTest < Minitest::Test end test "allows table cells and table headings without a style attribute" do - html = "thingthing" + html = "
thing
thing
" assert_equal html, Govspeak::HtmlSanitizer.new(html).sanitize end + test "strips table cells and headings that appear outside a table" do + html = "thingthing" + assert_equal 'thingthing', Govspeak::HtmlSanitizer.new(html).sanitize + end + + test "normalizes table tags to inject missing rows and bodies like a browser does" do + html = "
thingthing
" + assert_equal '
thingthing
', Govspeak::HtmlSanitizer.new(html).sanitize + end + + test "allows valid text-align properties on the style attribute for table cells and table headings" do ["left", "right", "center"].each do |alignment| - html = "thingthing" + html = "
thing
thing
" assert_equal html, Govspeak::HtmlSanitizer.new(html).sanitize end @@ -70,8 +81,8 @@ class HtmlSanitizerTest < Minitest::Test "background-image: url(javascript:alert('XSS'))", "expression(alert('XSS'));" ].each do |style| - html = "thingthing" - assert_equal 'thingthing', Govspeak::HtmlSanitizer.new(html).sanitize + html = "
thing
thing
" + assert_equal '
thing
thing
', Govspeak::HtmlSanitizer.new(html).sanitize end end end