Prevent addition of style attributes to all elements

This commit is contained in:
Andy Allan 2021-03-24 20:55:30 +00:00
parent 580b7bfc0c
commit bb2afc3e8b
2 changed files with 13 additions and 1 deletions

View file

@ -5,6 +5,7 @@ Sanitize::Config::OSM = Sanitize::Config.merge(
:remove_contents => %w[script style],
:transformers => lambda do |env|
env[:node].remove_class
env[:node].kwattr_remove("style", nil)
env[:node].add_class("table table-sm w-auto") if env[:node_name] == "table"
end
)

View file

@ -58,6 +58,12 @@ class RichTextTest < ActiveSupport::TestCase
assert_select "p[class='btn btn-warning']", false
assert_select "p", /^Click Me$/
end
r = RichText.new("html", "<p style='color:red'>Danger</p>")
assert_html r do
assert_select "p[style='color:red']", false
assert_select "p", /^Danger$/
end
end
def test_html_to_text
@ -163,11 +169,16 @@ class RichTextTest < ActiveSupport::TestCase
end
r = RichText.new("markdown", "Click Me\n{:.btn.btn-warning}")
# raise r.to_html
assert_html r do
assert_select "p[class='btn btn-warning']", false
assert_select "p", /^Click Me$/
end
r = RichText.new("markdown", "<p style='color:red'>Danger</p>")
assert_html r do
assert_select "p[style='color:red']", false
assert_select "p", /^Danger$/
end
end
def test_markdown_to_text